Browse Source

perf: models接口返回数据的容错处理

guochao 1 year ago
parent
commit
6653a31eb7
1 changed files with 7 additions and 5 deletions
  1. 7 5
      app/client/platforms/openai.ts

+ 7 - 5
app/client/platforms/openai.ts

@@ -254,13 +254,15 @@ export class ChatGPTApi implements LLMApi {
     });
 
     const resJson = (await res.json()) as OpenAIListModelResponse;
-    const chatModels = resJson.data.filter((m) => m.id.startsWith("gpt-"));
+    const chatModels = resJson.data?.filter((m) => m.id.startsWith("gpt-"));
     console.log("[Models]", chatModels);
 
-    return chatModels.map((m) => ({
-      name: m.id,
-      available: true,
-    }));
+    return (
+      chatModels?.map((m) => ({
+        name: m.id,
+        available: true,
+      })) || []
+    );
   }
 }
 export { OpenaiPath };