diff --git a/autogen/oai/anthropic.py b/autogen/oai/anthropic.py index 62078d42631d..9936b44cf4e4 100644 --- a/autogen/oai/anthropic.py +++ b/autogen/oai/anthropic.py @@ -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") @@ -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.") diff --git a/autogen/oai/client.py b/autogen/oai/client.py index 4e9d794a1f75..e8c6bfe416fd 100644 --- a/autogen/oai/client.py +++ b/autogen/oai/client.py @@ -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 total_usage_summary: Optional[Dict[str, Any]] = None actual_usage_summary: Optional[Dict[str, Any]] = None