Skip to content
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

Draft
wants to merge 104 commits into
base: main
Choose a base branch
from

Conversation

glayyiyi
Copy link

@glayyiyi glayyiyi commented Feb 16, 2025

💻 变更类型 | Change Type

  • 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, enabling enhanced API routing, streaming responses, and client-side interactions.
    • Introduced new AWS configuration options (region, access key, secret key, encryption key) with dedicated settings fields.
    • Expanded localization support to include Bedrock-specific configuration in multiple languages.
    • Enhanced security with improved encryption and password masking features.
  • Bug Fixes & Style

    • Resolved minor UI styling and formatting issues.
  • Documentation

    • Updated documentation to describe the new 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 and others added 30 commits October 29, 2024 22:20
	修改:     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
Copy link

vercel bot commented Feb 16, 2025

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

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Feb 16, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

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.

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
Loading

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!


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?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 suggestion

Consider 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() and models() 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 variables AWS_REGION, AWS_ACCESS_KEY, and AWS_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:

-```
+```text

This 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

📥 Commits

Reviewing files that changed from the base of the PR and between 12863f5 and 0081630.

⛔ 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 the bedrockHandler. 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, and awsSecretKey in the systemApiKey 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 and nova-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 the transformBedrockStream 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)

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 the BEDROCK_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

📥 Commits

Reviewing files that changed from the base of the PR and between 0081630 and bee5e15.

📒 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, and ModelProvider 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:


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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between bee5e15 and 3575fa6.

📒 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 and nova-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.

@glayyiyi glayyiyi marked this pull request as draft March 1, 2025 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant