Browse Source

fix: #2280 auto-detect models from 'list/models'

Yidadaa 1 year ago
parent
commit
28c457730a
2 changed files with 12 additions and 6 deletions
  1. 8 6
      app/client/platforms/openai.ts
  2. 4 0
      app/store/config.ts

+ 8 - 6
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 };

+ 4 - 0
app/store/config.ts

@@ -117,6 +117,10 @@ export const useAppConfig = create<ChatConfigStore>()(
       },
 
       mergeModels(newModels) {
+        if (!newModels || newModels.length === 0) {
+          return;
+        }
+
         const oldModels = get().models;
         const modelMap: Record<string, LLMModel> = {};