@@ -101,33 +101,45 @@ We look forward to your contributions!
101
101
First install the packages:
102
102
103
103
``` bash
104
- pip install ' autogen-agentchat==0.4.0.dev4 ' ' autogen-ext[docker ]==0.4.0.dev4 '
104
+ pip install ' autogen-agentchat==0.4.0.dev6 ' ' autogen-ext[openai ]==0.4.0.dev6 '
105
105
```
106
106
107
- The following code uses code execution, you need to have [ Docker installed] ( https://docs.docker.com/engine/install/ )
108
- and running on your machine.
107
+ The following code uses OpenAI's GPT-4o model and you need to provide your
108
+ API key to run.
109
+ To use Azure OpenAI models, follow the instruction
110
+ [ here] ( https://microsoft.github.io/autogen/dev/user-guide/core-user-guide/cookbook/azure-openai-with-aad-auth.html ) .
109
111
110
112
``` python
111
113
import asyncio
112
- from autogen_ext.code_executor.docker_executor import DockerCommandLineCodeExecutor
113
- from autogen_ext.models import OpenAIChatCompletionClient
114
- from autogen_agentchat.agents import CodeExecutorAgent, CodingAssistantAgent
114
+ from autogen_agentchat.agents import AssistantAgent
115
+ from autogen_agentchat.task import Console, TextMentionTermination
115
116
from autogen_agentchat.teams import RoundRobinGroupChat
116
- from autogen_agentchat.task import TextMentionTermination
117
+ from autogen_ext.models import OpenAIChatCompletionClient
118
+
119
+ # Define a tool
120
+ async def get_weather (city : str ) -> str :
121
+ return f " The weather in { city} is 73 degrees and Sunny. "
117
122
118
123
async def main () -> None :
119
- async with DockerCommandLineCodeExecutor(work_dir = " coding" ) as code_executor:
120
- code_executor_agent = CodeExecutorAgent(" code_executor" , code_executor = code_executor)
121
- coding_assistant_agent = CodingAssistantAgent(
122
- " coding_assistant" , model_client = OpenAIChatCompletionClient(model = " gpt-4o" , api_key = " YOUR_API_KEY" )
123
- )
124
- termination = TextMentionTermination(" TERMINATE" )
125
- group_chat = RoundRobinGroupChat([coding_assistant_agent, code_executor_agent], termination_condition = termination)
126
- stream = group_chat.run_stream(
127
- task = " Create a plot of NVDIA and TSLA stock returns YTD from 2024-01-01 and save it to 'nvidia_tesla_2024_ytd.png'."
128
- )
129
- async for message in stream:
130
- print (message)
124
+ # Define an agent
125
+ weather_agent = AssistantAgent(
126
+ name = " weather_agent" ,
127
+ model_client = OpenAIChatCompletionClient(
128
+ model = " gpt-4o-2024-08-06" ,
129
+ # api_key="YOUR_API_KEY",
130
+ ),
131
+ tools = [get_weather],
132
+ )
133
+
134
+ # Define termination condition
135
+ termination = TextMentionTermination(" TERMINATE" )
136
+
137
+ # Define a team
138
+ agent_team = RoundRobinGroupChat([weather_agent], termination_condition = termination)
139
+
140
+ # Run the team and stream messages to the console
141
+ stream = agent_team.run_stream(task = " What is the weather in New York?" )
142
+ await Console(stream)
131
143
132
144
asyncio.run(main())
133
145
```
0 commit comments