From 28c457730afc838f6cd153c3dc789b70f3a0b761 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 9 Jul 2023 18:03:06 +0800 Subject: [PATCH] fix: #2280 auto-detect models from 'list/models' --- app/client/platforms/openai.ts | 14 ++++++++------ app/store/config.ts | 4 ++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index 7e44909e4..dfe413002 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -257,12 +257,14 @@ export class ChatGPTApi implements LLMApi { const chatModels = resJson.data?.filter((m) => m.id.startsWith("gpt-")); console.log("[Models]", chatModels); - return ( - chatModels?.map((m) => ({ - name: m.id, - available: true, - })) || [] - ); + if (!chatModels) { + return []; + } + + return chatModels.map((m) => ({ + name: m.id, + available: true, + })); } } export { OpenaiPath }; diff --git a/app/store/config.ts b/app/store/config.ts index cf390c74d..075c2acff 100644 --- a/app/store/config.ts +++ b/app/store/config.ts @@ -117,6 +117,10 @@ export const useAppConfig = create()( }, mergeModels(newModels) { + if (!newModels || newModels.length === 0) { + return; + } + const oldModels = get().models; const modelMap: Record = {};