NextChat icon indicating copy to clipboard operation
NextChat copied to clipboard

feat:Add Amazon Bedrock to support the leading large language models such as Amazon Nova, Claude, Llama, Mistral, and others.

Open glayyiyi opened this issue 1 year ago • 2 comments

💻 变更类型 | 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.

  1. 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)
  2. Localization:

    • Updated Chinese translations (app/locales/cn.ts)
    • Updated English translations (app/locales/en.ts)
  3. Configuration:

    • Modified constants and configurations (app/constant.ts)
  4. 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.
Screenshot 2024-11-06 at 10 55 04 Screenshot 2024-11-06 at 11 02 19 Screenshot 2024-11-26 at 11 34 19

glayyiyi avatar Feb 16 '25 01:02 glayyiyi

@glayyiyi is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Feb 16 '25 01:02 vercel[bot]

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.

❤️ Share
🪧 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 @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file 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.

coderabbitai[bot] avatar Feb 16 '25 01:02 coderabbitai[bot]