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']))
|
||||
}
|
||||
|
||||
// 根据输入的文本筛选模型
|
||||
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
|
||||
.filter((p) => p.models && p.models.length > 0)
|
||||
.map((p) => {
|
||||
const filteredModels = sortBy(p.models, ['group', 'name'])
|
||||
.filter((m) => !isEmbeddingModel(m))
|
||||
.filter((m) =>
|
||||
[m.name + m.provider + t('provider.' + p.id)].join('').toLowerCase().includes(searchText.toLowerCase())
|
||||
)
|
||||
.map((m) => ({
|
||||
const filteredModels = getFilteredModels(p).map((m) => ({
|
||||
key: getModelUniqId(m),
|
||||
label: (
|
||||
<ModelItem>
|
||||
@ -194,12 +212,7 @@ const PopupContainer: React.FC<PopupContainerProps> = ({ model, resolve }) => {
|
||||
// 添加其他过滤后的模型
|
||||
providers.forEach((p) => {
|
||||
if (p.models) {
|
||||
sortBy(p.models, ['group', 'name'])
|
||||
.filter((m) => !isEmbeddingModel(m))
|
||||
.filter((m) =>
|
||||
[m.name + m.provider + t('provider.' + p.id)].join('').toLowerCase().includes(searchText.toLowerCase())
|
||||
)
|
||||
.forEach((m) => {
|
||||
getFilteredModels(p).forEach((m) => {
|
||||
const modelId = getModelUniqId(m)
|
||||
const isPinned = pinnedModels.includes(modelId)
|
||||
// 如果是搜索状态,或者不是固定模型,才添加到列表中
|
||||
@ -214,7 +227,7 @@ const PopupContainer: React.FC<PopupContainerProps> = ({ model, resolve }) => {
|
||||
})
|
||||
|
||||
return items
|
||||
}, [pinnedModels, searchText, providers, t])
|
||||
}, [pinnedModels, searchText, providers, getFilteredModels])
|
||||
|
||||
// 处理键盘导航
|
||||
const handleKeyDown = useCallback(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user