mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-21 17:57:14 +00:00
fix(wizard): prevent duplicate models at API level
Before adding models, fetch existing provider models and skip names that already exist. Show error toast for manual add duplicates.
This commit is contained in:
@@ -1201,11 +1201,24 @@ function WizardModelScan({
|
||||
});
|
||||
};
|
||||
|
||||
const getExistingModelNames = async (): Promise<Set<string>> => {
|
||||
if (!providerUuid) return new Set();
|
||||
try {
|
||||
const resp = await httpClient.getProviderLLMModels(providerUuid);
|
||||
return new Set((resp.models ?? []).map((m: { name: string }) => m.name));
|
||||
} catch {
|
||||
return new Set();
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddSelected = async () => {
|
||||
if (!providerUuid || selectedModels.size === 0) return;
|
||||
setAdding(true);
|
||||
try {
|
||||
const existing = await getExistingModelNames();
|
||||
let added = 0;
|
||||
for (const name of selectedModels) {
|
||||
if (existing.has(name)) continue;
|
||||
const model = scannedModels.find((m) => m.name === name);
|
||||
await httpClient.createProviderLLMModel({
|
||||
name,
|
||||
@@ -1215,10 +1228,12 @@ function WizardModelScan({
|
||||
context_length: model?.context_length ?? null,
|
||||
extra_args: {},
|
||||
} as never);
|
||||
existing.add(name);
|
||||
added++;
|
||||
}
|
||||
if (added > 0) {
|
||||
toast.success(t('wizard.provider.modelsAdded', { count: added }));
|
||||
}
|
||||
toast.success(
|
||||
t('wizard.provider.modelsAdded', { count: selectedModels.size }),
|
||||
);
|
||||
setAddedModelNames((prev) => {
|
||||
const next = new Set(prev);
|
||||
for (const name of selectedModels) next.add(name);
|
||||
@@ -1238,6 +1253,12 @@ function WizardModelScan({
|
||||
if (!providerUuid || !name) return;
|
||||
setManualAdding(true);
|
||||
try {
|
||||
const existing = await getExistingModelNames();
|
||||
if (existing.has(name)) {
|
||||
toast.error(t('wizard.provider.modelAlreadyExists', { name }));
|
||||
setManualAdding(false);
|
||||
return;
|
||||
}
|
||||
await httpClient.createProviderLLMModel({
|
||||
name,
|
||||
provider_uuid: providerUuid,
|
||||
|
||||
@@ -1874,6 +1874,7 @@ const enUS = {
|
||||
addManual: 'Add',
|
||||
saveAndNext: 'Save & Next',
|
||||
alreadyAdded: 'Added',
|
||||
modelAlreadyExists: 'Model "{{name}}" already exists',
|
||||
},
|
||||
modelSource: {
|
||||
title: 'Choose Model Source',
|
||||
|
||||
@@ -1732,6 +1732,7 @@ const esES = {
|
||||
addManual: 'Agregar',
|
||||
saveAndNext: 'Guardar y siguiente',
|
||||
alreadyAdded: 'Agregado',
|
||||
modelAlreadyExists: 'El modelo "{{name}}" ya existe',
|
||||
},
|
||||
modelSource: {
|
||||
title: 'Elegir fuente del modelo',
|
||||
|
||||
@@ -1793,6 +1793,7 @@ const jaJP = {
|
||||
addManual: '追加',
|
||||
saveAndNext: '保存して次へ',
|
||||
alreadyAdded: '追加済み',
|
||||
modelAlreadyExists: 'モデル「{{name}}」は既に存在します',
|
||||
},
|
||||
modelSource: {
|
||||
title: 'モデルソースを選択',
|
||||
|
||||
@@ -1702,6 +1702,7 @@ const ruRU = {
|
||||
addManual: 'Добавить',
|
||||
saveAndNext: 'Сохранить и далее',
|
||||
alreadyAdded: 'Добавлено',
|
||||
modelAlreadyExists: 'Модель "{{name}}" уже существует',
|
||||
},
|
||||
modelSource: {
|
||||
title: 'Выберите источник модели',
|
||||
|
||||
@@ -1666,6 +1666,7 @@ const thTH = {
|
||||
addManual: 'เพิ่ม',
|
||||
saveAndNext: 'บันทึกและถัดไป',
|
||||
alreadyAdded: 'เพิ่มแล้ว',
|
||||
modelAlreadyExists: 'โมเดล "{{name}}" มีอยู่แล้ว',
|
||||
},
|
||||
modelSource: {
|
||||
title: 'เลือกแหล่งโมเดล',
|
||||
|
||||
@@ -1692,6 +1692,7 @@ const viVN = {
|
||||
addManual: 'Thêm',
|
||||
saveAndNext: 'Lưu & Tiếp theo',
|
||||
alreadyAdded: 'Đã thêm',
|
||||
modelAlreadyExists: 'Mô hình "{{name}}" đã tồn tại',
|
||||
},
|
||||
modelSource: {
|
||||
title: 'Chọn nguồn mô hình',
|
||||
|
||||
@@ -1790,6 +1790,7 @@ const zhHans = {
|
||||
addManual: '添加',
|
||||
saveAndNext: '保存并下一步',
|
||||
alreadyAdded: '已添加',
|
||||
modelAlreadyExists: '模型 "{{name}}" 已存在',
|
||||
},
|
||||
modelSource: {
|
||||
title: '选择模型来源',
|
||||
|
||||
@@ -1613,6 +1613,7 @@ const zhHant = {
|
||||
addManual: '新增',
|
||||
saveAndNext: '儲存並下一步',
|
||||
alreadyAdded: '已新增',
|
||||
modelAlreadyExists: '模型「{{name}}」已存在',
|
||||
},
|
||||
modelSource: {
|
||||
title: '選擇模型來源',
|
||||
|
||||
Reference in New Issue
Block a user