From 445e05c63f8dddd325aa60e778a5db0b44c75fe9 Mon Sep 17 00:00:00 2001 From: Hk-Gosuto Date: Wed, 27 Dec 2023 12:17:39 +0800 Subject: [PATCH] fix: fix bug 124 --- app/api/common.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index c3bf87ec3..3031edfac 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -60,6 +60,12 @@ export async function requestOpenai(req: NextRequest) { 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 = { headers: { "Content-Type": "application/json", @@ -70,22 +76,16 @@ export async function requestOpenai(req: NextRequest) { }), }, method: req.method, - body: req.body, + body: clonedBody, // to fix #2485: https://stackoverflow.com/questions/55920957/cloudflare-worker-typeerror-one-time-use-body redirect: "manual", // @ts-ignore duplex: "half", 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 - if (serverConfig.customModels && req.body) { + if (serverConfig.customModels && clonedBody) { try { const modelTable = collectModelTable( DEFAULT_MODELS,