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

@@ -18,6 +18,7 @@ const DANGER_CONFIG = {
edgeTTSVoiceName: serverConfig.edgeTTSVoiceName,
isUseOpenAIEndpointForAllModels: serverConfig.isUseOpenAIEndpointForAllModels,
disableModelProviderDisplay: serverConfig.disableModelProviderDisplay,
isUseRemoteModels: serverConfig.isUseRemoteModels,
};
declare global {

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,
},
}));

View File

@@ -238,5 +238,6 @@ export const getServerSideConfig = () => {
!!process.env.USE_OPENAI_ENDPOINT_FOR_ALL_MODELS,
disableModelProviderDisplay: !!process.env.DISABLE_MODEL_PROVIDER_DISPLAY,
isUseRemoteModels: !!process.env.USE_REMOTE_MODELS,
};
};

View File

@@ -130,8 +130,8 @@ const DEFAULT_ACCESS_STATE = {
edgeTTSVoiceName: "zh-CN-YunxiNeural",
isUseOpenAIEndpointForAllModels: false,
disableModelProviderDisplay: false,
isUseRemoteModels: false,
};
export const useAccessStore = createPersistStore(
@@ -156,6 +156,12 @@ export const useAccessStore = createPersistStore(
return get().isUseOpenAIEndpointForAllModels;
},
useRemoteModels() {
this.fetch();
return get().isUseRemoteModels;
},
edgeVoiceName() {
this.fetch();