-
Notifications
You must be signed in to change notification settings - Fork 61.2k
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
feat:Add Amazon Bedrock to support the leading large language models such as Amazon Nova, Claude, Llama, Mistral, and others. #6237
base: main
Are you sure you want to change the base?
Conversation
修改: app/api/auth.ts 新文件: app/api/bedrock.ts 新文件: app/api/bedrock/models.ts 新文件: app/api/bedrock/utils.ts 修改: app/client/api.ts 新文件: app/client/platforms/bedrock.ts 修改: app/components/settings.tsx 修改: app/config/server.ts 修改: app/constant.ts 修改: app/locales/cn.ts 修改: app/locales/en.ts 修改: app/store/access.ts 修改: app/utils.ts 修改: package.json
修改: app/api/bedrock/models.ts 修改: app/api/bedrock/utils.ts 修改: app/client/api.ts 修改: app/client/platforms/bedrock.ts 新文件: app/components/chat-actions.tsx 修改: app/components/chat.module.scss 修改: app/components/chat.tsx 修改: app/constant.ts 新文件: app/icons/document.svg 修改: app/locales/cn.ts 修改: app/locales/en.ts
删除: app/api/bedrock/models.ts 删除: app/api/bedrock/utils.ts 修改: app/client/platforms/bedrock.ts 删除: app/components/chat-actions.tsx 修改: app/components/chat.tsx 修改: app/constant.ts 删除: app/icons/document.svg
修改: app/api/auth.ts 修改: app/api/bedrock.ts 修改: app/client/api.ts 修改: app/client/platforms/bedrock.ts 修改: app/components/settings.tsx 修改: app/config/server.ts 修改: app/constant.t
修改: app/client/platforms/bedrock.ts
修改: app/utils.ts
修改: app/client/api.ts 修改: app/store/access.ts 新文件: app/utils/encryption.ts 修改: package.json
修改: app/components/ui-lib.tsx 修改: app/constant.ts 修改: app/utils/encryption.ts
修改: app/client/platforms/bedrock.ts
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@glayyiyi is attempting to deploy a commit to the NextChat Team on Vercel. A member of the Team first needs to authorize it. |
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis update integrates AWS Bedrock support into the application. New configuration options for AWS credentials are added, and a dedicated API route, handler, and client-side implementation are introduced for Bedrock. The changes include updates in authentication, credential management, and request signing. Additionally, UI components and localization entries are extended to accommodate Bedrock settings. Utility functions for encryption, decryption, and AWS signing have also been implemented, and related documentation has been provided. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Frontend
participant API_Gateway
participant Bedrock_Handler
participant AWS_Service
Client->>Frontend: Initiate Bedrock request
Frontend->>API_Gateway: Send API request with credentials
API_Gateway->>Bedrock_Handler: Route to Bedrock handler
Bedrock_Handler->>AWS_Service: Sign & forward request using AWS credentials
AWS_Service-->>Bedrock_Handler: Return response data
Bedrock_Handler-->>API_Gateway: Send processed data
API_Gateway-->>Frontend: Relay response back to client
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🔭 Outside diff range comments (1)
app/components/ui-lib.tsx (1)
573-607
: 🛠️ Refactor suggestionConsider adding error handling to FullScreen component.
The fullscreen API calls could fail and should be handled gracefully.
Add error handling:
const toggleFullscreen = useCallback(() => { + try { if (!document.fullscreenElement) { - ref.current?.requestFullscreen(); + await ref.current?.requestFullscreen(); } else { - document.exitFullscreen(); + await document.exitFullscreen(); } + } catch (error) { + console.error('Failed to toggle fullscreen:', error); + // Optionally show user-friendly error message + } -}, []); +}, [ref]);
🧹 Nitpick comments (16)
app/api/bedrock.ts (3)
60-62
: Reevaluate the 10-minute timeout duration.A 10-minute (600,000ms) request timeout might be too long or untuned depending on application requirements. If streaming is required, consider implementing a more nuanced approach, such as sending keep-alive signals or adjusting for expected payload sizes to avoid unintended timeouts.
139-141
: Clarify user-facing error messages for empty response body.Throwing a generic error (“Empty response from Bedrock…”) might confuse users if AWS returns an unexpected but valid response. Consider returning more contextual information, or verifying the scenario before failing.
171-176
: Return standardized error objects for better client-side handling.Currently, all caught errors return a JSON object without a uniform structure. Consider returning a custom error interface (e.g.,
{ error: true, code: <code>, message: <message> }
) to facilitate consistent error handling in the client.app/utils/aws.ts (2)
57-91
: AES-GCM encryption appears correct, but confirm it’s suitable for all runtime environments.Your encryption logic correctly employs AES-GCM with PBKDF2-based key derivation. However, ensure that Web Crypto is available (e.g., in Node.js <19 scenarios, polyfills may be required). Confirm the environment’s support for
crypto.subtle
to prevent runtime incompatibilities.
335-336
: Provide more context when signing fails.Currently, the error logs only “Failed to sign AWS request”. Adding relevant details (e.g., region, service, truncated resource path) in a sanitized form can assist in debugging signature issues while avoiding sensitive data leakage.
app/client/platforms/bedrock.ts (5)
45-46
: Remove the commented-out line.Line 46 is commented out, and it appears to be a leftover. Minimizing dead or commented-out code helps maintain clarity and cleanliness in the codebase.
45 const isApp = !!getClientConfig()?.isApp; -46 // const isApp = true;
47-88
: Validate AWS credential fields before signing.Currently, the function does not verify that essential fields (e.g., region, accessKey, secretKey) are non-empty. If any of these fields are missing, the signing process may fail downstream or produce invalid headers. Consider adding a validation step or error handling to improve reliability.
111-378
: Break down this large function into smaller units.
formatRequestBody
handles several model-specific logic branches (Nova, Titan, LLaMA, Mistral, Claude), making the function lengthy and less maintainable. Consider extracting each branch into a dedicated helper function to enhance clarity and reduce complexity.
591-597
: Consider implementing or documenting the usage and models endpoints.Both
usage()
andmodels()
return static or empty data. If you plan to support usage tracking or model enumeration in the future, add a TODO comment or implement the desired functionality to avoid confusion.
600-859
: Consider refactoring the streaming and tool call logic.
bedrockStream
is lengthy and handles multiple responsibilities, from streaming event chunks to tool calls and finalizing the response. Splitting these concerns into smaller, focused functions can improve readability and make long-term maintenance easier.🧰 Tools
🪛 Biome (1.9.4)
[error] 604-604: Don't use 'Function' as a type.
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
(lint/complexity/noBannedTypes)
app/config/server.ts (1)
157-160
: Consider adding validation for AWS credentials format.While the code checks for the presence of AWS credentials, it doesn't validate their format.
Consider adding basic format validation:
const isBedrock = - !!process.env.AWS_REGION && - !!process.env.AWS_ACCESS_KEY && - !!process.env.AWS_SECRET_KEY; + !!process.env.AWS_REGION?.trim() && + /^[A-Z0-9]{20}$/i.test(process.env.AWS_ACCESS_KEY?.trim() ?? '') && + /^[A-Za-z0-9/+=]{40}$/.test(process.env.AWS_SECRET_KEY?.trim() ?? '');app/client/api.ts (1)
255-255
: Consider refactoring the conditional header logic.The nested if-else structure for header handling could be simplified.
Consider using early returns:
- if (isBedrock) { - if (apiKey) { - headers[authHeader] = getBearerToken(apiKey); - } - } else { - const bearerToken = getBearerToken( - apiKey, - isAzure || isAnthropic || isGoogle, - ); - - if (bearerToken) { - headers[authHeader] = bearerToken; - } else if (isEnabledAccessControl && validString(accessStore.accessCode)) { - headers["Authorization"] = getBearerToken( - ACCESS_CODE_PREFIX + accessStore.accessCode, - ); - } - } + if (isBedrock && apiKey) { + headers[authHeader] = getBearerToken(apiKey); + return headers; + } + + const bearerToken = getBearerToken( + apiKey, + isAzure || isAnthropic || isGoogle, + ); + + if (bearerToken) { + headers[authHeader] = bearerToken; + return headers; + } + + if (isEnabledAccessControl && validString(accessStore.accessCode)) { + headers["Authorization"] = getBearerToken( + ACCESS_CODE_PREFIX + accessStore.accessCode, + ); + }Also applies to: 346-363
app/utils.ts (1)
347-353
: Consider using constants for model names.The model names are hardcoded in the condition. This could lead to maintenance issues if model names change.
Consider using constants:
+const BEDROCK_PLUGIN_MODELS = { + CLAUDE_3: "claude-3", + MISTRAL_LARGE: "mistral-large", + AMAZON_NOVA: "amazon.nova" +} as const; + if ( - (provider == ServiceProvider.Bedrock && model.includes("claude-3")) || - model.includes("mistral-large") || - model.includes("amazon.nova") + (provider == ServiceProvider.Bedrock && model.includes(BEDROCK_PLUGIN_MODELS.CLAUDE_3)) || + model.includes(BEDROCK_PLUGIN_MODELS.MISTRAL_LARGE) || + model.includes(BEDROCK_PLUGIN_MODELS.AMAZON_NOVA) )app/components/ui-lib.tsx (1)
273-312
: Consider adding accessibility improvements to PasswordInput.While the masking functionality is good, the component could benefit from better accessibility.
Consider adding ARIA attributes and keyboard handling:
<div className={"password-input-container"}> <IconButton aria={props.aria} icon={visible ? <EyeIcon /> : <EyeOffIcon />} onClick={changeVisibility} + onKeyDown={(e) => e.key === 'Enter' && changeVisibility()} + role="button" + aria-label={visible ? "Hide password" : "Show password"} + tabIndex={0} className={"password-eye"} /> <input {...inputProps} value={displayValue} onChange={onChange} onFocus={() => setIsEditing(true)} onBlur={() => setIsEditing(false)} type={visible ? "text" : "password"} + aria-label="Password input" className={"password-input"} /> </div>.env.template (1)
79-84
: New AWS Bedrock Configuration Variables Added
The new “bedrock” section introduces the environment variablesAWS_REGION
,AWS_ACCESS_KEY
, andAWS_SECRET_KEY
needed for AWS Bedrock integration. These keys enable the authentication and request signing necessary for Bedrock services.
Consider adding a brief inline comment for each variable to clarify its role and expected format, and ensure that placeholder values (e.g.,AKIA
) are clearly marked as examples to avoid accidental use of production credentials.docs/bedrock-response-format.md (1)
5-10
: Specify Language for Fenced Code Blocks
The fenced code block demonstrating the SSE chunk header currently does not specify a language, triggering markdownlint Fenced Code Block warnings. To improve clarity and adhere to best practices, consider adding a language specifier (e.g.,text
) as shown below:-``` +```textThis change will enhance readability in Markdown editors and documentation renderers.
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
5-5: Fenced code blocks should have a language specified
null(MD040, fenced-code-language)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
📒 Files selected for processing (18)
.env.template
(1 hunks)app/api/[provider]/[...path]/route.ts
(2 hunks)app/api/auth.ts
(1 hunks)app/api/bedrock.ts
(1 hunks)app/client/api.ts
(6 hunks)app/client/platforms/bedrock.ts
(1 hunks)app/components/chat.module.scss
(1 hunks)app/components/settings.tsx
(2 hunks)app/components/ui-lib.tsx
(4 hunks)app/config/server.ts
(3 hunks)app/constant.ts
(8 hunks)app/locales/cn.ts
(1 hunks)app/locales/en.ts
(1 hunks)app/store/access.ts
(7 hunks)app/utils.ts
(1 hunks)app/utils/aws.ts
(1 hunks)docs/bedrock-response-format.md
(1 hunks)package.json
(1 hunks)
✅ Files skipped from review due to trivial changes (2)
- package.json
- app/components/chat.module.scss
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/bedrock-response-format.md
5-5: Fenced code blocks should have a language specified
null
(MD040, fenced-code-language)
🪛 Biome (1.9.4)
app/client/platforms/bedrock.ts
[error] 604-604: Don't use 'Function' as a type.
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
(lint/complexity/noBannedTypes)
app/utils/aws.ts
[error] 417-417: Unexpected control character in a regular expression.
Control characters are unusual and potentially incorrect inputs, so they are disallowed.
(lint/suspicious/noControlCharactersInRegex)
[error] 417-417: Unexpected control character in a regular expression.
Control characters are unusual and potentially incorrect inputs, so they are disallowed.
(lint/suspicious/noControlCharactersInRegex)
🔇 Additional comments (22)
app/api/bedrock.ts (1)
25-37
: Consider validating multi-colon credentials more strictly.If the credentials after "Bearer " contain multiple colons beyond the expected three-part split (
region
,accessKey
,secretKey
), it could cause incorrect parsing or runtime errors. Adding stricter validation or sanitization of the credential string would help ensure robust error handling.app/store/access.ts (3)
201-201
: Bedrock validation looks good.The
isValidBedrock
method comprehensively checks required fields for AWS usage, which is essential for ensuring that any requests sent to Bedrock are properly authenticated.Also applies to: 217-224
288-306
: Guard against double encryption on repeated calls to set().If
set()
is invoked multiple times without resetting/in-memory tracking, there is a risk of encrypting already-encrypted credentials, leading to decryption errors. Consider adding a check or a sentinel to avoid re-encrypting existing cipher text.
308-323
: Validate decryption inputs to avoid runtime errors.When retrieving AWS credentials, if an improperly formatted cipher string or mismatch with the stored encryption key exists, decryption may fail. To prevent confusion, add additional guards (e.g., checking for the expected “separator” count) to handle partial or invalid data gracefully.
app/client/platforms/bedrock.ts (2)
90-104
: Revisit client-side credential usage and encryption.Storing credentials client-side (even encrypted) can pose security risks if the
encryptionKey
is guessable or if the environment allows reverse engineering. Verify that this approach aligns with your security requirements and ensure that sensitive information is properly protected.
380-589
: Handle potential failures from image preprocessing.
preProcessImageContent
might fail or return unexpected data. Currently, the code does not explicitly handle errors or validate the returned content. Adding error handling or fallback logic for malformed image data can improve robustness.app/api/[provider]/[...path]/route.ts (2)
4-4
: New Bedsrock import appears correct.Importing the Bedrock handler is consistent with other provider imports. No issues here.
27-28
: Bedrock route handling looks good.Introducing this case for
ApiPath.Bedrock
correctly delegates requests to thebedrockHandler
. The implementation aligns with the existing pattern for other providers.app/api/auth.ts (1)
103-110
: Verify potential credential exposure in logs.Including
awsRegion
,awsAccessKey
, andawsSecretKey
in thesystemApiKey
might inadvertently expose sensitive details if logged or shared. Ensure no logs will print these credentials, or further secure how they're stored and transmitted.app/config/server.ts (1)
16-20
: LGTM! Well-structured AWS environment variables.The AWS-related environment variables are properly defined as optional string types and well-documented with clear comments.
app/client/api.ts (2)
26-26
: LGTM! Clean BedrockApi integration.The BedrockApi is properly imported and initialized following the existing pattern for other providers.
Also applies to: 137-139
370-371
: LGTM! Proper Bedrock client initialization.The Bedrock case in getClientApi follows the consistent pattern used for other providers.
app/locales/cn.ts (1)
346-371
: LGTM! Well-structured localization strings for Bedrock configuration.The localization strings are clear, consistent, and provide good user guidance with specific validation requirements.
app/constant.ts (5)
57-76
: LGTM! API path addition is consistent with existing patterns.The
ApiPath.Bedrock
addition follows the established pattern and maintains consistency with other providers.
118-135
: LGTM! Service provider enum updated correctly.The
ServiceProvider.Bedrock
addition maintains alphabetical order and follows the naming convention.
261-269
: LGTM! Well-structured Bedrock configuration.The Bedrock configuration follows the established pattern with appropriate defaults and helper methods.
513-533
: LGTM! Comprehensive model list for Bedrock.The model list is well-organized by provider (Amazon Nova, Claude, Llama, Mistral) and includes version information.
478-480
: LGTM! Vision model regex patterns added correctly.The regex patterns for
nova-lite
andnova-pro
are properly formatted and placed in the list.app/locales/en.ts (1)
350-376
: LGTM! Well-structured English localization strings for Bedrock configuration.The localization strings are clear, consistent, and provide good user guidance with specific validation requirements.
app/components/settings.tsx (2)
969-1051
: LGTM! Well-implemented Bedrock configuration component.The component follows established patterns, includes proper validation, and integrates well with the access store and localization system.
A few notable features:
- Proper use of aria labels for accessibility
- Consistent use of PasswordInput for sensitive fields
- Input validation with user feedback
- Secure handling of AWS credentials
1891-1892
: LGTM! Proper integration in the settings UI.The Bedrock configuration component is correctly placed in the provider configuration list.
docs/bedrock-response-format.md (1)
1-259
: Comprehensive Bedrock Response Format Documentation
This new documentation file is detailed and well-organized. It covers the Server-Sent Events (SSE) format and provides clear, model-specific JSON examples for Claude 3, Mistral, Llama, and Titan. The explanation of how thetransformBedrockStream
function processes these responses adds valuable context.
Make sure to keep this documentation in sync with any future changes in the response processing logic or model specifications.🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
5-5: Fenced code blocks should have a language specified
null(MD040, fenced-code-language)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
app/constant.ts (1)
261-269
: Consider making the region configurable.The Bedrock configuration looks good, but the default region is hardcoded in both the
getEndpoint
function and theBEDROCK_BASE_URL
constant.Consider this improvement:
-export const BEDROCK_BASE_URL = Bedrock.getEndpoint(); +export const BEDROCK_BASE_URL = (region?: string) => Bedrock.getEndpoint(region);This would allow the region to be configured at runtime based on user preferences or environment settings.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/constant.ts
(8 hunks)
🔇 Additional comments (4)
app/constant.ts (4)
59-59
: LGTM! Consistent enum additions for Bedrock integration.The additions to
ApiPath
,ServiceProvider
, andModelProvider
enums are consistent and properly aligned.Also applies to: 133-133, 160-160
478-479
: LGTM! Vision model support for Nova models.The addition of Nova models to
VISION_MODEL_REGEXES
is appropriate for enabling vision capabilities.
836-846
: LGTM! Consistent provider configuration.The Bedrock provider configuration in
DEFAULT_MODELS
follows the established pattern and maintains consistent sorting.
513-533
:❓ Verification inconclusive
Verify model versions and availability.
The Bedrock models list includes various models from different providers (Amazon, Anthropic, Meta, Mistral). Let's verify their versions and availability.
🌐 Web query:
What are the latest available models on Amazon Bedrock?
💡 Result:
As of December 2024, Amazon Bedrock offers a comprehensive selection of cutting-edge AI models across multiple modalities and use cases. Here's an overview of the latest developments:
Core Model Updates
Amazon Proprietary Models:
- Nova Series: New generation replacing Titan Text G1 models[2][6]
- Nova Micro: Low-latency text model (<100ms response time)
- Nova Pro: High-performance text model for complex tasks
- Nova Canvas: Multimodal image generator replacing Titan Image Generator[2][6]
Anthropic:
- Claude 3.5 Series: Latest generation with enhanced reasoning[8]
- Claude 3.5 Sonnet (405B parameters): Top-tier performance for enterprise use
- Claude 3.5 Haiku: Fastest model for real-time applications
Meta:
- Llama 3.2 Series: Improved instruction-following capabilities[1]
- 1B/3B Instruct: Lightweight options
- 90B Vision Instruct: Multimodal model combining text+vision
Stability AI:
- SD3 Large v1: Advanced text-to-image generation[7]
- Stable Image Ultra v1: Photorealistic image synthesis[1]
New Model Additions
Provider Notable Models Key Features Cohere Command R+ v1 Enhanced RAG capabilities Mistral AI Mistral Large 2 Improved multilingual understanding Luma AI (Marketplace) Specialized 3D content generation Key Infrastructure Improvements
- Rerank Models: Amazon Rerank + Cohere Rerank 3.5 for improved search accuracy[1]
- Marketplace Expansion: Over 122 specialized models including medical/financial domain-specific options[1][10]
Model Lifecycle Updates (Legacy Phase-outs)
Older versions being replaced include:
- Claude v2/v2.1 (EOL July 2025 → replaced by Claude 3.5)[2]
- Titan Text G1 series (EOL August 2025 → replaced by Nova)[2][6]
- SDXL 1.0 (EOL May 2025 → replaced by Stable Image Core/Ultra)[2]
The total model count reaches 174 when combining Serverless (52) and Marketplace (122) offerings across supported regions[1]. New multimodal capabilities and enterprise-grade safety features position Bedrock as a comprehensive platform for generative AI implementation[1][6].
Citations:
- 1: https://hidekazu-konishi.com/entry/amazon_bedrock_models_as_of_2024.html
- 2: https://docs.aws.amazon.com/bedrock/latest/userguide/model-lifecycle.html
- 3: https://www.economize.cloud/blog/aws-bedrock-foundation-models-list/
- 4: https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html
- 5: https://aws.amazon.com/bedrock/
- 6: https://www.aboutamazon.com/news/aws/amazon-nova-artificial-intelligence-bedrock-aws
- 7: https://aws.amazon.com/bedrock/stability-ai/
- 8: https://aws.amazon.com/bedrock/claude/
- 9: https://docs.aws.amazon.com/bedrock/latest/userguide/foundation-models-reference.html
- 10: https://www.artificialintelligence-news.com/news/amazon-bedrock-gains-new-ai-models-tools-and-features/
Attention: Confirm Model Identifiers and Update if Necessary
After checking the latest Amazon Bedrock documentation, I noted the following:
- Amazon Models:
- The Nova series in your code includes "nova-micro" and "nova-pro," which match the documentation.
- However, "us.amazon.nova-lite-v1:0" isn’t mentioned in the latest list—instead, Nova Canvas appears as the new addition. Please verify if "nova-lite" is deprecated or should be replaced with "nova-canvas."
- Anthropic and Meta Models:
- Ensure that the Anthropic model names consistently target the newer Claude 3.5 series rather than a mix of "claude-3" and "claude-3-5."
- For Meta models, check that using multiple variants (e.g., llama3-1, llama3-2, llama3-3) aligns with the current Llama 3.2 series recommendations.
- Mistral Models:
- The Mistral model identifiers appear in line with current expectations, but verifying them against the latest Bedrock update might be beneficial.
Please review these points in the context of
app/constant.ts
(lines 513-533) and update the model identifiers if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
app/client/api.ts (1)
351-368
: Auth handling properly implemented for Bedrock provider.The code correctly separates Bedrock authorization handling from other providers. This implementation ensures that the appropriate auth headers are set based on the provider type.
However, consider refactoring this growing conditional logic in the future as more providers are added to improve maintainability.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
app/client/api.ts
(6 hunks)app/constant.ts
(8 hunks)
🔇 Additional comments (9)
app/client/api.ts (4)
26-26
: Proper import of the new Bedrock API module.The BedrockApi import is correctly added to support the new Amazon Bedrock functionality.
142-144
: Good implementation of Bedrock provider support in ClientApi.The Bedrock case is correctly added to the provider switch statement, following the same pattern as other providers.
260-260
: Correctly identifies Bedrock provider in model configuration.The
isBedrock
flag is properly initialized and added to the returned configuration object.Also applies to: 301-301
375-376
: Appropriate client API factory method for Bedrock.The Bedrock case is correctly added to the getClientApi function, maintaining consistency with other providers.
app/constant.ts (5)
59-59
: Consistent enum updates for Bedrock provider.The Bedrock provider is correctly added to all relevant enums (ApiPath, ServiceProvider, ModelProvider), maintaining consistency throughout the application.
Also applies to: 133-133, 160-160
266-274
: Well-structured Bedrock configuration object.The Bedrock configuration includes all necessary properties and a useful
getEndpoint
function that dynamically constructs the AWS Bedrock endpoint URL based on the region, which is a good practice for AWS services.The
BEDROCK_BASE_URL
constant is initialized with a default region, which should be overridden with the user's configured region when making actual API calls.
483-484
: Vision model regex patterns updated for Nova models.The addition of regex patterns for
nova-lite
andnova-pro
properly enables vision capabilities for these Amazon Bedrock models.
518-538
: Comprehensive Bedrock model list implementation.The
bedrockModels
array includes a good selection of models from different providers available through AWS Bedrock:
- Amazon Nova models (micro, lite, pro)
- Claude models from Anthropic
- Meta Llama 3 models in various sizes
- Mistral models
All models include their proper version identifiers following AWS Bedrock's naming convention.
846-857
: Proper integration of Bedrock models into the default models list.The Bedrock models are correctly added to the DEFAULT_MODELS array with appropriate provider information and sorting, maintaining consistency with other providers.
修改: app/constant.ts
…GPT-Next-Web into feature/bedrock 合并到主题分支。
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
This PR introduces AWS Bedrock to support the leading large language models such as Claude, Llama, Mistral, and others.
API Enhancements:
app/api/bedrock.ts
)app/client/api.ts
)app/client/platforms/bedrock.ts
)app/utils/aws.ts
)Localization:
app/locales/cn.ts
)app/locales/en.ts
)Configuration:
app/constant.ts
)Documentation:
📝 补充信息 | Additional Information
These changes leveraging Amazon Bedrock provides access to cutting-edge language models, offering several advantages:
Access to State-of-the-Art Models: Users can now utilize the latest versions of Llama 3.2, Mistral Large, and Claude 3.5, which are known for their advanced natural language understanding and generation capabilities.
Summary by CodeRabbit
New Features
Bug Fixes & Style
Documentation