Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
victordibia committed Oct 20, 2024
1 parent 096bb22 commit d1d70ae
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"import logging\n",
"from autogen_agentchat import EVENT_LOGGER_NAME\n",
"from autogen_agentchat.logging import ConsoleLogHandler\n",
"from autogen_agentchat.agents import CodingAssistantAgent\n",
"from autogen_agentchat.agents import CodingAssistantAgent\n",
"from autogen_agentchat.teams import RoundRobinGroupChat, MaxMessageTermination\n",
"from autogen_core.components.models import OpenAIChatCompletionClient\n",
"\n",
Expand All @@ -42,17 +41,17 @@
"# define an agent\n",
"writing_agent = CodingAssistantAgent(\n",
" name=\"writing_agent\",\n",
" system_message=\"You are a helpful assistant that can respond to questions\" ,\n",
" model_client=OpenAIChatCompletionClient(model=\"gpt-4o-2024-08-06\")\n",
" system_message=\"You are a helpful assistant that can respond to questions\",\n",
" model_client=OpenAIChatCompletionClient(model=\"gpt-4o-2024-08-06\"),\n",
")\n",
"\n",
"# add the agent to a team\n",
"agent_team = RoundRobinGroupChat([writing_agent]) \n",
"agent_team = RoundRobinGroupChat([writing_agent])\n",
"result = await agent_team.run(\n",
" task=\"Write a 5 line haiku on international space station\",\n",
" termination_condition=MaxMessageTermination(max_messages=1)\n",
" )\n",
"print(\"\\n\",result)"
" task=\"Write a 5 line haiku on international space station\",\n",
" termination_condition=MaxMessageTermination(max_messages=1),\n",
")\n",
"print(\"\\n\", result)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"import logging\n",
"from autogen_agentchat import EVENT_LOGGER_NAME\n",
"from autogen_agentchat.logging import ConsoleLogHandler\n",
"from autogen_agentchat.agents import CodingAssistantAgent, ToolUseAssistantAgent, TextMessage\n",
"from autogen_agentchat.agents import CodingAssistantAgent, ToolUseAssistantAgent, TextMessage\n",
"from autogen_agentchat.teams import RoundRobinGroupChat, SelectorGroupChat, MaxMessageTermination\n",
"from autogen_core.components.models import OpenAIChatCompletionClient\n",
"from autogen_core.components.tools import FunctionTool\n",
Expand All @@ -61,7 +60,7 @@
"\n",
"writing_assistant_agent = CodingAssistantAgent(\n",
" name=\"writing_assistant_agent\",\n",
" system_message=\"You are a helpful assistant that solve tasks by generating text responses and code.\" ,\n",
" system_message=\"You are a helpful assistant that solve tasks by generating text responses and code.\",\n",
" model_client=model_client,\n",
")"
]
Expand All @@ -80,9 +79,12 @@
}
],
"source": [
"result = await writing_assistant_agent.on_messages(messages=[\n",
" TextMessage(content=\"What is the weather right now in France?\", source=\"user\"),\n",
"], cancellation_token=None)\n",
"result = await writing_assistant_agent.on_messages(\n",
" messages=[\n",
" TextMessage(content=\"What is the weather right now in France?\", source=\"user\"),\n",
" ],\n",
" cancellation_token=None,\n",
")\n",
"print(result)"
]
},
Expand Down Expand Up @@ -122,6 +124,8 @@
"source": [
"async def get_weather(city: str) -> str:\n",
" return f\"The weather in {city} is 72 degrees and Sunny.\"\n",
"\n",
"\n",
"get_weather_tool = FunctionTool(get_weather, description=\"Get the weather for a city\")\n",
"\n",
"tool_use_agent = ToolUseAssistantAgent(\n",
Expand All @@ -146,9 +150,12 @@
}
],
"source": [
"tool_result = await tool_use_agent.on_messages(messages=[\n",
" TextMessage(content=\"What is the weather right now in France?\", source=\"user\"),\n",
"], cancellation_token=None)\n",
"tool_result = await tool_use_agent.on_messages(\n",
" messages=[\n",
" TextMessage(content=\"What is the weather right now in France?\", source=\"user\"),\n",
" ],\n",
" cancellation_token=None,\n",
")\n",
"print(tool_result)"
]
},
Expand Down Expand Up @@ -197,12 +204,13 @@
"\n",
"# type: ignore[syntax]\n",
"async with DockerCommandLineCodeExecutor(work_dir=\"coding\") as code_executor:\n",
" code_executor_agent = CodeExecutorAgent(\n",
" \"code_executor\", code_executor=code_executor)\n",
" code_execution_result = await code_executor_agent.on_messages(messages=[\n",
" TextMessage(content=\"Here is some code \\n ```python print('Hello world') \\n``` \",\n",
" source=\"user\"),\n",
" ], cancellation_token=None)\n",
" code_executor_agent = CodeExecutorAgent(\"code_executor\", code_executor=code_executor)\n",
" code_execution_result = await code_executor_agent.on_messages(\n",
" messages=[\n",
" TextMessage(content=\"Here is some code \\n ```python print('Hello world') \\n``` \", source=\"user\"),\n",
" ],\n",
" cancellation_token=None,\n",
" )\n",
" print(code_execution_result)"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
" model=\"gpt-4o-2024-08-06\",\n",
" # api_key=\"sk-...\", # Optional if you have an OPENAI_API_KEY env variable set.\n",
")\n",
"model_client_result = await model_client.create(messages=[\n",
" UserMessage(content=\"What is the capital of France?\", source=\"user\"),\n",
"])\n",
"model_client_result = await model_client.create(\n",
" messages=[\n",
" UserMessage(content=\"What is the capital of France?\", source=\"user\"),\n",
" ]\n",
")\n",
"print(model_client_result) # \"Paris\""
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"import logging\n",
"from autogen_agentchat import EVENT_LOGGER_NAME\n",
"from autogen_agentchat.logging import ConsoleLogHandler\n",
"from autogen_agentchat.agents import CodingAssistantAgent, ToolUseAssistantAgent\n",
"from autogen_agentchat.agents import CodingAssistantAgent, ToolUseAssistantAgent\n",
"from autogen_agentchat.teams import RoundRobinGroupChat, SelectorGroupChat, MaxMessageTermination\n",
"from autogen_core.components.models import OpenAIChatCompletionClient\n",
"from autogen_core.components.tools import FunctionTool\n",
Expand All @@ -43,12 +42,15 @@
"\n",
"writing_assistant_agent = CodingAssistantAgent(\n",
" name=\"writing_assistant_agent\",\n",
" system_message=\"You are a helpful assistant that solve tasks by generating text responses and code.\" ,\n",
" system_message=\"You are a helpful assistant that solve tasks by generating text responses and code.\",\n",
" model_client=model_client,\n",
")\n",
"\n",
"\n",
"async def get_weather(city: str) -> str:\n",
" return f\"The weather in {city} is 72 degrees and Sunny.\"\n",
"\n",
"\n",
"get_weather_tool = FunctionTool(get_weather, description=\"Get the weather for a city\")\n",
"\n",
"tool_use_agent = ToolUseAssistantAgent(\n",
Expand All @@ -74,9 +76,10 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"round_robin_team = RoundRobinGroupChat([tool_use_agent, writing_assistant_agent])\n",
"round_robin_team_result = await round_robin_team.run(\"Write a Haiku about the weather in Paris\", termination_condition=MaxMessageTermination(max_messages=2))"
"round_robin_team_result = await round_robin_team.run(\n",
" \"Write a Haiku about the weather in Paris\", termination_condition=MaxMessageTermination(max_messages=2)\n",
")"
]
},
{
Expand Down Expand Up @@ -111,7 +114,9 @@
"source": [
"llm_team = SelectorGroupChat([tool_use_agent, writing_assistant_agent], model_client=model_client)\n",
"\n",
"llm_team_result = await llm_team.run(\"What is the weather in paris right now? Also, \", termination_condition=MaxMessageTermination(max_messages=2))"
"llm_team_result = await llm_team.run(\n",
" \"What is the weather in paris right now? Also, \", termination_condition=MaxMessageTermination(max_messages=2)\n",
")"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"import logging\n",
"from autogen_agentchat import EVENT_LOGGER_NAME\n",
"from autogen_agentchat.logging import ConsoleLogHandler\n",
"from autogen_agentchat.agents import CodingAssistantAgent\n",
"from autogen_agentchat.agents import CodingAssistantAgent\n",
"from autogen_agentchat.teams import RoundRobinGroupChat, MaxMessageTermination, StopMessageTermination\n",
"from autogen_core.components.models import OpenAIChatCompletionClient\n",
"\n",
Expand All @@ -55,7 +54,7 @@
"\n",
"writing_assistant_agent = CodingAssistantAgent(\n",
" name=\"writing_assistant_agent\",\n",
" system_message=\"You are a helpful assistant that solve tasks by generating text responses and code.\" ,\n",
" system_message=\"You are a helpful assistant that solve tasks by generating text responses and code.\",\n",
" model_client=model_client,\n",
")\n",
"\n",
Expand Down Expand Up @@ -120,7 +119,9 @@
"source": [
"round_robin_team = RoundRobinGroupChat([writing_assistant_agent])\n",
"\n",
"round_robin_team_result = await round_robin_team.run(\"Write a unique, Haiku about the weather in Paris\", termination_condition=MaxMessageTermination(max_messages=3))"
"round_robin_team_result = await round_robin_team.run(\n",
" \"Write a unique, Haiku about the weather in Paris\", termination_condition=MaxMessageTermination(max_messages=3)\n",
")"
]
},
{
Expand Down Expand Up @@ -177,14 +178,16 @@
"source": [
"writing_assistant_agent = CodingAssistantAgent(\n",
" name=\"writing_assistant_agent\",\n",
" system_message=\"You are a helpful assistant that solve tasks by generating text responses and code. Respond with TERMINATE when the task is done.\" ,\n",
" system_message=\"You are a helpful assistant that solve tasks by generating text responses and code. Respond with TERMINATE when the task is done.\",\n",
" model_client=model_client,\n",
")\n",
"\n",
"\n",
"round_robin_team = RoundRobinGroupChat([writing_assistant_agent])\n",
"\n",
"round_robin_team_result = await round_robin_team.run(\"Write a unique, Haiku about the weather in Paris\", termination_condition=StopMessageTermination())"
"round_robin_team_result = await round_robin_team.run(\n",
" \"Write a unique, Haiku about the weather in Paris\", termination_condition=StopMessageTermination()\n",
")"
]
}
],
Expand Down

0 comments on commit d1d70ae

Please sign in to comment.