mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-13 20:53:45 +08:00
feat: #327
This commit is contained in:
@@ -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,
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user