From 2fd68bcac3f8aa9e8227b9f93acb4518e7e1165a Mon Sep 17 00:00:00 2001 From: "Mr. Z" <112755085+ZTH7@users.noreply.github.com> Date: Sun, 21 Jul 2024 16:42:34 +0800 Subject: [PATCH 1/4] Fix defaultModel undefined error --- app/utils/model.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/utils/model.ts b/app/utils/model.ts index 55a5ee0d67d..dc4b1f55cc7 100644 --- a/app/utils/model.ts +++ b/app/utils/model.ts @@ -98,10 +98,9 @@ export function collectModelTableWithDefaultModel( defaultModel: string, ) { let modelTable = collectModelTable(models, customModels); - if (defaultModel && defaultModel !== "") { + if (defaultModel && defaultModel !== "" && defaultModel in modelTable) { modelTable[defaultModel] = { ...modelTable[defaultModel], - name: defaultModel, available: true, isDefault: true, }; From aa4e8550127f66c5c77c557045fbc81f8aedb1cb Mon Sep 17 00:00:00 2001 From: "Mr. Z" <112755085+ZTH7@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:41:11 +0800 Subject: [PATCH 2/4] Compatibility changes --- app/utils/model.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/utils/model.ts b/app/utils/model.ts index dc4b1f55cc7..a0b0d6b65fa 100644 --- a/app/utils/model.ts +++ b/app/utils/model.ts @@ -98,9 +98,11 @@ export function collectModelTableWithDefaultModel( defaultModel: string, ) { let modelTable = collectModelTable(models, customModels); - if (defaultModel && defaultModel !== "" && defaultModel in modelTable) { + if (defaultModel && defaultModel !== "") { modelTable[defaultModel] = { ...modelTable[defaultModel], + name: modelTable[defaultModel]?.name ?? defaultModel, + displayName: modelTable[defaultModel]?.displayName ?? defaultModel, available: true, isDefault: true, }; From 5c04d3c5eafe20aa9d799fe60ec9df49df251846 Mon Sep 17 00:00:00 2001 From: "Mr. Z" <112755085+ZTH7@users.noreply.github.com> Date: Thu, 25 Jul 2024 17:59:15 +0800 Subject: [PATCH 3/4] Change method --- app/utils/model.ts | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/app/utils/model.ts b/app/utils/model.ts index a0b0d6b65fa..cc924f40f01 100644 --- a/app/utils/model.ts +++ b/app/utils/model.ts @@ -99,13 +99,25 @@ export function collectModelTableWithDefaultModel( ) { let modelTable = collectModelTable(models, customModels); if (defaultModel && defaultModel !== "") { - modelTable[defaultModel] = { - ...modelTable[defaultModel], - name: modelTable[defaultModel]?.name ?? defaultModel, - displayName: modelTable[defaultModel]?.displayName ?? defaultModel, - available: true, - isDefault: true, - }; + const [modelName, providerName] = defaultModel.split("@"); + if (providerName && providerName != "") { + modelTable[defaultModel] = { + ...modelTable[defaultModel], + name: modelTable[defaultModel]?.name ?? modelName, + displayName: + modelTable[defaultModel]?.displayName ?? + modelName + "(" + providerName + ")", + available: true, + isDefault: true, + }; + } else { + for (const key of Object.keys(modelTable)) { + if (modelTable[key].available && key.startsWith(modelName)) { + modelTable[key].isDefault = true; + break; + } + } + } } return modelTable; } From c4334d4e5fcca05b92bd6c8a6b5b25f187f1f540 Mon Sep 17 00:00:00 2001 From: "Mr. Z" <112755085+ZTH7@users.noreply.github.com> Date: Thu, 25 Jul 2024 20:03:54 +0800 Subject: [PATCH 4/4] Update model.ts --- app/utils/model.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/app/utils/model.ts b/app/utils/model.ts index cc924f40f01..4de0eb8d96a 100644 --- a/app/utils/model.ts +++ b/app/utils/model.ts @@ -99,20 +99,13 @@ export function collectModelTableWithDefaultModel( ) { let modelTable = collectModelTable(models, customModels); if (defaultModel && defaultModel !== "") { - const [modelName, providerName] = defaultModel.split("@"); - if (providerName && providerName != "") { - modelTable[defaultModel] = { - ...modelTable[defaultModel], - name: modelTable[defaultModel]?.name ?? modelName, - displayName: - modelTable[defaultModel]?.displayName ?? - modelName + "(" + providerName + ")", - available: true, - isDefault: true, - }; + if (defaultModel.includes('@')) { + if (defaultModel in modelTable) { + modelTable[defaultModel].isDefault = true; + } } else { for (const key of Object.keys(modelTable)) { - if (modelTable[key].available && key.startsWith(modelName)) { + if (modelTable[key].available && key.split('@').shift() == defaultModel) { modelTable[key].isDefault = true; break; }