KEMBAR78
Fix AnthropicBedrockChatCompletionClient import error by victordibia · Pull Request #6489 · microsoft/autogen · GitHub
Skip to content

Conversation

@victordibia
Copy link
Collaborator

@victordibia victordibia commented May 8, 2025

Some fixes with the AnthropicBedrockChatCompletionClient

  • Ensure AnthropicBedrockChatCompletionClient exported and can be imported.
  • Update the BedrockInfo keys serialization - client argument can be string (similar to api key in this ) but exported config should be Secret
  • Replace AnthropicBedrock with AsyncAnthropicBedrock : client should be async to work with the ag stack and the BaseAnthropicClient it inherits from
  • Improve AnthropicBedrockChatCompletionClient docstring to use the correct client arguments rather than serialized dict format.

Expect

from autogen_ext.models.anthropic import AnthropicBedrockChatCompletionClient, BedrockInfo
from autogen_core.models import UserMessage, ModelInfo


async def main():
    anthropic_client = AnthropicBedrockChatCompletionClient(
        model="anthropic.claude-3-5-sonnet-20240620-v1:0",
        temperature=0.1,
        model_info=ModelInfo(vision=False, function_calling=True,
                             json_output=False, family="unknown", structured_output=True),
        bedrock_info=BedrockInfo(
            aws_access_key="<aws_access_key>",
            aws_secret_key="<aws_secret_key>",
            aws_session_token="<aws_session_token>",
            aws_region="<aws_region>",
        ),
    )
    # type: ignore
    result = await anthropic_client.create([UserMessage(content="What is the capital of France?", source="user")])
    print(result)

await main()

Why are these changes needed?

Related issue number

Closes #6483

Checks

@victordibia victordibia requested a review from ekzhu May 8, 2025 17:41
@codecov
Copy link

codecov bot commented May 8, 2025

Codecov Report

Attention: Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 78.75%. Comparing base (3db7a29) to head (9f51c47).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../autogen_ext/models/anthropic/_anthropic_client.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6489      +/-   ##
==========================================
+ Coverage   78.57%   78.75%   +0.17%     
==========================================
  Files         225      225              
  Lines       16573    16581       +8     
==========================================
+ Hits        13023    13058      +35     
+ Misses       3550     3523      -27     
Flag Coverage Δ
unittests 78.75% <95.00%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@victordibia victordibia marked this pull request as ready for review May 8, 2025 23:58
@victordibia victordibia changed the title [Draft] Fix AnthropicBedrockChatCompletionClient import error Fix AnthropicBedrockChatCompletionClient import error May 8, 2025
@victordibia victordibia merged commit 6427c07 into main May 10, 2025
63 checks passed
@victordibia victordibia deleted the fix_anthropic_bedrock branch May 10, 2025 16:12
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.

Not able to use AnthropicsBedrockClient, Not able to import

2 participants