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

[OAI]: Fix Anthropic Bedrock Client Bug #3200

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions autogen/oai/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,30 @@


class AnthropicClient:
def __init__(self, **kwargs: Any):
def __init__(
self,
api_key: str | None = None,
aws_access_key: str | None = None,
aws_secret_key: str | None = None,
aws_session_token: str | None = None,
aws_region: str | None = None,
**kwargs: Any,
):
"""
Initialize the Anthropic API client.
Args:
api_key (str): The API key for the Anthropic API or set the `ANTHROPIC_API_KEY` environment variable.
aws_access_key (str, optional): AWS Access Key. If not provided, it will try to get it from the `AWS_ACCESS_KEY` environment variable.
aws_secret_key (str, optional): AWS Secret Key. If not provided, it will try to get it from the `AWS_SECRET_KEY` environment variable.
aws_session_token (str, optional): AWS Session Token. If not provided, it will try to get it from the `AWS_SESSION_TOKEN` environment variable.
aws_region (str, optional): AWS Region. If not provided, it will try to get it from the `AWS_REGION` environment variable.
**kwargs: Other parameters.
"""
self._api_key = kwargs.get("api_key", None)
self._aws_access_key = kwargs.get("aws_access_key", None)
self._aws_secret_key = kwargs.get("aws_secret_key", None)
self._aws_session_token = kwargs.get("aws_session_token", None)
self._aws_region = kwargs.get("aws_region", None)
self._api_key = api_key
self._aws_access_key = aws_access_key
self._aws_secret_key = aws_secret_key
self._aws_session_token = aws_session_token
self._aws_region = aws_region

if not self._api_key:
self._api_key = os.getenv("ANTHROPIC_API_KEY")
Expand All @@ -106,10 +119,7 @@ def __init__(self, **kwargs: Any):
self._aws_region = os.getenv("AWS_REGION")

if self._api_key is None and (
self._aws_access_key is None
or self._aws_secret_key is None
or self._aws_session_token is None
or self._aws_region is None
self._aws_access_key is None or self._aws_secret_key is None or self._aws_region is None
):
raise ValueError("API key or AWS credentials are required to use the Anthropic API.")

Expand Down
3 changes: 2 additions & 1 deletion autogen/oai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ class OpenAIWrapper:

openai_kwargs = set(inspect.getfullargspec(OpenAI.__init__).kwonlyargs)
aopenai_kwargs = set(inspect.getfullargspec(AzureOpenAI.__init__).kwonlyargs)
openai_kwargs = openai_kwargs | aopenai_kwargs
anthropic_kwargs = set(inspect.getfullargspec(AnthropicClient.__init__).args)
openai_kwargs = openai_kwargs | aopenai_kwargs | anthropic_kwargs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is not intuitive: should openai_kwargs contain anthropic_kwargs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe #3210 fixes this issue.

total_usage_summary: Optional[Dict[str, Any]] = None
actual_usage_summary: Optional[Dict[str, Any]] = None

Expand Down