mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-11-05 17:46:11 +08:00
.github
.husky
app
api
client
components
config
icons
locales
masks
store
styles
utils
cloud
audio.ts
auth-settings-events.ts
baidu.ts
chat.ts
clone.ts
cloudflare.ts
cors.ts
format.ts
hmac.ts
hooks.ts
indexedDB-storage.ts
merge.ts
model.ts
ms_edge_tts.ts
object.ts
store.ts
sync.ts
tencent.ts
token.ts
command.ts
constant.ts
global.d.ts
layout.tsx
page.tsx
polyfill.ts
typing.ts
utils.ts
docs
public
scripts
src-tauri
.babelrc
.dockerignore
.env.template
.eslintignore
.eslintrc.json
.gitignore
.gitpod.yml
.lintstagedrc.json
.prettierrc.js
CODE_OF_CONDUCT.md
Dockerfile
LICENSE
README.md
README_CN.md
README_JA.md
docker-compose.yml
next.config.mjs
package.json
tsconfig.json
vercel.json
yarn.lock
27 lines
1.2 KiB
TypeScript
27 lines
1.2 KiB
TypeScript
export function cloudflareAIGatewayUrl(fetchUrl: string) {
|
|
// rebuild fetchUrl, if using cloudflare ai gateway
|
|
// document: https://developers.cloudflare.com/ai-gateway/providers/openai/
|
|
|
|
const paths = fetchUrl.split("/");
|
|
if ("gateway.ai.cloudflare.com" == paths[2]) {
|
|
// is cloudflare.com ai gateway
|
|
// https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/azure-openai/{resource_name}/{deployment_name}/chat/completions?api-version=2023-05-15'
|
|
if ("azure-openai" == paths[6]) {
|
|
// is azure gateway
|
|
return paths.slice(0, 8).concat(paths.slice(-3)).join("/"); // rebuild ai gateway azure_url
|
|
}
|
|
// https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions
|
|
if ("openai" == paths[6]) {
|
|
// is openai gateway
|
|
return paths.slice(0, 7).concat(paths.slice(-2)).join("/"); // rebuild ai gateway openai_url
|
|
}
|
|
// https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/anthropic/v1/messages \
|
|
if ("anthropic" == paths[6]) {
|
|
// is anthropic gateway
|
|
return paths.slice(0, 7).concat(paths.slice(-2)).join("/"); // rebuild ai gateway anthropic_url
|
|
}
|
|
// TODO: Amazon Bedrock, Groq, HuggingFace...
|
|
}
|
|
return fetchUrl;
|
|
}
|