From b8f2aa2c2082f1f77734ebee1348f0e0177b9021 Mon Sep 17 00:00:00 2001 From: Evan Date: Fri, 5 Jul 2024 09:24:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8FBASE=5FURL=E8=AE=BE=E7=BD=AE=E4=B8=BACloudfla?= =?UTF-8?q?re=20AI=20Gateway=E6=97=B6=EF=BC=8C=20=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20=E6=8A=A5=E9=94=99=E4=BF=A1=E6=81=AF=EF=BC=9A=20Unknown=20re?= =?UTF-8?q?quest=20URL:=20POST=20/v1/v1/chat/completions=3Fpath=3Dv1&path?= =?UTF-8?q?=3Dchat&path=3Dcompletions.=20Please=20check=20the=20URL=20for?= =?UTF-8?q?=20typos,=20or=20see=20the=20docs=20at=20https://platform.opena?= =?UTF-8?q?i.com/docs/api-reference/.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/common.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index 1454fde2ed1..222f2cedc21 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -30,11 +30,6 @@ export async function requestOpenai(req: NextRequest) { authHeaderName = "Authorization"; } - let path = `${req.nextUrl.pathname}${req.nextUrl.search}`.replaceAll( - "/api/openai/", - "", - ); - let baseUrl = serverConfig.azureUrl || serverConfig.baseUrl || OPENAI_BASE_URL; @@ -45,16 +40,21 @@ export async function requestOpenai(req: NextRequest) { if (baseUrl.endsWith("/")) { baseUrl = baseUrl.slice(0, -1); } - + let path = baseUrl.startsWith("https://gateway.ai.cloudflare.com") + ? `${req.nextUrl.pathname}${req.nextUrl.search}`.replaceAll( + "/api/openai/v1/", + "", + ) + : `${req.nextUrl.pathname}${req.nextUrl.search}`.replaceAll( + "/api/openai/", + "", + ); console.log("[Proxy] ", path); console.log("[Base Url]", baseUrl); - const timeoutId = setTimeout( - () => { - controller.abort(); - }, - 10 * 60 * 1000, - ); + const timeoutId = setTimeout(() => { + controller.abort(); + }, 10 * 60 * 1000); if (serverConfig.isAzure) { if (!serverConfig.azureApiVersion) {