From a3a77006ffc1ca481436de1bcd359816cc7eafca Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Wed, 7 Jun 2023 02:24:45 +0800 Subject: [PATCH] fixup: #1815 req.body will be broken in edge runtime --- app/api/common.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index c650c545..787d5c6a 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -42,15 +42,19 @@ export async function requestOpenai(req: NextRequest) { }, cache: "no-store", method: req.method, - body: req.clone().body, + body: req.body, signal: controller.signal, }; // #1815 try to refuse gpt4 request - if (DISABLE_GPT4) { + if (DISABLE_GPT4 && req.body) { try { - const clonedBody = await req.clone().json(); - if ((clonedBody?.model ?? "").includes("gpt-4")) { + const clonedBody = await req.text(); + fetchOptions.body = clonedBody; + + const jsonBody = JSON.parse(clonedBody); + + if ((jsonBody?.model ?? "").includes("gpt-4")) { return NextResponse.json( { error: true,