Merge pull request #2275 from Saber-Kurama/pref/api-models

perf:  models接口返回异常数据的容错处理
This commit is contained in:
Yifei Zhang 2023-07-07 11:23:30 +08:00 committed by GitHub
commit 05fcb96181
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 };