mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-31 11:16:55 +08:00
Compare commits
13 Commits
feature/co
...
feature/gl
Author | SHA1 | Date | |
---|---|---|---|
|
8a22c9d6db | ||
|
5f96804f3b | ||
|
13430ea3e2 | ||
|
9df24e568b | ||
|
e467ce028d | ||
|
cdfe907fb5 | ||
|
d91af7f983 | ||
|
87b5e3bf62 | ||
|
93c5320bf2 | ||
|
cc5e16b045 | ||
|
54f6feb2d7 | ||
|
e1ac0538b8 | ||
|
1a678cb4d8 |
@@ -8,7 +8,7 @@ import {
|
|||||||
import { prettyObject } from "@/app/utils/format";
|
import { prettyObject } from "@/app/utils/format";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { auth } from "@/app/api/auth";
|
import { auth } from "@/app/api/auth";
|
||||||
import { isModelAvailableInServer } from "@/app/utils/model";
|
import { isModelNotavailableInServer } from "@/app/utils/model";
|
||||||
|
|
||||||
const serverConfig = getServerSideConfig();
|
const serverConfig = getServerSideConfig();
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ async function request(req: NextRequest) {
|
|||||||
|
|
||||||
// not undefined and is false
|
// not undefined and is false
|
||||||
if (
|
if (
|
||||||
isModelAvailableInServer(
|
isModelNotavailableInServer(
|
||||||
serverConfig.customModels,
|
serverConfig.customModels,
|
||||||
jsonBody?.model as string,
|
jsonBody?.model as string,
|
||||||
ServiceProvider.Alibaba as string,
|
ServiceProvider.Alibaba as string,
|
||||||
|
@@ -9,7 +9,7 @@ import {
|
|||||||
import { prettyObject } from "@/app/utils/format";
|
import { prettyObject } from "@/app/utils/format";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { auth } from "./auth";
|
import { auth } from "./auth";
|
||||||
import { isModelAvailableInServer } from "@/app/utils/model";
|
import { isModelNotavailableInServer } from "@/app/utils/model";
|
||||||
import { cloudflareAIGatewayUrl } from "@/app/utils/cloudflare";
|
import { cloudflareAIGatewayUrl } from "@/app/utils/cloudflare";
|
||||||
|
|
||||||
const ALLOWD_PATH = new Set([Anthropic.ChatPath, Anthropic.ChatPath1]);
|
const ALLOWD_PATH = new Set([Anthropic.ChatPath, Anthropic.ChatPath1]);
|
||||||
@@ -122,7 +122,7 @@ async function request(req: NextRequest) {
|
|||||||
|
|
||||||
// not undefined and is false
|
// not undefined and is false
|
||||||
if (
|
if (
|
||||||
isModelAvailableInServer(
|
isModelNotavailableInServer(
|
||||||
serverConfig.customModels,
|
serverConfig.customModels,
|
||||||
jsonBody?.model as string,
|
jsonBody?.model as string,
|
||||||
ServiceProvider.Anthropic as string,
|
ServiceProvider.Anthropic as string,
|
||||||
|
@@ -8,7 +8,7 @@ import {
|
|||||||
import { prettyObject } from "@/app/utils/format";
|
import { prettyObject } from "@/app/utils/format";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { auth } from "@/app/api/auth";
|
import { auth } from "@/app/api/auth";
|
||||||
import { isModelAvailableInServer } from "@/app/utils/model";
|
import { isModelNotavailableInServer } from "@/app/utils/model";
|
||||||
import { getAccessToken } from "@/app/utils/baidu";
|
import { getAccessToken } from "@/app/utils/baidu";
|
||||||
|
|
||||||
const serverConfig = getServerSideConfig();
|
const serverConfig = getServerSideConfig();
|
||||||
@@ -104,7 +104,7 @@ async function request(req: NextRequest) {
|
|||||||
|
|
||||||
// not undefined and is false
|
// not undefined and is false
|
||||||
if (
|
if (
|
||||||
isModelAvailableInServer(
|
isModelNotavailableInServer(
|
||||||
serverConfig.customModels,
|
serverConfig.customModels,
|
||||||
jsonBody?.model as string,
|
jsonBody?.model as string,
|
||||||
ServiceProvider.Baidu as string,
|
ServiceProvider.Baidu as string,
|
||||||
|
@@ -8,7 +8,7 @@ import {
|
|||||||
import { prettyObject } from "@/app/utils/format";
|
import { prettyObject } from "@/app/utils/format";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { auth } from "@/app/api/auth";
|
import { auth } from "@/app/api/auth";
|
||||||
import { isModelAvailableInServer } from "@/app/utils/model";
|
import { isModelNotavailableInServer } from "@/app/utils/model";
|
||||||
|
|
||||||
const serverConfig = getServerSideConfig();
|
const serverConfig = getServerSideConfig();
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ async function request(req: NextRequest) {
|
|||||||
|
|
||||||
// not undefined and is false
|
// not undefined and is false
|
||||||
if (
|
if (
|
||||||
isModelAvailableInServer(
|
isModelNotavailableInServer(
|
||||||
serverConfig.customModels,
|
serverConfig.customModels,
|
||||||
jsonBody?.model as string,
|
jsonBody?.model as string,
|
||||||
ServiceProvider.ByteDance as string,
|
ServiceProvider.ByteDance as string,
|
||||||
|
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
|||||||
import { getServerSideConfig } from "../config/server";
|
import { getServerSideConfig } from "../config/server";
|
||||||
import { OPENAI_BASE_URL, ServiceProvider } from "../constant";
|
import { OPENAI_BASE_URL, ServiceProvider } from "../constant";
|
||||||
import { cloudflareAIGatewayUrl } from "../utils/cloudflare";
|
import { cloudflareAIGatewayUrl } from "../utils/cloudflare";
|
||||||
import { getModelProvider, isModelAvailableInServer } from "../utils/model";
|
import { getModelProvider, isModelNotavailableInServer } from "../utils/model";
|
||||||
|
|
||||||
const serverConfig = getServerSideConfig();
|
const serverConfig = getServerSideConfig();
|
||||||
|
|
||||||
@@ -118,15 +118,14 @@ export async function requestOpenai(req: NextRequest) {
|
|||||||
|
|
||||||
// not undefined and is false
|
// not undefined and is false
|
||||||
if (
|
if (
|
||||||
isModelAvailableInServer(
|
isModelNotavailableInServer(
|
||||||
serverConfig.customModels,
|
serverConfig.customModels,
|
||||||
jsonBody?.model as string,
|
jsonBody?.model as string,
|
||||||
ServiceProvider.OpenAI as string,
|
[
|
||||||
) ||
|
ServiceProvider.OpenAI,
|
||||||
isModelAvailableInServer(
|
ServiceProvider.Azure,
|
||||||
serverConfig.customModels,
|
jsonBody?.model as string, // support provider-unspecified model
|
||||||
jsonBody?.model as string,
|
],
|
||||||
ServiceProvider.Azure as string,
|
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
|
@@ -8,7 +8,7 @@ import {
|
|||||||
import { prettyObject } from "@/app/utils/format";
|
import { prettyObject } from "@/app/utils/format";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { auth } from "@/app/api/auth";
|
import { auth } from "@/app/api/auth";
|
||||||
import { isModelAvailableInServer } from "@/app/utils/model";
|
import { isModelNotavailableInServer } from "@/app/utils/model";
|
||||||
|
|
||||||
const serverConfig = getServerSideConfig();
|
const serverConfig = getServerSideConfig();
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ async function request(req: NextRequest) {
|
|||||||
|
|
||||||
// not undefined and is false
|
// not undefined and is false
|
||||||
if (
|
if (
|
||||||
isModelAvailableInServer(
|
isModelNotavailableInServer(
|
||||||
serverConfig.customModels,
|
serverConfig.customModels,
|
||||||
jsonBody?.model as string,
|
jsonBody?.model as string,
|
||||||
ServiceProvider.ChatGLM as string,
|
ServiceProvider.ChatGLM as string,
|
||||||
|
@@ -8,7 +8,7 @@ import {
|
|||||||
import { prettyObject } from "@/app/utils/format";
|
import { prettyObject } from "@/app/utils/format";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { auth } from "@/app/api/auth";
|
import { auth } from "@/app/api/auth";
|
||||||
import { isModelAvailableInServer } from "@/app/utils/model";
|
import { isModelNotavailableInServer } from "@/app/utils/model";
|
||||||
// iflytek
|
// iflytek
|
||||||
|
|
||||||
const serverConfig = getServerSideConfig();
|
const serverConfig = getServerSideConfig();
|
||||||
@@ -89,7 +89,7 @@ async function request(req: NextRequest) {
|
|||||||
|
|
||||||
// not undefined and is false
|
// not undefined and is false
|
||||||
if (
|
if (
|
||||||
isModelAvailableInServer(
|
isModelNotavailableInServer(
|
||||||
serverConfig.customModels,
|
serverConfig.customModels,
|
||||||
jsonBody?.model as string,
|
jsonBody?.model as string,
|
||||||
ServiceProvider.Iflytek as string,
|
ServiceProvider.Iflytek as string,
|
||||||
|
@@ -8,7 +8,7 @@ import {
|
|||||||
import { prettyObject } from "@/app/utils/format";
|
import { prettyObject } from "@/app/utils/format";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { auth } from "@/app/api/auth";
|
import { auth } from "@/app/api/auth";
|
||||||
import { isModelAvailableInServer } from "@/app/utils/model";
|
import { isModelNotavailableInServer } from "@/app/utils/model";
|
||||||
|
|
||||||
const serverConfig = getServerSideConfig();
|
const serverConfig = getServerSideConfig();
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ async function request(req: NextRequest) {
|
|||||||
|
|
||||||
// not undefined and is false
|
// not undefined and is false
|
||||||
if (
|
if (
|
||||||
isModelAvailableInServer(
|
isModelNotavailableInServer(
|
||||||
serverConfig.customModels,
|
serverConfig.customModels,
|
||||||
jsonBody?.model as string,
|
jsonBody?.model as string,
|
||||||
ServiceProvider.Moonshot as string,
|
ServiceProvider.Moonshot as string,
|
||||||
|
@@ -8,7 +8,7 @@ import {
|
|||||||
import { prettyObject } from "@/app/utils/format";
|
import { prettyObject } from "@/app/utils/format";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { auth } from "@/app/api/auth";
|
import { auth } from "@/app/api/auth";
|
||||||
import { isModelAvailableInServer } from "@/app/utils/model";
|
import { isModelNotavailableInServer } from "@/app/utils/model";
|
||||||
|
|
||||||
const serverConfig = getServerSideConfig();
|
const serverConfig = getServerSideConfig();
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ async function request(req: NextRequest) {
|
|||||||
|
|
||||||
// not undefined and is false
|
// not undefined and is false
|
||||||
if (
|
if (
|
||||||
isModelAvailableInServer(
|
isModelNotavailableInServer(
|
||||||
serverConfig.customModels,
|
serverConfig.customModels,
|
||||||
jsonBody?.model as string,
|
jsonBody?.model as string,
|
||||||
ServiceProvider.XAI as string,
|
ServiceProvider.XAI as string,
|
||||||
|
@@ -21,9 +21,10 @@ import {
|
|||||||
SpeechOptions,
|
SpeechOptions,
|
||||||
} from "../api";
|
} from "../api";
|
||||||
import { getClientConfig } from "@/app/config/client";
|
import { getClientConfig } from "@/app/config/client";
|
||||||
import { getMessageTextContent } from "@/app/utils";
|
import { getMessageTextContent, isVisionModel } from "@/app/utils";
|
||||||
import { RequestPayload } from "./openai";
|
import { RequestPayload } from "./openai";
|
||||||
import { fetch } from "@/app/utils/stream";
|
import { fetch } from "@/app/utils/stream";
|
||||||
|
import { preProcessImageContent } from "@/app/utils/chat";
|
||||||
|
|
||||||
interface BasePayload {
|
interface BasePayload {
|
||||||
model: string;
|
model: string;
|
||||||
@@ -154,9 +155,12 @@ export class ChatGLMApi implements LLMApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async chat(options: ChatOptions) {
|
async chat(options: ChatOptions) {
|
||||||
|
const visionModel = isVisionModel(options.config.model);
|
||||||
const messages: ChatOptions["messages"] = [];
|
const messages: ChatOptions["messages"] = [];
|
||||||
for (const v of options.messages) {
|
for (const v of options.messages) {
|
||||||
const content = getMessageTextContent(v);
|
const content = visionModel
|
||||||
|
? await preProcessImageContent(v.content)
|
||||||
|
: getMessageTextContent(v);
|
||||||
messages.push({ role: v.role, content });
|
messages.push({ role: v.role, content });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +172,6 @@ export class ChatGLMApi implements LLMApi {
|
|||||||
providerName: options.config.providerName,
|
providerName: options.config.providerName,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const modelType = this.getModelType(modelConfig.model);
|
const modelType = this.getModelType(modelConfig.model);
|
||||||
const requestPayload = this.createPayload(messages, modelConfig, options);
|
const requestPayload = this.createPayload(messages, modelConfig, options);
|
||||||
const path = this.path(this.getModelPath(modelType));
|
const path = this.path(this.getModelPath(modelType));
|
||||||
|
@@ -60,9 +60,18 @@ export class GeminiProApi implements LLMApi {
|
|||||||
extractMessage(res: any) {
|
extractMessage(res: any) {
|
||||||
console.log("[Response] gemini-pro response: ", res);
|
console.log("[Response] gemini-pro response: ", res);
|
||||||
|
|
||||||
|
const getTextFromParts = (parts: any[]) => {
|
||||||
|
if (!Array.isArray(parts)) return "";
|
||||||
|
|
||||||
|
return parts
|
||||||
|
.map((part) => part?.text || "")
|
||||||
|
.filter((text) => text.trim() !== "")
|
||||||
|
.join("\n\n");
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
res?.candidates?.at(0)?.content?.parts.at(0)?.text ||
|
getTextFromParts(res?.candidates?.at(0)?.content?.parts) ||
|
||||||
res?.at(0)?.candidates?.at(0)?.content?.parts.at(0)?.text ||
|
getTextFromParts(res?.at(0)?.candidates?.at(0)?.content?.parts) ||
|
||||||
res?.error?.message ||
|
res?.error?.message ||
|
||||||
""
|
""
|
||||||
);
|
);
|
||||||
@@ -223,7 +232,10 @@ export class GeminiProApi implements LLMApi {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return chunkJson?.candidates?.at(0)?.content.parts.at(0)?.text;
|
return chunkJson?.candidates
|
||||||
|
?.at(0)
|
||||||
|
?.content.parts?.map((part: { text: string }) => part.text)
|
||||||
|
.join("\n\n");
|
||||||
},
|
},
|
||||||
// processToolMessage, include tool_calls message and tool call results
|
// processToolMessage, include tool_calls message and tool call results
|
||||||
(
|
(
|
||||||
|
@@ -22,7 +22,6 @@ import {
|
|||||||
MIN_SIDEBAR_WIDTH,
|
MIN_SIDEBAR_WIDTH,
|
||||||
NARROW_SIDEBAR_WIDTH,
|
NARROW_SIDEBAR_WIDTH,
|
||||||
Path,
|
Path,
|
||||||
PLUGINS,
|
|
||||||
REPO_URL,
|
REPO_URL,
|
||||||
} from "../constant";
|
} from "../constant";
|
||||||
|
|
||||||
@@ -32,6 +31,12 @@ import dynamic from "next/dynamic";
|
|||||||
import { showConfirm, Selector } from "./ui-lib";
|
import { showConfirm, Selector } from "./ui-lib";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
|
|
||||||
|
const DISCOVERY = [
|
||||||
|
{ name: Locale.Plugin.Name, path: Path.Plugins },
|
||||||
|
{ name: "Stable Diffusion", path: Path.Sd },
|
||||||
|
{ name: Locale.SearchChat.Page.Title, path: Path.SearchChat },
|
||||||
|
];
|
||||||
|
|
||||||
const ChatList = dynamic(async () => (await import("./chat-list")).ChatList, {
|
const ChatList = dynamic(async () => (await import("./chat-list")).ChatList, {
|
||||||
loading: () => null,
|
loading: () => null,
|
||||||
});
|
});
|
||||||
@@ -219,7 +224,7 @@ export function SideBarTail(props: {
|
|||||||
export function SideBar(props: { className?: string }) {
|
export function SideBar(props: { className?: string }) {
|
||||||
useHotKey();
|
useHotKey();
|
||||||
const { onDragStart, shouldNarrow } = useDragSideBar();
|
const { onDragStart, shouldNarrow } = useDragSideBar();
|
||||||
const [showPluginSelector, setShowPluginSelector] = useState(false);
|
const [showDiscoverySelector, setshowDiscoverySelector] = useState(false);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const config = useAppConfig();
|
const config = useAppConfig();
|
||||||
const chatStore = useChatStore();
|
const chatStore = useChatStore();
|
||||||
@@ -254,21 +259,21 @@ export function SideBar(props: { className?: string }) {
|
|||||||
icon={<DiscoveryIcon />}
|
icon={<DiscoveryIcon />}
|
||||||
text={shouldNarrow ? undefined : Locale.Discovery.Name}
|
text={shouldNarrow ? undefined : Locale.Discovery.Name}
|
||||||
className={styles["sidebar-bar-button"]}
|
className={styles["sidebar-bar-button"]}
|
||||||
onClick={() => setShowPluginSelector(true)}
|
onClick={() => setshowDiscoverySelector(true)}
|
||||||
shadow
|
shadow
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{showPluginSelector && (
|
{showDiscoverySelector && (
|
||||||
<Selector
|
<Selector
|
||||||
items={[
|
items={[
|
||||||
...PLUGINS.map((item) => {
|
...DISCOVERY.map((item) => {
|
||||||
return {
|
return {
|
||||||
title: item.name,
|
title: item.name,
|
||||||
value: item.path,
|
value: item.path,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
]}
|
]}
|
||||||
onClose={() => setShowPluginSelector(false)}
|
onClose={() => setshowDiscoverySelector(false)}
|
||||||
onSelection={(s) => {
|
onSelection={(s) => {
|
||||||
navigate(s[0], { state: { fromHome: true } });
|
navigate(s[0], { state: { fromHome: true } });
|
||||||
}}
|
}}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import md5 from "spark-md5";
|
import md5 from "spark-md5";
|
||||||
import { DEFAULT_MODELS, DEFAULT_GA_ID } from "../constant";
|
import { DEFAULT_MODELS, DEFAULT_GA_ID } from "../constant";
|
||||||
|
import { isGPT4Model } from "../utils/model";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace NodeJS {
|
namespace NodeJS {
|
||||||
@@ -127,20 +128,12 @@ export const getServerSideConfig = () => {
|
|||||||
|
|
||||||
if (disableGPT4) {
|
if (disableGPT4) {
|
||||||
if (customModels) customModels += ",";
|
if (customModels) customModels += ",";
|
||||||
customModels += DEFAULT_MODELS.filter(
|
customModels += DEFAULT_MODELS.filter((m) => isGPT4Model(m.name))
|
||||||
(m) =>
|
|
||||||
(m.name.startsWith("gpt-4") || m.name.startsWith("chatgpt-4o") || m.name.startsWith("o1")) &&
|
|
||||||
!m.name.startsWith("gpt-4o-mini"),
|
|
||||||
)
|
|
||||||
.map((m) => "-" + m.name)
|
.map((m) => "-" + m.name)
|
||||||
.join(",");
|
.join(",");
|
||||||
if (
|
if (defaultModel && isGPT4Model(defaultModel)) {
|
||||||
(defaultModel.startsWith("gpt-4") ||
|
|
||||||
defaultModel.startsWith("chatgpt-4o") ||
|
|
||||||
defaultModel.startsWith("o1")) &&
|
|
||||||
!defaultModel.startsWith("gpt-4o-mini")
|
|
||||||
)
|
|
||||||
defaultModel = "";
|
defaultModel = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isStability = !!process.env.STABILITY_API_KEY;
|
const isStability = !!process.env.STABILITY_API_KEY;
|
||||||
|
@@ -305,6 +305,9 @@ export const VISION_MODEL_REGEXES = [
|
|||||||
/qwen2-vl/,
|
/qwen2-vl/,
|
||||||
/gpt-4-turbo(?!.*preview)/, // Matches "gpt-4-turbo" but not "gpt-4-turbo-preview"
|
/gpt-4-turbo(?!.*preview)/, // Matches "gpt-4-turbo" but not "gpt-4-turbo-preview"
|
||||||
/^dall-e-3$/, // Matches exactly "dall-e-3"
|
/^dall-e-3$/, // Matches exactly "dall-e-3"
|
||||||
|
/glm-4v-plus/,
|
||||||
|
/glm-4v/,
|
||||||
|
/glm-4v-flash/,
|
||||||
];
|
];
|
||||||
|
|
||||||
export const EXCLUDE_VISION_MODEL_REGEXES = [/claude-3-5-haiku-20241022/];
|
export const EXCLUDE_VISION_MODEL_REGEXES = [/claude-3-5-haiku-20241022/];
|
||||||
@@ -597,11 +600,6 @@ export const internalAllowedWebDavEndpoints = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export const DEFAULT_GA_ID = "G-89WN60ZK2E";
|
export const DEFAULT_GA_ID = "G-89WN60ZK2E";
|
||||||
export const PLUGINS = [
|
|
||||||
{ name: "Plugins", path: Path.Plugins },
|
|
||||||
{ name: "Stable Diffusion", path: Path.Sd },
|
|
||||||
{ name: "Search Chat", path: Path.SearchChat },
|
|
||||||
];
|
|
||||||
|
|
||||||
export const SAAS_CHAT_URL = "https://nextchat.dev/chat";
|
export const SAAS_CHAT_URL = "https://nextchat.dev/chat";
|
||||||
export const SAAS_CHAT_UTM_URL = "https://nextchat.dev/chat?utm=github";
|
export const SAAS_CHAT_UTM_URL = "https://nextchat.dev/chat?utm=github";
|
||||||
|
@@ -176,7 +176,7 @@ const cn = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Lang: {
|
Lang: {
|
||||||
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
|
Name: "Language", // 注意:如果要添加新的翻译,请不要翻译此值,将它保留为 `Language`
|
||||||
All: "所有语言",
|
All: "所有语言",
|
||||||
},
|
},
|
||||||
Avatar: "头像",
|
Avatar: "头像",
|
||||||
@@ -630,7 +630,7 @@ const cn = {
|
|||||||
Sysmessage: "你是一个助手",
|
Sysmessage: "你是一个助手",
|
||||||
},
|
},
|
||||||
SearchChat: {
|
SearchChat: {
|
||||||
Name: "搜索",
|
Name: "搜索聊天记录",
|
||||||
Page: {
|
Page: {
|
||||||
Title: "搜索聊天记录",
|
Title: "搜索聊天记录",
|
||||||
Search: "输入搜索关键词",
|
Search: "输入搜索关键词",
|
||||||
|
@@ -485,7 +485,7 @@ const tw = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
SearchChat: {
|
SearchChat: {
|
||||||
Name: "搜尋",
|
Name: "搜尋聊天記錄",
|
||||||
Page: {
|
Page: {
|
||||||
Title: "搜尋聊天記錄",
|
Title: "搜尋聊天記錄",
|
||||||
Search: "輸入搜尋關鍵詞",
|
Search: "輸入搜尋關鍵詞",
|
||||||
|
@@ -202,3 +202,52 @@ export function isModelAvailableInServer(
|
|||||||
const modelTable = collectModelTable(DEFAULT_MODELS, customModels);
|
const modelTable = collectModelTable(DEFAULT_MODELS, customModels);
|
||||||
return modelTable[fullName]?.available === false;
|
return modelTable[fullName]?.available === false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the model name is a GPT-4 related model
|
||||||
|
*
|
||||||
|
* @param modelName The name of the model to check
|
||||||
|
* @returns True if the model is a GPT-4 related model (excluding gpt-4o-mini)
|
||||||
|
*/
|
||||||
|
export function isGPT4Model(modelName: string): boolean {
|
||||||
|
return (
|
||||||
|
(modelName.startsWith("gpt-4") ||
|
||||||
|
modelName.startsWith("chatgpt-4o") ||
|
||||||
|
modelName.startsWith("o1")) &&
|
||||||
|
!modelName.startsWith("gpt-4o-mini")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a model is not available on any of the specified providers in the server.
|
||||||
|
*
|
||||||
|
* @param {string} customModels - A string of custom models, comma-separated.
|
||||||
|
* @param {string} modelName - The name of the model to check.
|
||||||
|
* @param {string|string[]} providerNames - A string or array of provider names to check against.
|
||||||
|
*
|
||||||
|
* @returns {boolean} True if the model is not available on any of the specified providers, false otherwise.
|
||||||
|
*/
|
||||||
|
export function isModelNotavailableInServer(
|
||||||
|
customModels: string,
|
||||||
|
modelName: string,
|
||||||
|
providerNames: string | string[],
|
||||||
|
): boolean {
|
||||||
|
// Check DISABLE_GPT4 environment variable
|
||||||
|
if (
|
||||||
|
process.env.DISABLE_GPT4 === "1" &&
|
||||||
|
isGPT4Model(modelName.toLowerCase())
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const modelTable = collectModelTable(DEFAULT_MODELS, customModels);
|
||||||
|
|
||||||
|
const providerNamesArray = Array.isArray(providerNames)
|
||||||
|
? providerNames
|
||||||
|
: [providerNames];
|
||||||
|
for (const providerName of providerNamesArray) {
|
||||||
|
const fullName = `${modelName}@${providerName.toLowerCase()}`;
|
||||||
|
if (modelTable?.[fullName]?.available === true) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
80
test/model-available.test.ts
Normal file
80
test/model-available.test.ts
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import { isModelNotavailableInServer } from "../app/utils/model";
|
||||||
|
|
||||||
|
describe("isModelNotavailableInServer", () => {
|
||||||
|
test("test model will return false, which means the model is available", () => {
|
||||||
|
const customModels = "";
|
||||||
|
const modelName = "gpt-4";
|
||||||
|
const providerNames = "OpenAI";
|
||||||
|
const result = isModelNotavailableInServer(
|
||||||
|
customModels,
|
||||||
|
modelName,
|
||||||
|
providerNames,
|
||||||
|
);
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("test model will return true when model is not available in custom models", () => {
|
||||||
|
const customModels = "-all,gpt-4o-mini";
|
||||||
|
const modelName = "gpt-4";
|
||||||
|
const providerNames = "OpenAI";
|
||||||
|
const result = isModelNotavailableInServer(
|
||||||
|
customModels,
|
||||||
|
modelName,
|
||||||
|
providerNames,
|
||||||
|
);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should respect DISABLE_GPT4 setting", () => {
|
||||||
|
process.env.DISABLE_GPT4 = "1";
|
||||||
|
const result = isModelNotavailableInServer("", "gpt-4", "OpenAI");
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should handle empty provider names", () => {
|
||||||
|
const result = isModelNotavailableInServer("-all,gpt-4", "gpt-4", "");
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should be case insensitive for model names", () => {
|
||||||
|
const result = isModelNotavailableInServer("-all,GPT-4", "gpt-4", "OpenAI");
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("support passing multiple providers, model unavailable on one of the providers will return true", () => {
|
||||||
|
const customModels = "-all,gpt-4@google";
|
||||||
|
const modelName = "gpt-4";
|
||||||
|
const providerNames = ["OpenAI", "Azure"];
|
||||||
|
const result = isModelNotavailableInServer(
|
||||||
|
customModels,
|
||||||
|
modelName,
|
||||||
|
providerNames,
|
||||||
|
);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// FIXME: 这个测试用例有问题,需要修复
|
||||||
|
// test("support passing multiple providers, model available on one of the providers will return false", () => {
|
||||||
|
// const customModels = "-all,gpt-4@google";
|
||||||
|
// const modelName = "gpt-4";
|
||||||
|
// const providerNames = ["OpenAI", "Google"];
|
||||||
|
// const result = isModelNotavailableInServer(
|
||||||
|
// customModels,
|
||||||
|
// modelName,
|
||||||
|
// providerNames,
|
||||||
|
// );
|
||||||
|
// expect(result).toBe(false);
|
||||||
|
// });
|
||||||
|
|
||||||
|
test("test custom model without setting provider", () => {
|
||||||
|
const customModels = "-all,mistral-large";
|
||||||
|
const modelName = "mistral-large";
|
||||||
|
const providerNames = modelName;
|
||||||
|
const result = isModelNotavailableInServer(
|
||||||
|
customModels,
|
||||||
|
modelName,
|
||||||
|
providerNames,
|
||||||
|
);
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue
Block a user