Skip to content

Commit

Permalink
fix: 修复环境变量BASE_URL设置为Cloudflare AI Gateway时,
Browse files Browse the repository at this point in the history
请求路径错误的问题
报错信息:
Unknown request URL:
POST /v1/v1/chat/completions?path=v1&path=chat&path=completions.
Please check the URL for typos,
or see the docs at https://platform.openai.com/docs/api-reference/.
  • Loading branch information
Evan committed Jul 5, 2024
1 parent c4a6c93 commit b8f2aa2
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions app/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down

0 comments on commit b8f2aa2

Please sign in to comment.