feat:Add Amazon Bedrock to support the leading large language models such as Amazon Nova, Claude, Llama, Mistral, and others.
💻 变更类型 | Change Type
- [x] feat
🔀 变更说明 | Description of Change
This PR introduces AWS Bedrock to support the leading large language models such as Claude, Llama, Mistral, and others.
-
API Enhancements:
- Add Bedrock API integration (
app/api/bedrock.ts) - Updated client API integration (
app/client/api.ts) - Add Bedrock platform support (
app/client/platforms/bedrock.ts) - Add Bedrock platform util (
app/utils/aws.ts)
- Add Bedrock API integration (
-
Localization:
- Updated Chinese translations (
app/locales/cn.ts) - Updated English translations (
app/locales/en.ts)
- Updated Chinese translations (
-
Configuration:
- Modified constants and configurations (
app/constant.ts)
- Modified constants and configurations (
-
Documentation:
- Add the description of multiple Bedrock model responses format ('docs/bedrock-response-format.md')
📝 补充信息 | 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
- Added comprehensive AWS Bedrock integration with support for API routing, authentication, and streaming responses.
- Introduced new AWS configuration options (region, access key, secret key, encryption key) with dedicated settings UI and validation.
- Expanded localization support for Bedrock configuration in English and Chinese.
- Enhanced client API to support Bedrock models with tailored request formatting and authorization handling.
- Improved security by encrypting AWS credentials and adding password masking enhancements.
- Added fullscreen toggle component for improved UI experience.
- Updated model and provider lists to include Bedrock-specific models and endpoints.
-
Bug Fixes & Style
- Fixed CSS syntax issue in chat side panel styles.
- Refined icon mapping to support Bedrock-related models.
-
Documentation
- Added detailed documentation on AWS Bedrock streaming response format.
@glayyiyi is attempting to deploy a commit to the NextChat Team on Vercel.
A member of the Team first needs to authorize it.
Walkthrough
This 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
| File(s) | Change Summary |
|---|---|
.env.template, app/config/server.ts |
Added new AWS Bedrock environment variables (AWS_REGION, AWS_ACCESS_KEY, AWS_SECRET_KEY, ENCRYPTION_KEY) and an isBedrock flag to the configuration. |
app/api/[provider]/[...path]/route.ts, app/api/auth.ts, app/api/bedrock.ts |
Introduced a new Bedrock API endpoint with dedicated routing and handler logic. Authentication logic for ModelProvider.Bedrock is updated, and a complete Bedrock request flow (credential decryption, endpoint construction, error handling) has been implemented in a new file. |
app/client/api.ts, app/client/platforms/bedrock.ts |
Integrated Bedrock support in the client API. A new BedrockApi class is implemented to handle chat, usage, and model queries, and the main ClientApi has been updated to instantiate Bedrock for the relevant provider. |
app/components/settings.tsx, app/components/ui-lib.tsx, app/components/chat.module.scss |
Updated the UI to include a Bedrock configuration component with fields for AWS credentials and encryption key. Also improved password masking with a new maskWhenShow property and added a FullScreen component; a minor CSS syntax fix was applied. |
app/constant.ts, app/locales/cn.ts, app/locales/en.ts |
Added new enum entries and constants for Bedrock. Localization files now include translations and guidance for AWS Bedrock configuration (region, keys, encryption key), and default models now incorporate a list of Bedrock models. |
app/store/access.ts |
Expanded the access store with AWS Bedrock support. New default URL, credential validation (isValidBedrock), and secure encryption/decryption methods have been added to protect AWS credentials. |
app/utils.ts, app/utils/aws.ts |
Introduced new AWS utility functions for encryption/decryption, signing requests, base64 conversions, and processing streaming responses for Bedrock. A new interface for Bedrock credentials and several functions to manage cryptographic operations now support secure AWS interactions. |
docs/bedrock-response-format.md |
Documented the AWS Bedrock streaming response format, detailing the structure of SSE chunks and model-specific response formats. |
package.json |
Removed a trailing newline for minor formatting adjustment. |
app/components/emoji.tsx |
Added new bot icon import and extended icon mapping to include Bedrock-related models with the nova substring. |
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
Suggested labels
planned, enhancement
Suggested reviewers
- lloydzhou
Poem
I'm a bunny with a code-filled beat,
Hop-ping through changes oh-so-sweet.
AWS Bedrock now leads the way,
With keys and flows in bright display.
I nibble bugs and fix with cheer,
Celebrating enhancements far and near!
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>, please review it. -
Explain this complex logic. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai explain this code block. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -
@coderabbitai read src/utils.ts and explain its main purpose. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -
@coderabbitai help me debug CodeRabbit configuration file.
-
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
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)
-
@coderabbitai pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.