mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-09-30 15:16:38 +08:00
Compare commits
10 Commits
7854f9758a
...
2b6aa1a634
Author | SHA1 | Date | |
---|---|---|---|
|
2b6aa1a634 | ||
|
995bef73de | ||
|
38ac502d80 | ||
|
0511808900 | ||
|
42eff644b4 | ||
|
8ae6883784 | ||
|
c0f2ab6de3 | ||
|
ecc65fa775 | ||
|
da9963d4ee | ||
|
24ff78e1c5 |
@ -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
|
||||
],
|
||||
)
|
||||
) {
|
||||
|
@ -200,6 +200,7 @@ export class ChatGPTApi implements LLMApi {
|
||||
options.config.model.startsWith("o1") ||
|
||||
options.config.model.startsWith("o3") ||
|
||||
options.config.model.startsWith("o4-mini");
|
||||
const isGpt5 = options.config.model.startsWith("gpt-5");
|
||||
if (isDalle3) {
|
||||
const prompt = getMessageTextContent(
|
||||
options.messages.slice(-1)?.pop() as any,
|
||||
@ -230,7 +231,7 @@ export class ChatGPTApi implements LLMApi {
|
||||
messages,
|
||||
stream: options.config.stream,
|
||||
model: modelConfig.model,
|
||||
temperature: !isO1OrO3 ? modelConfig.temperature : 1,
|
||||
temperature: (!isO1OrO3 && !isGpt5) ? modelConfig.temperature : 1,
|
||||
presence_penalty: !isO1OrO3 ? modelConfig.presence_penalty : 0,
|
||||
frequency_penalty: !isO1OrO3 ? modelConfig.frequency_penalty : 0,
|
||||
top_p: !isO1OrO3 ? modelConfig.top_p : 1,
|
||||
@ -238,7 +239,13 @@ export class ChatGPTApi implements LLMApi {
|
||||
// Please do not ask me why not send max_tokens, no reason, this param is just shit, I dont want to explain anymore.
|
||||
};
|
||||
|
||||
if (isO1OrO3) {
|
||||
if (isGpt5) {
|
||||
// Remove max_tokens if present
|
||||
delete requestPayload.max_tokens;
|
||||
// Add max_completion_tokens (or max_completion_tokens if that's what you meant)
|
||||
requestPayload["max_completion_tokens"] = modelConfig.max_tokens;
|
||||
|
||||
} else if (isO1OrO3) {
|
||||
// by default the o1/o3 models will not attempt to produce output that includes markdown formatting
|
||||
// manually add "Formatting re-enabled" developer message to encourage markdown inclusion in model responses
|
||||
// (https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/reasoning?tabs=python-secure#markdown-output)
|
||||
@ -251,8 +258,9 @@ export class ChatGPTApi implements LLMApi {
|
||||
requestPayload["max_completion_tokens"] = modelConfig.max_tokens;
|
||||
}
|
||||
|
||||
|
||||
// add max_tokens to vision model
|
||||
if (visionModel && !isO1OrO3) {
|
||||
if (visionModel && !isO1OrO3 && ! isGpt5) {
|
||||
requestPayload["max_tokens"] = Math.max(modelConfig.max_tokens, 4000);
|
||||
}
|
||||
}
|
||||
|
@ -493,6 +493,7 @@ export const VISION_MODEL_REGEXES = [
|
||||
/o3/,
|
||||
/o4-mini/,
|
||||
/grok-4/i,
|
||||
/gpt-5/
|
||||
];
|
||||
|
||||
export const EXCLUDE_VISION_MODEL_REGEXES = [/claude-3-5-haiku-20241022/];
|
||||
@ -517,6 +518,11 @@ const openaiModels = [
|
||||
"gpt-4.1-nano-2025-04-14",
|
||||
"gpt-4.5-preview",
|
||||
"gpt-4.5-preview-2025-02-27",
|
||||
"gpt-5-chat",
|
||||
"gpt-5-mini",
|
||||
"gpt-5-nano",
|
||||
"gpt-5",
|
||||
"gpt-5-chat-2025-01-01-preview",
|
||||
"gpt-4o",
|
||||
"gpt-4o-2024-05-13",
|
||||
"gpt-4o-2024-08-06",
|
||||
|
@ -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}`,
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user