diff --git a/python/samples/getting_started/agents/azure/azure_chat_client_agent.py b/python/samples/getting_started/agents/azure/azure_chat_client_agent.py new file mode 100644 index 0000000000..b35689beb7 --- /dev/null +++ b/python/samples/getting_started/agents/azure/azure_chat_client_agent.py @@ -0,0 +1,27 @@ +# Copyright (c) Microsoft. All rights reserved. + +import asyncio +from random import randint +from typing import Annotated + +from agent_framework import ChatClientAgent +from agent_framework.azure import AzureChatClient +from pydantic import Field + + +def get_weather( + location: Annotated[str, Field(description="The location to get the weather for.")], +) -> str: + """Get the weather for a given location.""" + conditions = ["sunny", "cloudy", "rainy", "stormy"] + return f"The weather in {location} is {conditions[randint(0, 3)]} with a high of {randint(10, 30)}°C." + + +async def main() -> None: + instructions = "You are a helpful assistant, you can help the user with weather information." + agent = ChatClientAgent(AzureChatClient(), instructions=instructions, tools=get_weather) + print(str(await agent.run("What's the weather in Amsterdam?"))) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/python/samples/getting_started/agents/foundry/foundry_basic.py b/python/samples/getting_started/agents/foundry/foundry_basic.py index 7a40bd0fa0..ed698b2a5e 100644 --- a/python/samples/getting_started/agents/foundry/foundry_basic.py +++ b/python/samples/getting_started/agents/foundry/foundry_basic.py @@ -6,7 +6,6 @@ from typing import Annotated from agent_framework import ChatClientAgent from agent_framework.foundry import FoundryChatClient -from dotenv import load_dotenv from pydantic import Field @@ -33,5 +32,4 @@ async def main() -> None: if __name__ == "__main__": - load_dotenv() asyncio.run(main()) diff --git a/python/samples/getting_started/agents/foundry/foundry_with_existing_agent.py b/python/samples/getting_started/agents/foundry/foundry_with_existing_agent.py index 16d3c1ee34..bda2fde90a 100644 --- a/python/samples/getting_started/agents/foundry/foundry_with_existing_agent.py +++ b/python/samples/getting_started/agents/foundry/foundry_with_existing_agent.py @@ -9,7 +9,6 @@ from agent_framework import ChatClientAgent from agent_framework.foundry import FoundryChatClient from azure.ai.projects.aio import AIProjectClient from azure.identity.aio import AzureCliCredential -from dotenv import load_dotenv from pydantic import Field @@ -46,5 +45,4 @@ async def main() -> None: if __name__ == "__main__": - load_dotenv() asyncio.run(main()) diff --git a/python/samples/getting_started/agents/foundry/foundry_with_existing_client.py b/python/samples/getting_started/agents/foundry/foundry_with_existing_client.py index 8191f1cd17..6870a9606b 100644 --- a/python/samples/getting_started/agents/foundry/foundry_with_existing_client.py +++ b/python/samples/getting_started/agents/foundry/foundry_with_existing_client.py @@ -9,7 +9,6 @@ from agent_framework import ChatClientAgent from agent_framework.foundry import FoundryChatClient from azure.ai.projects.aio import AIProjectClient from azure.identity.aio import AzureCliCredential -from dotenv import load_dotenv from pydantic import Field @@ -43,5 +42,4 @@ async def main() -> None: if __name__ == "__main__": - load_dotenv() asyncio.run(main()) diff --git a/python/samples/getting_started/agents/foundry/foundry_with_explicit_settings.py b/python/samples/getting_started/agents/foundry/foundry_with_explicit_settings.py index 0a9e69e159..a9d451e701 100644 --- a/python/samples/getting_started/agents/foundry/foundry_with_explicit_settings.py +++ b/python/samples/getting_started/agents/foundry/foundry_with_explicit_settings.py @@ -8,7 +8,6 @@ from typing import Annotated from agent_framework import ChatClientAgent from agent_framework.foundry import FoundryChatClient from azure.identity.aio import AzureCliCredential -from dotenv import load_dotenv from pydantic import Field @@ -40,5 +39,4 @@ async def main() -> None: if __name__ == "__main__": - load_dotenv() asyncio.run(main()) diff --git a/python/samples/getting_started/agents/chat_client_agent.py b/python/samples/getting_started/agents/openai/openai_chat_client_agent.py similarity index 94% rename from python/samples/getting_started/agents/chat_client_agent.py rename to python/samples/getting_started/agents/openai/openai_chat_client_agent.py index 7cd456cc17..d5c7512d7c 100644 --- a/python/samples/getting_started/agents/chat_client_agent.py +++ b/python/samples/getting_started/agents/openai/openai_chat_client_agent.py @@ -6,7 +6,6 @@ from typing import Annotated from agent_framework import ChatClientAgent from agent_framework.openai import OpenAIChatClient -from dotenv import load_dotenv from pydantic import Field @@ -25,5 +24,4 @@ async def main() -> None: if __name__ == "__main__": - load_dotenv() asyncio.run(main()) diff --git a/python/samples/getting_started/chat_client/azure_chat_client.py b/python/samples/getting_started/chat_client/azure_chat_client.py new file mode 100644 index 0000000000..dc7ea4069c --- /dev/null +++ b/python/samples/getting_started/chat_client/azure_chat_client.py @@ -0,0 +1,36 @@ +# Copyright (c) Microsoft. All rights reserved. + +import asyncio +from random import randint +from typing import Annotated + +from agent_framework.azure import AzureChatClient +from pydantic import Field + + +def get_weather( + location: Annotated[str, Field(description="The location to get the weather for.")], +) -> str: + """Get the weather for a given location.""" + conditions = ["sunny", "cloudy", "rainy", "stormy"] + return f"The weather in {location} is {conditions[randint(0, 3)]} with a high of {randint(10, 30)}°C." + + +async def main() -> None: + client = AzureChatClient() + message = "What's the weather in Amsterdam and in Paris?" + stream = False + print(f"User: {message}") + if stream: + print("Assistant: ", end="") + async for chunk in client.get_streaming_response(message, tools=get_weather): + if str(chunk): + print(str(chunk), end="") + print("") + else: + response = await client.get_response(message, tools=get_weather) + print(f"Assistant: {response}") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/python/samples/getting_started/chat_client/foundry_chat_client.py b/python/samples/getting_started/chat_client/foundry_chat_client.py new file mode 100644 index 0000000000..3cfb157bce --- /dev/null +++ b/python/samples/getting_started/chat_client/foundry_chat_client.py @@ -0,0 +1,36 @@ +# Copyright (c) Microsoft. All rights reserved. + +import asyncio +from random import randint +from typing import Annotated + +from agent_framework.foundry import FoundryChatClient +from pydantic import Field + + +def get_weather( + location: Annotated[str, Field(description="The location to get the weather for.")], +) -> str: + """Get the weather for a given location.""" + conditions = ["sunny", "cloudy", "rainy", "stormy"] + return f"The weather in {location} is {conditions[randint(0, 3)]} with a high of {randint(10, 30)}°C." + + +async def main() -> None: + client = FoundryChatClient() + message = "What's the weather in Amsterdam and in Paris?" + stream = False + print(f"User: {message}") + if stream: + print("Assistant: ", end="") + async for chunk in client.get_streaming_response(message, tools=get_weather): + if str(chunk): + print(str(chunk), end="") + print("") + else: + response = await client.get_response(message, tools=get_weather) + print(f"Assistant: {response}") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/python/samples/getting_started/chat_client/openai_chat_client.py b/python/samples/getting_started/chat_client/openai_chat_client.py index e89715d99d..183a1f61d4 100644 --- a/python/samples/getting_started/chat_client/openai_chat_client.py +++ b/python/samples/getting_started/chat_client/openai_chat_client.py @@ -4,12 +4,10 @@ import asyncio from random import randint from typing import Annotated -from agent_framework import ai_function from agent_framework.openai import OpenAIChatClient from pydantic import Field -@ai_function def get_weather( location: Annotated[str, Field(description="The location to get the weather for.")], ) -> str: @@ -18,7 +16,7 @@ def get_weather( return f"The weather in {location} is {conditions[randint(0, 3)]} with a high of {randint(10, 30)}°C." -async def main(): +async def main() -> None: client = OpenAIChatClient() message = "What's the weather in Amsterdam and in Paris?" stream = False