mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-21 13:10:16 +09:00

Adds support for using models hosted on AWS Bedrock, specifically Anthropic Claude models. Key changes: - Added '@aws-sdk/client-bedrock-runtime' dependency. - Updated constants, server config, and auth logic for Bedrock. - Implemented backend API handler () to communicate with the Bedrock API, handling streaming and non-streaming responses, and formatting output to be OpenAI compatible. - Updated dynamic API router () to dispatch requests to the Bedrock handler. - Created frontend client () and updated client factory (). - Updated with necessary Bedrock environment variables (AWS keys, region, enable flag) and an example for using to alias Bedrock models.
86 lines
2.7 KiB
TypeScript
86 lines
2.7 KiB
TypeScript
import { ApiPath } from "@/app/constant";
|
|
import { NextRequest } from "next/server";
|
|
import { handle as openaiHandler } from "../../openai";
|
|
import { handle as azureHandler } from "../../azure";
|
|
import { handle as googleHandler } from "../../google";
|
|
import { handle as anthropicHandler } from "../../anthropic";
|
|
import { handle as baiduHandler } from "../../baidu";
|
|
import { handle as bytedanceHandler } from "../../bytedance";
|
|
import { handle as alibabaHandler } from "../../alibaba";
|
|
import { handle as moonshotHandler } from "../../moonshot";
|
|
import { handle as stabilityHandler } from "../../stability";
|
|
import { handle as iflytekHandler } from "../../iflytek";
|
|
import { handle as deepseekHandler } from "../../deepseek";
|
|
import { handle as siliconflowHandler } from "../../siliconflow";
|
|
import { handle as xaiHandler } from "../../xai";
|
|
import { handle as chatglmHandler } from "../../glm";
|
|
import { handle as bedrockHandler } from "../../bedrock";
|
|
import { handle as proxyHandler } from "../../proxy";
|
|
|
|
async function handle(
|
|
req: NextRequest,
|
|
{ params }: { params: { provider: string; path: string[] } },
|
|
) {
|
|
const apiPath = `/api/${params.provider}`;
|
|
console.log(`[${params.provider} Route] params `, params);
|
|
switch (apiPath) {
|
|
case ApiPath.Azure:
|
|
return azureHandler(req, { params });
|
|
case ApiPath.Google:
|
|
return googleHandler(req, { params });
|
|
case ApiPath.Anthropic:
|
|
return anthropicHandler(req, { params });
|
|
case ApiPath.Baidu:
|
|
return baiduHandler(req, { params });
|
|
case ApiPath.ByteDance:
|
|
return bytedanceHandler(req, { params });
|
|
case ApiPath.Alibaba:
|
|
return alibabaHandler(req, { params });
|
|
// case ApiPath.Tencent: using "/api/tencent"
|
|
case ApiPath.Moonshot:
|
|
return moonshotHandler(req, { params });
|
|
case ApiPath.Stability:
|
|
return stabilityHandler(req, { params });
|
|
case ApiPath.Iflytek:
|
|
return iflytekHandler(req, { params });
|
|
case ApiPath.DeepSeek:
|
|
return deepseekHandler(req, { params });
|
|
case ApiPath.XAI:
|
|
return xaiHandler(req, { params });
|
|
case ApiPath.ChatGLM:
|
|
return chatglmHandler(req, { params });
|
|
case ApiPath.SiliconFlow:
|
|
return siliconflowHandler(req, { params });
|
|
case ApiPath.Bedrock:
|
|
return bedrockHandler(req, { params });
|
|
case ApiPath.OpenAI:
|
|
return openaiHandler(req, { params });
|
|
default:
|
|
return proxyHandler(req, { params });
|
|
}
|
|
}
|
|
|
|
export const GET = handle;
|
|
export const POST = handle;
|
|
|
|
export const runtime = "edge";
|
|
export const preferredRegion = [
|
|
"arn1",
|
|
"bom1",
|
|
"cdg1",
|
|
"cle1",
|
|
"cpt1",
|
|
"dub1",
|
|
"fra1",
|
|
"gru1",
|
|
"hnd1",
|
|
"iad1",
|
|
"icn1",
|
|
"kix1",
|
|
"lhr1",
|
|
"pdx1",
|
|
"sfo1",
|
|
"sin1",
|
|
"syd1",
|
|
];
|