From 64453bb15dd0ed7d693dd3888d6c299e0a7c527b Mon Sep 17 00:00:00 2001 From: Hk-Gosuto Date: Thu, 8 Feb 2024 14:23:50 +0800 Subject: [PATCH] fix: #180 --- app/api/common.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index 58037645e..d931edc19 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -65,10 +65,14 @@ export async function requestOpenai(req: NextRequest) { path = makeAzurePath(path, serverConfig.azureApiVersion); } - const clonedBody = await req.text(); - const jsonBody = JSON.parse(clonedBody) as { model?: string }; + let jsonBody; + let clonedBody; + if (req.method !== "GET" && req.method !== "HEAD") { + clonedBody = await req.text(); + jsonBody = JSON.parse(clonedBody) as { model?: string }; + } if (serverConfig.isAzure) { - baseUrl = `${baseUrl}/${jsonBody.model}`; + baseUrl = `${baseUrl}/${jsonBody?.model}`; } const fetchUrl = `${baseUrl}/${path}`; const fetchOptions: RequestInit = {