A programming framework for agentic AI
Add anthropic docs (#5882)
Victor Dibia134a8c71ef53
diff --git a/python/packages/autogen-core/docs/src/reference/index.md b/python/packages/autogen-core/docs/src/reference/index.mdindex 29850dc3d..e312c288d 100644--- a/python/packages/autogen-core/docs/src/reference/index.md+++ b/python/packages/autogen-core/docs/src/reference/index.md@@ -51,6 +51,7 @@ python/autogen_ext.models.cachepython/autogen_ext.models.openaipython/autogen_ext.models.replaypython/autogen_ext.models.azure+python/autogen_ext.models.anthropicpython/autogen_ext.models.semantic_kernelpython/autogen_ext.models.ollamapython/autogen_ext.tools.code_executiondiff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.anthropic.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.anthropic.rstnew file mode 100644index 000000000..51d882829--- /dev/null+++ b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.anthropic.rst@@ -0,0 +1,8 @@+autogen\_ext.models.anthropic+=============================+++.. automodule:: autogen_ext.models.anthropic+ :members:+ :undoc-members:+ :show-inheritance:diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/models.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/models.ipynbindex 5cde8edd6..9b359fe58 100644--- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/models.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/models.ipynb@@ -228,6 +228,47 @@"print(result)"]},+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## Anthropic (experimental)\n",+ "\n",+ "To use the {py:class}`~autogen_ext.models.anthropic.AnthropicChatCompletionClient`, you need to install the `anthropic` extra. Underneath, it uses the `anthropic` python sdk to access the models.\n",+ "You will also need to obtain an [API key](https://console.anthropic.com) from Anthropic."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "# !pip install -U \"autogen-ext[anthropic]\""+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 2,+ "metadata": {},+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "finish_reason='stop' content=\"The capital of France is Paris. It's not only the political and administrative capital but also a major global center for art, fashion, gastronomy, and culture. Paris is known for landmarks such as the Eiffel Tower, the Louvre Museum, Notre-Dame Cathedral, and the Champs-Élysées.\" usage=RequestUsage(prompt_tokens=14, completion_tokens=73) cached=False logprobs=None thought=None\n"+ ]+ }+ ],+ "source": [+ "from autogen_core.models import UserMessage\n",+ "from autogen_ext.models.anthropic import AnthropicChatCompletionClient\n",+ "\n",+ "anthropic_client = AnthropicChatCompletionClient(model=\"claude-3-7-sonnet-20250219\")\n",+ "result = await anthropic_client.create([UserMessage(content=\"What is the capital of France?\", source=\"user\")])\n",+ "print(result)"+ ]+ },{"cell_type": "markdown","metadata": {},@@ -434,7 +475,7 @@"name": "python","nbconvert_exporter": "python","pygments_lexer": "ipython3",- "version": "3.12.7"+ "version": "3.11.9"}},"nbformat": 4,diff --git a/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py b/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.pyindex ea21fa28e..7da8508c7 100644--- a/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py+++ b/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py@@ -910,16 +910,23 @@ class AnthropicChatCompletionClient(.. code-block:: python+ import asynciofrom autogen_ext.models.anthropic import AnthropicChatCompletionClientfrom autogen_core.models import UserMessage- anthropic_client = AnthropicChatCompletionClient(- model="claude-3-sonnet-20240229",- api_key="your-api-key", # Optional if ANTHROPIC_API_KEY is set in environment- )- result = await anthropic_client.create([UserMessage(content="What is the capital of France?", source="user")])- print(result)+ async def main():+ anthropic_client = AnthropicChatCompletionClient(+ model="claude-3-sonnet-20240229",+ api_key="your-api-key", # Optional if ANTHROPIC_API_KEY is set in environment+ )++ result = await anthropic_client.create([UserMessage(content="What is the capital of France?", source="user")]) # type: ignore+ print(result)+++ if __name__ == "__main__":+ asyncio.run(main())To load the client from a configuration:@@ -933,25 +940,6 @@ class AnthropicChatCompletionClient(}client = ChatCompletionClient.load_component(config)-- The client supports function calling with Claude models that have the capability:-- .. code-block:: python-- from autogen_core.tools import FunctionTool--- def get_weather(location: str) -> str:- '''Get the weather for a location'''- return f"The weather in {location} is sunny."--- tool = FunctionTool(get_weather)-- result = await anthropic_client.create(- [UserMessage(content="What's the weather in Paris?", source="user")],- tools=[tool],- )"""component_type = "model"