Skip to content

support anthropic_beta as a top level parameter for anthropic on bedr… #1079

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

Merged
merged 2 commits into from
May 6, 2025

Conversation

narengogi
Copy link
Collaborator

support anthropic_beta as a top level parameter for anthropic on bedrock, support both string and array of strings to be compatible with anthropic signature

…ock, support both string and array of strings to be compatible with anthropic signature
Copy link

Code Quality new feature

Summary By MatterAI MatterAI logo

🔄 What Changed

Added support for the anthropic_beta parameter as a top-level parameter for Anthropic models on Bedrock. The implementation supports both string and array of strings formats to maintain compatibility with Anthropic's signature.

🔍 Impact of the Change

This change enhances the flexibility of the Bedrock Anthropic integration by allowing users to pass the anthropic_beta parameter in either string or array format. The code now properly transforms this parameter into the expected format for the Bedrock API.

📁 Total Files Changed

2 files changed with 14 additions and 2 deletions:

  • src/providers/bedrock/chatComplete.ts: Modified interface and parameter handling
  • src/providers/bedrock/utils.ts: Added transformation logic for the anthropic_beta parameter

🧪 Test Added

N/A - No tests were included in this PR

🔒Security Vulnerabilities

N/A - No security vulnerabilities identified

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Testing

Screenshots (if applicable)

N/A

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Related Issues

N/A

Sequence Diagram

sequenceDiagram
    participant Client
    participant Gateway
    participant BedrockConverseAnthropicChatCompleteConfig
    participant transformAnthropicAdditionalModelRequestFields
    participant Bedrock API

    Client->>Gateway: Request with anthropic_beta parameter
    Note over Client,Gateway: anthropic_beta can be string or string[]
    
    Gateway->>BedrockConverseAnthropicChatCompleteConfig: Process request parameters
    BedrockConverseAnthropicChatCompleteConfig->>transformAnthropicAdditionalModelRequestFields: Transform anthropic_beta
    
    Note over transformAnthropicAdditionalModelRequestFields: Check if anthropic_beta exists
    Note over transformAnthropicAdditionalModelRequestFields: If string, convert to [string]
    Note over transformAnthropicAdditionalModelRequestFields: If array, use as is
    
    transformAnthropicAdditionalModelRequestFields-->>BedrockConverseAnthropicChatCompleteConfig: Return additionalModelRequestFields
    BedrockConverseAnthropicChatCompleteConfig-->>Gateway: Return transformed parameters
    Gateway->>Bedrock API: Send request with properly formatted anthropic_beta
    Bedrock API-->>Client: Response
Loading

@narengogi
Copy link
Collaborator Author

this PR relates to the changes in #1070

Copy link

Code Quality new feature

Summary By MatterAI MatterAI logo

🔄 What Changed

Added support for the anthropic_beta parameter as a top-level parameter for Anthropic models on Bedrock. The implementation supports both string and array of strings to maintain compatibility with the Anthropic API signature.

🔍 Impact of the Change

This change enables users to pass the anthropic_beta parameter directly when using Anthropic models through Bedrock, improving feature parity with the native Anthropic API.

📁 Total Files Changed

2 files changed with 11 additions and 1 deletion:

  • src/providers/bedrock/chatComplete.ts: Modified interface definition to support the new parameter
  • src/providers/bedrock/utils.ts: Added logic to handle the parameter transformation

🧪 Test Added

N/A - No tests were included in this PR

🔒Security Vulnerabilities

N/A - No security vulnerabilities identified

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Testing

Screenshots (if applicable)

N/A

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Related Issues

N/A

Sequence Diagram

sequenceDiagram
    participant Client
    participant BedrockChatCompletions
    participant transformAnthropicAdditionalModelRequestFields
    participant AnthropicAPI
    
    Client->>BedrockChatCompletions: Request with anthropic_beta parameter
    Note over Client,BedrockChatCompletions: anthropic_beta can be string or string[]
    
    BedrockChatCompletions->>transformAnthropicAdditionalModelRequestFields: Pass params including anthropic_beta
    
    alt anthropic_beta is string
        transformAnthropicAdditionalModelRequestFields->>transformAnthropicAdditionalModelRequestFields: Convert string to [string]
    else anthropic_beta is array
        transformAnthropicAdditionalModelRequestFields->>transformAnthropicAdditionalModelRequestFields: Use array as is
    end
    
    transformAnthropicAdditionalModelRequestFields->>BedrockChatCompletions: Return additionalModelRequestFields
    BedrockChatCompletions->>AnthropicAPI: Send request with anthropic_beta
    AnthropicAPI->>BedrockChatCompletions: Response
    BedrockChatCompletions->>Client: Return response
Loading

@VisargD VisargD merged commit 269c0f0 into Portkey-AI:main May 6, 2025
1 check passed
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.

2 participants