Compare commits

...

6 Commits

Author SHA1 Message Date
Q.A.zh
c977b4bfc2
Merge ecc65fa775 into 80d7fd9b98 2025-07-14 13:50:06 +08:00
RiverRay
80d7fd9b98
Merge pull request #6562 from LePao1/main
Some checks failed
Run Tests / test (push) Has been cancelled
fix: Update the regular expressions to support image upload functionality for multimodal Claude 4 and Gemini 2.5 series.
2025-07-14 13:37:52 +08:00
LePao1
e8a18d0b38 fix: Update the regular expressions to support image upload functionality for multimodal Claude 4 and Gemini 2.5 series. 2025-07-13 21:20:20 +08:00
Q.A.zh
ecc65fa775
fixbug 2024-12-30 02:31:25 +00:00
Q.A.zh
da9963d4ee
仅对chat模型进行模型可用性检验,避免tts功能受影响 2024-12-29 09:10:37 +00:00
Q.A.zh
24ff78e1c5
fix custom models setting 2024-12-29 06:45:58 +00:00
4 changed files with 29 additions and 14 deletions

View File

@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from "next/server";
import { getServerSideConfig } from "../config/server";
import { OPENAI_BASE_URL, ServiceProvider } from "../constant";
import { OPENAI_BASE_URL, ServiceProvider, OpenaiPath } from "../constant";
import { cloudflareAIGatewayUrl } from "../utils/cloudflare";
import { getModelProvider, isModelNotavailableInServer } from "../utils/model";
@ -26,8 +26,8 @@ export async function requestOpenai(req: NextRequest) {
authValue = req.headers.get("Authorization") ?? "";
authHeaderName = "Authorization";
}
let path = `${req.nextUrl.pathname}`.replaceAll("/api/openai/", "");
let isChatRequest = path.includes(OpenaiPath.ChatPath);
let baseUrl =
(isAzure ? serverConfig.azureUrl : serverConfig.baseUrl) || OPENAI_BASE_URL;
@ -117,14 +117,14 @@ export async function requestOpenai(req: NextRequest) {
const jsonBody = JSON.parse(clonedBody) as { model?: string };
// not undefined and is false
if (
if ( isChatRequest &&
isModelNotavailableInServer(
serverConfig.customModels,
jsonBody?.model as string,
[
ServiceProvider.OpenAI,
ServiceProvider.Azure,
jsonBody?.model as string, // support provider-unspecified model
"custom" as string, // support provider-unspecified model
],
)
) {

View File

@ -479,19 +479,20 @@ export const VISION_MODEL_REGEXES = [
/vision/,
/gpt-4o/,
/gpt-4\.1/,
/claude-3/,
/claude.*[34]/,
/gemini-1\.5/,
/gemini-exp/,
/gemini-2\.0/,
/gemini-2\.[05]/,
/learnlm/,
/qwen-vl/,
/qwen2-vl/,
/gpt-4-turbo(?!.*preview)/, // Matches "gpt-4-turbo" but not "gpt-4-turbo-preview"
/^dall-e-3$/, // Matches exactly "dall-e-3"
/gpt-4-turbo(?!.*preview)/,
/^dall-e-3$/,
/glm-4v/,
/vl/i,
/o3/,
/o4-mini/,
/grok-4/i,
];
export const EXCLUDE_VISION_MODEL_REGEXES = [/claude-3-5-haiku-20241022/];

View File

@ -66,8 +66,8 @@ export function collectModelTable(
// default models
models.forEach((m) => {
// using <modelName>@<providerId> as fullName
modelTable[`${m.name}@${m?.provider?.id}`] = {
// using <modelName>@<providerType> as fullName
modelTable[`${m.name}@${m?.provider?.providerType}`] = {
...m,
displayName: m.name, // 'provider' is copied over if it exists
};
@ -121,12 +121,14 @@ export function collectModelTable(
if (displayName && provider.providerName == "ByteDance") {
[customModelName, displayName] = [displayName, customModelName];
}
modelTable[`${customModelName}@${provider?.id}`] = {
modelTable[`${customModelName}@${provider?.providerType}`] = {
name: customModelName,
displayName: displayName || customModelName,
available,
provider, // Use optional chaining
sorted: CustomSeq.next(`${customModelName}@${provider?.id}`),
sorted: CustomSeq.next(
`${customModelName}@${provider?.providerType}`,
),
};
}
}

View File

@ -53,7 +53,7 @@ describe("isModelNotavailableInServer", () => {
expect(result).toBe(true);
});
// FIXME: 这个测试用例有问题,需要修复
// 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";
@ -69,7 +69,19 @@ describe("isModelNotavailableInServer", () => {
test("test custom model without setting provider", () => {
const customModels = "-all,mistral-large";
const modelName = "mistral-large";
const providerNames = modelName;
const providerNames = "custom";
const result = isModelNotavailableInServer(
customModels,
modelName,
providerNames,
);
expect(result).toBe(false);
});
test("test custom model with non-standard provider", () => {
const customModels = "-all,deepseek-chat@DeepSeek";
const modelName = "deepseek-chat";
const providerNames = "custom";
const result = isModelNotavailableInServer(
customModels,
modelName,