fix: USE_OPENAI_ENDPOINT_FOR_ALL_MODELS

This commit is contained in:
Hk-Gosuto 2024-06-07 18:04:05 +08:00
parent c289305b05
commit 740ece39da
6 changed files with 16 additions and 3 deletions

View File

@ -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 即可

View File

@ -16,6 +16,7 @@ const DANGER_CONFIG = {
isEnableRAG: serverConfig.isEnableRAG,
defaultModel: serverConfig.defaultModel,
edgeTTSVoiceName: serverConfig.edgeTTSVoiceName,
isUseOpenAIEndpointForAllModels: serverConfig.isUseOpenAIEndpointForAllModels,
};
declare global {

View File

@ -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",

View File

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

View File

@ -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();

View File

@ -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")) {