mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-14 05:03:43 +08:00
feat: add env
This commit is contained in:
@@ -108,7 +108,7 @@ export async function requestOpenai(req: NextRequest) {
|
||||
fetchOptions.body = clonedBody;
|
||||
|
||||
// not undefined and is false
|
||||
if (modelTable[jsonBody?.model ?? ""].available === false) {
|
||||
if (modelTable[jsonBody?.model ?? ""]?.available === false) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: true,
|
||||
|
||||
@@ -216,7 +216,9 @@ export function getHeaders(ignoreHeaders?: boolean) {
|
||||
const accessStore = useAccessStore.getState();
|
||||
let headers: Record<string, string> = {};
|
||||
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) {
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -15,6 +15,7 @@ import { IconButton } from "./button";
|
||||
import {
|
||||
copyToClipboard,
|
||||
downloadAs,
|
||||
getClientApi,
|
||||
getMessageImages,
|
||||
useMobileScreen,
|
||||
} from "../utils";
|
||||
@@ -313,14 +314,7 @@ export function PreviewActions(props: {
|
||||
const onRenderMsgs = (msgs: ChatMessage[]) => {
|
||||
setShouldExport(false);
|
||||
|
||||
var api: ClientApi;
|
||||
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);
|
||||
}
|
||||
var api: ClientApi = getClientApi(config.modelConfig.model);
|
||||
|
||||
api
|
||||
.share(msgs)
|
||||
|
||||
@@ -9,7 +9,7 @@ import styles from "./home.module.scss";
|
||||
import BotIcon from "../icons/bot.svg";
|
||||
import LoadingIcon from "../icons/three-dots.svg";
|
||||
|
||||
import { useMobileScreen } from "../utils";
|
||||
import { getClientApi, useMobileScreen } from "../utils";
|
||||
|
||||
import dynamic from "next/dynamic";
|
||||
import { ModelProvider, Path, SlotID } from "../constant";
|
||||
@@ -178,14 +178,8 @@ function Screen() {
|
||||
export function useLoadData() {
|
||||
const config = useAppConfig();
|
||||
|
||||
var api: ClientApi;
|
||||
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);
|
||||
}
|
||||
var api: ClientApi = getClientApi(config.modelConfig.model);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
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 { showToast } from "../components/ui-lib";
|
||||
@@ -484,13 +484,6 @@ export const useChatStore = createPersistStore(
|
||||
agentCall();
|
||||
}
|
||||
} 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
|
||||
api.llm.chat({
|
||||
messages: sendMessages,
|
||||
@@ -667,14 +660,7 @@ export const useChatStore = createPersistStore(
|
||||
const session = get().currentSession();
|
||||
const modelConfig = session.mask.modelConfig;
|
||||
|
||||
var api: ClientApi;
|
||||
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);
|
||||
}
|
||||
var api: ClientApi = getClientApi(config.modelConfig.model);
|
||||
|
||||
// remove error messages if any
|
||||
const messages = session.messages;
|
||||
|
||||
19
app/utils.ts
19
app/utils.ts
@@ -1,8 +1,9 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { showToast } from "./components/ui-lib";
|
||||
import Locale from "./locales";
|
||||
import { RequestMessage } from "./client/api";
|
||||
import { DEFAULT_MODELS } from "./constant";
|
||||
import { ClientApi, RequestMessage } from "./client/api";
|
||||
import { DEFAULT_MODELS, ModelProvider } from "./constant";
|
||||
import { identifyDefaultClaudeModel } from "./utils/checkers";
|
||||
|
||||
export function trimTopic(topic: string) {
|
||||
// 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,
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user