Skip to content

集成 AWS Bedrock 作为新的 LLM 服务提供商 #6430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ DISABLE_FAST_LINK=
# (optional)
# Default: Empty
# To control custom models, use + to add a custom model, use - to hide a model, use name=displayName to customize model name, separated by comma.
CUSTOM_MODELS=
CUSTOM_MODELS=-all,+gpt-4o-2024-11-20@openai=gpt-4o,+gpt-4o-mini@openai,+us.anthropic.claude-3-5-sonnet-20241022-v2:0@bedrock=sonnet

# (optional)
# Default: Empty
Expand All @@ -81,3 +81,22 @@ SILICONFLOW_API_KEY=

### siliconflow Api url (optional)
SILICONFLOW_URL=

# --- AWS Bedrock Section ---
# Ensure these lines for keys either have placeholder values like below,
# are commented out entirely, or removed if they shouldn't be in the template.

# AWS Access Key for Bedrock API (Example: Use placeholder or comment out)
# AWS_ACCESS_KEY_ID=

# AWS Secret Access Key for Bedrock API (Example: Use placeholder or comment out)
# AWS_SECRET_ACCESS_KEY=

# AWS Region for Bedrock API (e.g. us-east-1, us-west-2)
AWS_REGION=

# Enable AWS Bedrock models (set to "true" to enable)
ENABLE_AWS_BEDROCK=

# Custom endpoint URL for AWS Bedrock (optional)
AWS_BEDROCK_ENDPOINT=
3 changes: 3 additions & 0 deletions app/api/[provider]/[...path]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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(
Expand Down Expand Up @@ -50,6 +51,8 @@ async function handle(
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:
Expand Down
18 changes: 9 additions & 9 deletions app/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ export function auth(req: NextRequest, modelProvider: ModelProvider) {
// if user does not provide an api key, inject system api key
if (!apiKey) {
const serverConfig = getServerSideConfig();

// const systemApiKey =
// modelProvider === ModelProvider.GeminiPro
// ? serverConfig.googleApiKey
// : serverConfig.isAzure
// ? serverConfig.azureApiKey
// : serverConfig.apiKey;

let systemApiKey: string | undefined;

switch (modelProvider) {
Expand Down Expand Up @@ -104,6 +96,11 @@ export function auth(req: NextRequest, modelProvider: ModelProvider) {
case ModelProvider.SiliconFlow:
systemApiKey = serverConfig.siliconFlowApiKey;
break;
case ModelProvider.Bedrock:
console.log(
"[Auth] Using AWS credentials for Bedrock, no API key override.",
);
return { error: false };
case ModelProvider.GPT:
Comment on lines +99 to 104
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Verify AWS credentials before returning.
This block immediately returns { error: false } for Bedrock, skipping an explicit credential validation step. Consider ensuring that AWS credential checks (e.g., presence of required environment variables) have definitively passed before returning success.

🧰 Tools
🪛 Biome (1.9.4)

[error] 104-104: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

default:
if (req.nextUrl.pathname.includes("azure/deployments")) {
Expand All @@ -117,7 +114,10 @@ export function auth(req: NextRequest, modelProvider: ModelProvider) {
console.log("[Auth] use system api key");
req.headers.set("Authorization", `Bearer ${systemApiKey}`);
} else {
console.log("[Auth] admin did not provide an api key");
console.log(
"[Auth] admin did not provide an api key for provider:",
modelProvider,
);
}
} else {
console.log("[Auth] use user api key");
Expand Down
Loading
Loading