mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-03 00:26:40 +08:00
加强不可用模型过滤
This commit is contained in:
parent
36d993cc5a
commit
07c48ef7fd
@ -10,6 +10,7 @@ export async function requestOpenai(
|
|||||||
req: NextRequest,
|
req: NextRequest,
|
||||||
cloneBody: any,
|
cloneBody: any,
|
||||||
isAzure: boolean,
|
isAzure: boolean,
|
||||||
|
current_model: string,
|
||||||
) {
|
) {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
|
|
||||||
@ -65,26 +66,20 @@ export async function requestOpenai(
|
|||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
};
|
};
|
||||||
|
|
||||||
// #1815 try to refuse gpt4 request
|
// #1815 try to refuse some model request
|
||||||
if (serverConfig.customModels && cloneBody) {
|
if (current_model) {
|
||||||
try {
|
try {
|
||||||
const modelTable = collectModelTable(
|
const modelTable = collectModelTable(
|
||||||
DEFAULT_MODELS,
|
DEFAULT_MODELS,
|
||||||
serverConfig.customModels,
|
serverConfig.customModels,
|
||||||
);
|
);
|
||||||
// const clonedBody = await req.text();
|
|
||||||
fetchOptions.body = cloneBody;
|
|
||||||
|
|
||||||
const jsonBody = JSON.parse(cloneBody) as {
|
|
||||||
model?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
// not undefined and is false
|
// not undefined and is false
|
||||||
if (!modelTable[jsonBody?.model ?? ""].available) {
|
if (!modelTable[current_model ?? ""].available) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
error: true,
|
error: true,
|
||||||
message: `you are not allowed to use ${jsonBody?.model} model`,
|
message: `you are not allowed to use ${current_model} model`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
status: 403,
|
status: 403,
|
||||||
@ -92,7 +87,7 @@ export async function requestOpenai(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("[OpenAI] gpt4 filter", e);
|
console.error("[OpenAI] gpt model filter", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ function getModels(remoteModelRes: OpenAIListModelResponse) {
|
|||||||
m.id === "gpt-3.5-turbo-16k" ||
|
m.id === "gpt-3.5-turbo-16k" ||
|
||||||
m.id === "gpt-4-32k",
|
m.id === "gpt-4-32k",
|
||||||
);
|
);
|
||||||
|
|
||||||
return remoteModelRes;
|
return remoteModelRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +104,12 @@ async function handle(
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await requestOpenai(req, cloneBody, isAzure);
|
const response = await requestOpenai(
|
||||||
|
req,
|
||||||
|
cloneBody,
|
||||||
|
isAzure,
|
||||||
|
jsonBody?.model ?? "",
|
||||||
|
);
|
||||||
|
|
||||||
// list models
|
// list models
|
||||||
if (subpath === OpenaiPath.ListModelPath && response.status === 200) {
|
if (subpath === OpenaiPath.ListModelPath && response.status === 200) {
|
||||||
|
Loading…
Reference in New Issue
Block a user