Skip to content

Commit

Permalink
feat: 修改openai的请求url,之前env填写base_url=cloudflare ai
Browse files Browse the repository at this point in the history
getway的时候会报错,
{
  "error": {
    "type": "invalid_request_error",
    "code": "unknown_url",
    "message": "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/.",
    "param": null
  }
}
  • Loading branch information
Evan committed Jul 4, 2024
1 parent 8cb204e commit 549c0f1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions app/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 549c0f1

Please sign in to comment.