fix: fix bug 124

This commit is contained in:
Hk-Gosuto 2023-12-27 12:17:39 +08:00
parent af60f46ba2
commit 445e05c63f

View File

@ -60,6 +60,12 @@ export async function requestOpenai(req: NextRequest) {
path = makeAzurePath(path, serverConfig.azureApiVersion); path = makeAzurePath(path, serverConfig.azureApiVersion);
} }
const clonedBody = await req.text();
const jsonBody = JSON.parse(clonedBody) as { model?: string };
if (serverConfig.isAzure) {
baseUrl = `${baseUrl}/${jsonBody.model}`;
}
const fetchUrl = `${baseUrl}/${path}`;
const fetchOptions: RequestInit = { const fetchOptions: RequestInit = {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@ -70,22 +76,16 @@ export async function requestOpenai(req: NextRequest) {
}), }),
}, },
method: req.method, method: req.method,
body: req.body, body: clonedBody,
// to fix #2485: https://stackoverflow.com/questions/55920957/cloudflare-worker-typeerror-one-time-use-body // to fix #2485: https://stackoverflow.com/questions/55920957/cloudflare-worker-typeerror-one-time-use-body
redirect: "manual", redirect: "manual",
// @ts-ignore // @ts-ignore
duplex: "half", duplex: "half",
signal: controller.signal, signal: controller.signal,
}; };
const clonedBody = await req.text();
const jsonBody = JSON.parse(clonedBody) as { model?: string };
if (serverConfig.isAzure) {
baseUrl = `${baseUrl}/${jsonBody.model}`;
}
const fetchUrl = `${baseUrl}/${path}`;
// #1815 try to refuse gpt4 request // #1815 try to refuse gpt4 request
if (serverConfig.customModels && req.body) { if (serverConfig.customModels && clonedBody) {
try { try {
const modelTable = collectModelTable( const modelTable = collectModelTable(
DEFAULT_MODELS, DEFAULT_MODELS,