Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复同名模型选择问题 #1772

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/renderer/src/pages/home/Inputbar/MentionModelsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const MentionModelsButton: FC<Props> = ({ mentionModels, onMentionModel: onSelec

const handleModelSelect = (model: Model) => {
// Check if model is already selected
if (mentionModels.some((selected) => selected.id === model.id)) {
if (mentionModels.some((selected) => getModelUniqId(selected) === getModelUniqId(model))) {
return
}
onSelect(model)
Expand Down Expand Up @@ -209,7 +209,7 @@ const MentionModelsButton: FC<Props> = ({ mentionModels, onMentionModel: onSelec
e.preventDefault()
if (selectedIndex >= 0 && selectedIndex < flatModelItems.length) {
const selectedModel = flatModelItems[selectedIndex].model
if (!mentionModels.some((selected) => selected.id === selectedModel.id)) {
if (!mentionModels.some((selected) => getModelUniqId(selected) === getModelUniqId(selectedModel))) {
flatModelItems[selectedIndex].onClick()
}
setIsOpen(false)
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/src/pages/home/Inputbar/MentionModelsInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useProviders } from '@renderer/hooks/useProvider'
import { getModelUniqId } from '@renderer/services/ModelService'
import { Model } from '@renderer/types'
import { Flex, Tag } from 'antd'
import { FC } from 'react'
Expand All @@ -13,14 +14,19 @@ const MentionModelsInput: FC<{
const { t } = useTranslation()

const getProviderName = (model: Model) => {
const provider = providers.find((p) => p.models?.some((m) => m.id === model.id))
const provider = providers.find((p) => p.id === model?.provider)
return provider ? (provider.isSystem ? t(`provider.${provider.id}`) : provider.name) : ''
}

return (
<Container gap="4px 0" wrap>
{selectedModels.map((model) => (
<Tag bordered={false} color="processing" key={model.id} closable onClose={() => onRemoveModel(model)}>
<Tag
bordered={false}
color="processing"
key={getModelUniqId(model)}
closable
onClose={() => onRemoveModel(model)}>
@{model.name} ({getProviderName(model)})
</Tag>
))}
Expand Down