feat: improve SelectModelPopup (#2740)
* fix: do not match provider id for non-system models * feat: match multiple words
This commit is contained in:
parent
886a7ec1e9
commit
0e4f06e86a
@ -63,15 +63,33 @@ const PopupContainer: React.FC<PopupContainerProps> = ({ model, resolve }) => {
|
|||||||
setPinnedModels(sortBy(newPinnedModels, ['group', 'name']))
|
setPinnedModels(sortBy(newPinnedModels, ['group', 'name']))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 根据输入的文本筛选模型
|
||||||
|
const getFilteredModels = useCallback(
|
||||||
|
(provider) => {
|
||||||
|
const nonEmbeddingModels = provider.models.filter((m) => !isEmbeddingModel(m))
|
||||||
|
|
||||||
|
if (!searchText.trim()) {
|
||||||
|
return sortBy(nonEmbeddingModels, ['group', 'name'])
|
||||||
|
}
|
||||||
|
|
||||||
|
const keywords = searchText.toLowerCase().split(/\s+/).filter(Boolean)
|
||||||
|
|
||||||
|
return sortBy(nonEmbeddingModels, ['group', 'name']).filter((m) => {
|
||||||
|
const fullName = provider.isSystem
|
||||||
|
? `${m.name}${m.provider}${t('provider.' + provider.id)}`
|
||||||
|
: `${m.name}${m.provider}`
|
||||||
|
|
||||||
|
const lowerFullName = fullName.toLowerCase()
|
||||||
|
return keywords.every((keyword) => lowerFullName.includes(keyword))
|
||||||
|
})
|
||||||
|
},
|
||||||
|
[searchText, t]
|
||||||
|
)
|
||||||
|
|
||||||
const filteredItems: MenuItem[] = providers
|
const filteredItems: MenuItem[] = providers
|
||||||
.filter((p) => p.models && p.models.length > 0)
|
.filter((p) => p.models && p.models.length > 0)
|
||||||
.map((p) => {
|
.map((p) => {
|
||||||
const filteredModels = sortBy(p.models, ['group', 'name'])
|
const filteredModels = getFilteredModels(p).map((m) => ({
|
||||||
.filter((m) => !isEmbeddingModel(m))
|
|
||||||
.filter((m) =>
|
|
||||||
[m.name + m.provider + t('provider.' + p.id)].join('').toLowerCase().includes(searchText.toLowerCase())
|
|
||||||
)
|
|
||||||
.map((m) => ({
|
|
||||||
key: getModelUniqId(m),
|
key: getModelUniqId(m),
|
||||||
label: (
|
label: (
|
||||||
<ModelItem>
|
<ModelItem>
|
||||||
@ -194,12 +212,7 @@ const PopupContainer: React.FC<PopupContainerProps> = ({ model, resolve }) => {
|
|||||||
// 添加其他过滤后的模型
|
// 添加其他过滤后的模型
|
||||||
providers.forEach((p) => {
|
providers.forEach((p) => {
|
||||||
if (p.models) {
|
if (p.models) {
|
||||||
sortBy(p.models, ['group', 'name'])
|
getFilteredModels(p).forEach((m) => {
|
||||||
.filter((m) => !isEmbeddingModel(m))
|
|
||||||
.filter((m) =>
|
|
||||||
[m.name + m.provider + t('provider.' + p.id)].join('').toLowerCase().includes(searchText.toLowerCase())
|
|
||||||
)
|
|
||||||
.forEach((m) => {
|
|
||||||
const modelId = getModelUniqId(m)
|
const modelId = getModelUniqId(m)
|
||||||
const isPinned = pinnedModels.includes(modelId)
|
const isPinned = pinnedModels.includes(modelId)
|
||||||
// 如果是搜索状态,或者不是固定模型,才添加到列表中
|
// 如果是搜索状态,或者不是固定模型,才添加到列表中
|
||||||
@ -214,7 +227,7 @@ const PopupContainer: React.FC<PopupContainerProps> = ({ model, resolve }) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return items
|
return items
|
||||||
}, [pinnedModels, searchText, providers, t])
|
}, [pinnedModels, searchText, providers, getFilteredModels])
|
||||||
|
|
||||||
// 处理键盘导航
|
// 处理键盘导航
|
||||||
const handleKeyDown = useCallback(
|
const handleKeyDown = useCallback(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user