feat: add env
This commit is contained in:
parent
991dd0490f
commit
c289305b05
|
@ -292,12 +292,19 @@ anthropic claude Api Url.
|
||||||
- 多个地址以`,`相连
|
- 多个地址以`,`相连
|
||||||
|
|
||||||
### `DEFAULT_INPUT_TEMPLATE` (可选)
|
### `DEFAULT_INPUT_TEMPLATE` (可选)
|
||||||
|
|
||||||
自定义默认的 template,用于初始化『设置』中的『用户输入预处理』配置项
|
自定义默认的 template,用于初始化『设置』中的『用户输入预处理』配置项
|
||||||
|
|
||||||
### `EDGE_TTS_VOICE_NAME` (可选)
|
### `EDGE_TTS_VOICE_NAME` (可选)
|
||||||
|
|
||||||
配置 Edge TTS 使用的语音声音,默认为:zh-CN-YunxiNeural
|
配置 Edge TTS 使用的语音声音,默认为:zh-CN-YunxiNeural
|
||||||
可访问 https://learn.microsoft.com/zh-cn/azure/ai-services/speech-service/language-support?tabs=tts#supported-languages 查看支持的参数
|
可访问 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` (可选)
|
||||||
|
|
||||||
|
配置所有模型都使用 OpenAI 路由,在使用类似 `one-api` 的中转项目时会很有用
|
||||||
|
将此环境变量设置为 1 即可
|
||||||
|
|
||||||
## 部署
|
## 部署
|
||||||
|
|
||||||
### 容器部署 (推荐)
|
### 容器部署 (推荐)
|
||||||
|
|
|
@ -108,7 +108,7 @@ export async function requestOpenai(req: NextRequest) {
|
||||||
fetchOptions.body = clonedBody;
|
fetchOptions.body = clonedBody;
|
||||||
|
|
||||||
// not undefined and is false
|
// not undefined and is false
|
||||||
if (modelTable[jsonBody?.model ?? ""].available === false) {
|
if (modelTable[jsonBody?.model ?? ""]?.available === false) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
error: true,
|
error: true,
|
||||||
|
|
|
@ -216,7 +216,9 @@ export function getHeaders(ignoreHeaders?: boolean) {
|
||||||
const accessStore = useAccessStore.getState();
|
const accessStore = useAccessStore.getState();
|
||||||
let headers: Record<string, string> = {};
|
let headers: Record<string, string> = {};
|
||||||
const modelConfig = useChatStore.getState().currentSession().mask.modelConfig;
|
const modelConfig = useChatStore.getState().currentSession().mask.modelConfig;
|
||||||
const isGoogle = modelConfig.model.startsWith("gemini");
|
const isGoogle =
|
||||||
|
modelConfig.model.startsWith("gemini") &&
|
||||||
|
!!!process.env.NEXT_PUBLIC_USE_OPENAI_ENDPOINT_FOR_ALL_MODELS;
|
||||||
if (!ignoreHeaders && !isGoogle) {
|
if (!ignoreHeaders && !isGoogle) {
|
||||||
headers = {
|
headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { IconButton } from "./button";
|
||||||
import {
|
import {
|
||||||
copyToClipboard,
|
copyToClipboard,
|
||||||
downloadAs,
|
downloadAs,
|
||||||
|
getClientApi,
|
||||||
getMessageImages,
|
getMessageImages,
|
||||||
useMobileScreen,
|
useMobileScreen,
|
||||||
} from "../utils";
|
} from "../utils";
|
||||||
|
@ -313,14 +314,7 @@ export function PreviewActions(props: {
|
||||||
const onRenderMsgs = (msgs: ChatMessage[]) => {
|
const onRenderMsgs = (msgs: ChatMessage[]) => {
|
||||||
setShouldExport(false);
|
setShouldExport(false);
|
||||||
|
|
||||||
var api: ClientApi;
|
var api: ClientApi = getClientApi(config.modelConfig.model);
|
||||||
if (config.modelConfig.model.startsWith("gemini")) {
|
|
||||||
api = new ClientApi(ModelProvider.GeminiPro);
|
|
||||||
} else if (identifyDefaultClaudeModel(config.modelConfig.model)) {
|
|
||||||
api = new ClientApi(ModelProvider.Claude);
|
|
||||||
} else {
|
|
||||||
api = new ClientApi(ModelProvider.GPT);
|
|
||||||
}
|
|
||||||
|
|
||||||
api
|
api
|
||||||
.share(msgs)
|
.share(msgs)
|
||||||
|
|
|
@ -9,7 +9,7 @@ import styles from "./home.module.scss";
|
||||||
import BotIcon from "../icons/bot.svg";
|
import BotIcon from "../icons/bot.svg";
|
||||||
import LoadingIcon from "../icons/three-dots.svg";
|
import LoadingIcon from "../icons/three-dots.svg";
|
||||||
|
|
||||||
import { useMobileScreen } from "../utils";
|
import { getClientApi, useMobileScreen } from "../utils";
|
||||||
|
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
import { ModelProvider, Path, SlotID } from "../constant";
|
import { ModelProvider, Path, SlotID } from "../constant";
|
||||||
|
@ -178,14 +178,8 @@ function Screen() {
|
||||||
export function useLoadData() {
|
export function useLoadData() {
|
||||||
const config = useAppConfig();
|
const config = useAppConfig();
|
||||||
|
|
||||||
var api: ClientApi;
|
var api: ClientApi = getClientApi(config.modelConfig.model);
|
||||||
if (config.modelConfig.model.startsWith("gemini")) {
|
|
||||||
api = new ClientApi(ModelProvider.GeminiPro);
|
|
||||||
} else if (identifyDefaultClaudeModel(config.modelConfig.model)) {
|
|
||||||
api = new ClientApi(ModelProvider.Claude);
|
|
||||||
} else {
|
|
||||||
api = new ClientApi(ModelProvider.GPT);
|
|
||||||
}
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const models = await api.llm.models();
|
const models = await api.llm.models();
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { trimTopic, getMessageTextContent } from "../utils";
|
import { trimTopic, getMessageTextContent, getClientApi } from "../utils";
|
||||||
|
|
||||||
import Locale, { getLang } from "../locales";
|
import Locale, { getLang } from "../locales";
|
||||||
import { showToast } from "../components/ui-lib";
|
import { showToast } from "../components/ui-lib";
|
||||||
|
@ -484,13 +484,6 @@ export const useChatStore = createPersistStore(
|
||||||
agentCall();
|
agentCall();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (modelConfig.model.startsWith("gemini")) {
|
|
||||||
api = new ClientApi(ModelProvider.GeminiPro);
|
|
||||||
} else if (identifyDefaultClaudeModel(modelConfig.model)) {
|
|
||||||
api = new ClientApi(ModelProvider.Claude);
|
|
||||||
} else {
|
|
||||||
api = new ClientApi(ModelProvider.GPT);
|
|
||||||
}
|
|
||||||
// make request
|
// make request
|
||||||
api.llm.chat({
|
api.llm.chat({
|
||||||
messages: sendMessages,
|
messages: sendMessages,
|
||||||
|
@ -667,14 +660,7 @@ export const useChatStore = createPersistStore(
|
||||||
const session = get().currentSession();
|
const session = get().currentSession();
|
||||||
const modelConfig = session.mask.modelConfig;
|
const modelConfig = session.mask.modelConfig;
|
||||||
|
|
||||||
var api: ClientApi;
|
var api: ClientApi = getClientApi(config.modelConfig.model);
|
||||||
if (modelConfig.model.startsWith("gemini")) {
|
|
||||||
api = new ClientApi(ModelProvider.GeminiPro);
|
|
||||||
} else if (identifyDefaultClaudeModel(modelConfig.model)) {
|
|
||||||
api = new ClientApi(ModelProvider.Claude);
|
|
||||||
} else {
|
|
||||||
api = new ClientApi(ModelProvider.GPT);
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove error messages if any
|
// remove error messages if any
|
||||||
const messages = session.messages;
|
const messages = session.messages;
|
||||||
|
|
19
app/utils.ts
19
app/utils.ts
|
@ -1,8 +1,9 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { showToast } from "./components/ui-lib";
|
import { showToast } from "./components/ui-lib";
|
||||||
import Locale from "./locales";
|
import Locale from "./locales";
|
||||||
import { RequestMessage } from "./client/api";
|
import { ClientApi, RequestMessage } from "./client/api";
|
||||||
import { DEFAULT_MODELS } from "./constant";
|
import { DEFAULT_MODELS, ModelProvider } from "./constant";
|
||||||
|
import { identifyDefaultClaudeModel } from "./utils/checkers";
|
||||||
|
|
||||||
export function trimTopic(topic: string) {
|
export function trimTopic(topic: string) {
|
||||||
// Fix an issue where double quotes still show in the Indonesian language
|
// Fix an issue where double quotes still show in the Indonesian language
|
||||||
|
@ -279,3 +280,17 @@ export function isSupportRAGModel(modelName: string) {
|
||||||
(model) => model.name === modelName,
|
(model) => model.name === modelName,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getClientApi(modelName: string): ClientApi {
|
||||||
|
if (!!process.env.NEXT_PUBLIC_USE_OPENAI_ENDPOINT_FOR_ALL_MODELS)
|
||||||
|
return new ClientApi(ModelProvider.GPT);
|
||||||
|
var api: ClientApi;
|
||||||
|
if (modelName.startsWith("gemini")) {
|
||||||
|
api = new ClientApi(ModelProvider.GeminiPro);
|
||||||
|
} else if (identifyDefaultClaudeModel(modelName)) {
|
||||||
|
api = new ClientApi(ModelProvider.Claude);
|
||||||
|
} else {
|
||||||
|
api = new ClientApi(ModelProvider.GPT);
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue