mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-10 20:16:37 +08:00
Compare commits
10 Commits
afce63b6e3
...
eb50f37f81
Author | SHA1 | Date | |
---|---|---|---|
|
eb50f37f81 | ||
|
c30ddfbb07 | ||
|
a2f0149786 | ||
|
03d36f96ed | ||
|
843dc52efa | ||
|
c261ebc82c | ||
|
f7c747c65f | ||
|
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
|
||||
],
|
||||
)
|
||||
) {
|
||||
|
@ -56,7 +56,7 @@ export interface OpenAIListModelResponse {
|
||||
|
||||
export interface RequestPayload {
|
||||
messages: {
|
||||
role: "system" | "user" | "assistant";
|
||||
role: "developer" | "system" | "user" | "assistant";
|
||||
content: string | MultimodalContent[];
|
||||
}[];
|
||||
stream?: boolean;
|
||||
@ -238,8 +238,16 @@ 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.
|
||||
};
|
||||
|
||||
// O1 使用 max_completion_tokens 控制token数 (https://platform.openai.com/docs/guides/reasoning#controlling-costs)
|
||||
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)
|
||||
requestPayload["messages"].unshift({
|
||||
role: "developer",
|
||||
content: "Formatting re-enabled",
|
||||
});
|
||||
|
||||
// o1/o3 uses max_completion_tokens to control the number of tokens (https://platform.openai.com/docs/guides/reasoning#controlling-costs)
|
||||
requestPayload["max_completion_tokens"] = modelConfig.max_tokens;
|
||||
}
|
||||
|
||||
|
@ -633,6 +633,18 @@ const xAIModes = [
|
||||
"grok-2-vision-1212",
|
||||
"grok-2-vision",
|
||||
"grok-2-vision-latest",
|
||||
"grok-3-mini-fast-beta",
|
||||
"grok-3-mini-fast",
|
||||
"grok-3-mini-fast-latest",
|
||||
"grok-3-mini-beta",
|
||||
"grok-3-mini",
|
||||
"grok-3-mini-latest",
|
||||
"grok-3-fast-beta",
|
||||
"grok-3-fast",
|
||||
"grok-3-fast-latest",
|
||||
"grok-3-beta",
|
||||
"grok-3",
|
||||
"grok-3-latest",
|
||||
];
|
||||
|
||||
const chatglmModels = [
|
||||
|
@ -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