fix: should not allow duplicating model (#6658)

This commit is contained in:
Louis 2025-09-30 13:59:17 +07:00 committed by GitHub
parent 334b160012
commit de9c04474e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 34 additions and 14 deletions

View File

@ -17,6 +17,7 @@ import { getProviderTitle } from '@/lib/utils'
import { useTranslation } from '@/i18n/react-i18next-compat'
import { ModelCapabilities } from '@/types/models'
import { models as providerModels } from 'token.js'
import { toast } from 'sonner'
type DialogAddModelProps = {
provider: ModelProvider
@ -37,8 +38,13 @@ export const DialogAddModel = ({ provider, trigger }: DialogAddModelProps) => {
// Handle form submission
const handleSubmit = () => {
if (!modelId.trim()) {
return // Don't submit if model ID is empty
if (!modelId.trim()) return // Don't submit if model ID is empty
if (provider.models.some((e) => e.id === modelId)) {
toast.error(t('providers:addModel.modelExists'), {
description: t('providers:addModel.modelExistsDesc'),
})
return // Don't submit if model ID already exists
}
// Create the new model

View File

@ -35,7 +35,9 @@
"modelId": "Modell ID",
"enterModelId": "Modell ID eingeben",
"exploreModels": "Sehe Modellliste von {{provider}}",
"addModel": "Modell hinzufügen"
"addModel": "Modell hinzufügen",
"modelExists": "Modell bereits vorhanden",
"modelExistsDesc": "Bitte wähle eine andere Modell-ID."
},
"deleteModel": {
"title": "Lösche Modell: {{modelId}}",

View File

@ -35,7 +35,9 @@
"modelId": "Model ID",
"enterModelId": "Enter model ID",
"exploreModels": "See model list from {{provider}}",
"addModel": "Add Model"
"addModel": "Add Model",
"modelExists": "Model already exists",
"modelExistsDesc": "Please choose a different model ID."
},
"deleteModel": {
"title": "Delete Model: {{modelId}}",
@ -69,4 +71,4 @@
"addProvider": "Add Provider",
"addOpenAIProvider": "Add OpenAI Provider",
"enterNameForProvider": "Enter name for provider"
}
}

View File

@ -35,7 +35,9 @@
"modelId": "ID Model",
"enterModelId": "Masukkan ID model",
"exploreModels": "Lihat daftar model dari {{provider}}",
"addModel": "Tambah Model"
"addModel": "Tambah Model",
"modelExists": "Model sudah ada",
"modelExistsDesc": "Silakan pilih ID model yang berbeda."
},
"deleteModel": {
"title": "Hapus Model: {{modelId}}",
@ -69,4 +71,4 @@
"addProvider": "Tambah Penyedia",
"addOpenAIProvider": "Tambah Penyedia OpenAI",
"enterNameForProvider": "Masukkan nama untuk penyedia"
}
}

View File

@ -35,7 +35,9 @@
"modelId": "Identyfikator Modelu",
"enterModelId": "Wprowadź identyfikator modelu",
"exploreModels": "Zobacz listę modeli dostawcy {{provider}}",
"addModel": "Dodaj Model"
"addModel": "Dodaj Model",
"modelExists": "Model już istnieje",
"modelExistsDesc": "Wybierz inny identyfikator modelu."
},
"deleteModel": {
"title": "Usuń Model: {{modelId}}",

View File

@ -35,7 +35,9 @@
"modelId": "ID mô hình",
"enterModelId": "Nhập ID mô hình",
"exploreModels": "Xem danh sách mô hình từ {{provider}}",
"addModel": "Thêm mô hình"
"addModel": "Thêm mô hình",
"modelExists": "Mô hình đã tồn tại",
"modelExistsDesc": "Vui lòng chọn một ID mô hình khác."
},
"deleteModel": {
"title": "Xóa mô hình: {{modelId}}",
@ -69,4 +71,4 @@
"addProvider": "Thêm nhà cung cấp",
"addOpenAIProvider": "Thêm nhà cung cấp OpenAI",
"enterNameForProvider": "Nhập tên cho nhà cung cấp"
}
}

View File

@ -35,7 +35,9 @@
"modelId": "模型 ID",
"enterModelId": "输入模型 ID",
"exploreModels": "查看 {{provider}} 的模型列表",
"addModel": "添加模型"
"addModel": "添加模型",
"modelExists": "模型已存在",
"modelExistsDesc": "请选择不同的模型 ID。"
},
"deleteModel": {
"title": "删除模型:{{modelId}}",
@ -69,4 +71,4 @@
"addProvider": "添加提供商",
"addOpenAIProvider": "添加 OpenAI 提供商",
"enterNameForProvider": "输入提供商名称"
}
}

View File

@ -35,7 +35,9 @@
"modelId": "模型 ID",
"enterModelId": "輸入模型 ID",
"exploreModels": "查看 {{provider}} 的模型清單",
"addModel": "新增模型"
"addModel": "新增模型",
"modelExists": "模型已存在",
"modelExistsDesc": "請選擇不同的模型 ID。"
},
"deleteModel": {
"title": "刪除模型:{{modelId}}",
@ -69,4 +71,4 @@
"addProvider": "新增提供者",
"addOpenAIProvider": "新增 OpenAI 提供者",
"enterNameForProvider": "輸入提供者名稱"
}
}