From 549c0f1e35e70cd1fef11f4c969a07ea309b1db2 Mon Sep 17 00:00:00 2001 From: Evan Date: Thu, 4 Jul 2024 17:43:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9openai=E7=9A=84?= =?UTF-8?q?=E8=AF=B7=E6=B1=82url=EF=BC=8C=E4=B9=8B=E5=89=8Denv=E5=A1=AB?= =?UTF-8?q?=E5=86=99base=5Furl=3Dcloudflare=20ai=20getway=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E4=BC=9A=E6=8A=A5=E9=94=99=EF=BC=8C=20{=20?= =?UTF-8?q?=20=20"error":=20{=20=20=20=20=20"type":=20"invalid=5Frequest?= =?UTF-8?q?=5Ferror",=20=20=20=20=20"code":=20"unknown=5Furl",=20=20=20=20?= =?UTF-8?q?=20"message":=20"Unknown=20request=20URL:=20POST=20/v1/v1/chat/?= =?UTF-8?q?completions=3Fpath=3Dv1&path=3Dchat&path=3Dcompletions.=20Pleas?= =?UTF-8?q?e=20check=20the=20URL=20for=20typos,=20or=20see=20the=20docs=20?= =?UTF-8?q?at=20https://platform.openai.com/docs/api-reference/.",=20=20?= =?UTF-8?q?=20=20=20"param":=20null=20=20=20}=20}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/common.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index a75f2de5cfa..3ddc153931e 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -24,11 +24,10 @@ export async function requestOpenai(req: NextRequest) { authValue = req.headers.get("Authorization") ?? ""; authHeaderName = "Authorization"; } - - let path = `${req.nextUrl.pathname}${req.nextUrl.search}`.replaceAll( - "/api/openai/", - "", - ); + const requestUrl = `${req.nextUrl.pathname}${req.nextUrl.search}`; + let path = requestUrl.startsWith("https://gateway.ai.cloudflare.com") + ? requestUrl.replaceAll("/api/openai/v1/", "") + : requestUrl.replaceAll("/api/openai/", ""); let baseUrl = serverConfig.azureUrl || serverConfig.baseUrl || OPENAI_BASE_URL;