diff --git a/README.md b/README.md index be1d3e594..8e56bac4d 100644 --- a/README.md +++ b/README.md @@ -300,7 +300,7 @@ anthropic claude Api Url. 配置 Edge TTS 使用的语音声音,默认为:zh-CN-YunxiNeural 可访问 https://learn.microsoft.com/zh-cn/azure/ai-services/speech-service/language-support?tabs=tts#supported-languages 查看支持的参数 -### `NEXT_PUBLIC_USE_OPENAI_ENDPOINT_FOR_ALL_MODELS` (可选) +### `USE_OPENAI_ENDPOINT_FOR_ALL_MODELS` (可选) 配置所有模型都使用 OpenAI 路由,在使用类似 `one-api` 的中转项目时会很有用 将此环境变量设置为 1 即可 diff --git a/app/api/config/route.ts b/app/api/config/route.ts index 0cc049d45..f21388595 100644 --- a/app/api/config/route.ts +++ b/app/api/config/route.ts @@ -16,6 +16,7 @@ const DANGER_CONFIG = { isEnableRAG: serverConfig.isEnableRAG, defaultModel: serverConfig.defaultModel, edgeTTSVoiceName: serverConfig.edgeTTSVoiceName, + isUseOpenAIEndpointForAllModels: serverConfig.isUseOpenAIEndpointForAllModels, }; declare global { diff --git a/app/client/api.ts b/app/client/api.ts index 6aaf9461b..cf3edb575 100644 --- a/app/client/api.ts +++ b/app/client/api.ts @@ -218,7 +218,7 @@ export function getHeaders(ignoreHeaders?: boolean) { const modelConfig = useChatStore.getState().currentSession().mask.modelConfig; const isGoogle = modelConfig.model.startsWith("gemini") && - !!!process.env.NEXT_PUBLIC_USE_OPENAI_ENDPOINT_FOR_ALL_MODELS; + !accessStore.useOpenAIEndpointForAllModels(); if (!ignoreHeaders && !isGoogle) { headers = { "Content-Type": "application/json", diff --git a/app/config/server.ts b/app/config/server.ts index 43745913f..b98bb379f 100644 --- a/app/config/server.ts +++ b/app/config/server.ts @@ -153,5 +153,7 @@ export const getServerSideConfig = () => { allowedWebDevEndpoints, edgeTTSVoiceName: process.env.EDGE_TTS_VOICE_NAME ?? "zh-CN-YunxiNeural", + isUseOpenAIEndpointForAllModels: + !!process.env.USE_OPENAI_ENDPOINT_FOR_ALL_MODELS, }; }; diff --git a/app/store/access.ts b/app/store/access.ts index eac9078d5..8ce4e25a1 100644 --- a/app/store/access.ts +++ b/app/store/access.ts @@ -54,6 +54,8 @@ const DEFAULT_ACCESS_STATE = { // tts config edgeTTSVoiceName: "zh-CN-YunxiNeural", + + isUseOpenAIEndpointForAllModels: false, }; export const useAccessStore = createPersistStore( @@ -66,6 +68,12 @@ export const useAccessStore = createPersistStore( return get().needCode; }, + useOpenAIEndpointForAllModels() { + this.fetch(); + + return get().isUseOpenAIEndpointForAllModels; + }, + edgeVoiceName() { this.fetch(); diff --git a/app/utils.ts b/app/utils.ts index f229fa6ff..6cac9cfbd 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -4,6 +4,7 @@ import Locale from "./locales"; import { ClientApi, RequestMessage } from "./client/api"; import { DEFAULT_MODELS, ModelProvider } from "./constant"; import { identifyDefaultClaudeModel } from "./utils/checkers"; +import { useAccessStore } from "./store"; export function trimTopic(topic: string) { // Fix an issue where double quotes still show in the Indonesian language @@ -282,7 +283,8 @@ export function isSupportRAGModel(modelName: string) { } export function getClientApi(modelName: string): ClientApi { - if (!!process.env.NEXT_PUBLIC_USE_OPENAI_ENDPOINT_FOR_ALL_MODELS) + const accessStore = useAccessStore.getState(); + if (accessStore.useOpenAIEndpointForAllModels()) return new ClientApi(ModelProvider.GPT); var api: ClientApi; if (modelName.startsWith("gemini")) {