This commit is contained in:
Hk-Gosuto
2025-01-10 16:55:31 +08:00
parent 8b501ccf2c
commit 798b751f2b
5 changed files with 49 additions and 17 deletions

View File

@@ -51,7 +51,8 @@ export interface OpenAIListModelResponse {
data: Array<{
id: string;
object: string;
root: string;
created: number;
owned_by: string;
}>;
}
@@ -80,7 +81,7 @@ export interface DalleRequestPayload {
}
export class ChatGPTApi implements LLMApi {
private disableListModels = true;
private disableListModels = false;
path(path: string, model?: string): string {
const accessStore = useAccessStore.getState();
@@ -651,7 +652,8 @@ export class ChatGPTApi implements LLMApi {
}
async models(): Promise<LLMModel[]> {
if (this.disableListModels) {
const accessStore = useAccessStore.getState();
if (!accessStore.isUseRemoteModels) {
return DEFAULT_MODELS.slice();
}
@@ -663,25 +665,27 @@ export class ChatGPTApi implements LLMApi {
});
const resJson = (await res.json()) as OpenAIListModelResponse;
const chatModels = resJson.data?.filter(
(m) => m.id.startsWith("gpt-") || m.id.startsWith("chatgpt-"),
);
// const chatModels = resJson.data?.filter(
// (m) => m.id.startsWith("gpt-") || m.id.startsWith("chatgpt-"),
// );
const chatModels = resJson.data.sort((a, b) => {
return b.created - a.created;
});
console.log("[Models]", chatModels);
if (!chatModels) {
return [];
}
//由于目前 OpenAI 的 disableListModels 默认为 true所以当前实际不会运行到这场
let seq = 1000; //同 Constant.ts 中的排序保持一致
return chatModels.map((m) => ({
name: m.id,
available: true,
sorted: seq++,
provider: {
id: "openai",
providerName: "OpenAI",
providerType: "openai",
id: m.owned_by.toLowerCase(),
providerName: m.owned_by,
providerType: m.owned_by.toLowerCase(),
sorted: 1,
},
}));