-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Add] Function calling support for Autobuild
- Loading branch information
1 parent
c6f6707
commit 900fdd6
Showing
3 changed files
with
179 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ | |
"api_type": "azure", | ||
"api_version": "2024-02-15-preview" | ||
} | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"ename": "ModuleNotFoundError", | ||
"evalue": "No module named 'autogen.agentchat.contrib.agent_builder'", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", | ||
"Cell \u001b[0;32mIn[1], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mautogen\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mautogen\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39magentchat\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mcontrib\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39magent_builder\u001b[39;00m \u001b[39mimport\u001b[39;00m AgentBuilder\n\u001b[1;32m 4\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mIPython\u001b[39;00m \u001b[39mimport\u001b[39;00m get_ipython\n\u001b[1;32m 5\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mtyping_extensions\u001b[39;00m \u001b[39mimport\u001b[39;00m Annotated\n", | ||
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'autogen.agentchat.contrib.agent_builder'" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import autogen\n", | ||
"from autogen.agentchat.contrib.agent_builder import AgentBuilder\n", | ||
"\n", | ||
"from IPython import get_ipython\n", | ||
"from typing_extensions import Annotated\n", | ||
"\n", | ||
"\n", | ||
"config_file_or_env = \"/workspaces/autogen/OAI_CONFIG_LIST.json\"\n", | ||
"\n", | ||
"\n", | ||
"def exec_python(cell: Annotated[str, \"Valid Python cell to execute.\"]) -> str:\n", | ||
" ipython = get_ipython()\n", | ||
" result = ipython.run_cell(cell)\n", | ||
" log = str(result.result)\n", | ||
" if result.error_before_exec is not None:\n", | ||
" log += f\"\\n{result.error_before_exec}\"\n", | ||
" if result.error_in_exec is not None:\n", | ||
" log += f\"\\n{result.error_in_exec}\"\n", | ||
" return log\n", | ||
"\n", | ||
"\n", | ||
"config_list = autogen.config_list_from_json(config_file_or_env, filter_dict={\"model\": [\"gpt-4-1106-preview\", \"gpt-4\"]})\n", | ||
"\n", | ||
"\n", | ||
"llm_config = {\n", | ||
" \"config_list\": config_list,\n", | ||
" \"timeout\": 120,\n", | ||
"}\n", | ||
"\n", | ||
"def start_task(execution_task: str, agent_list: list):\n", | ||
" group_chat = autogen.GroupChat(agents=agent_list, messages=[], max_round=12)\n", | ||
" manager = autogen.GroupChatManager(groupchat=group_chat, llm_config={\"config_list\": config_list})\n", | ||
" agent_list[0].initiate_chat(manager, message=execution_task)\n", | ||
"\n", | ||
"\n", | ||
"builder = AgentBuilder(\n", | ||
" config_file_or_env=config_file_or_env, builder_model=\"gpt-4-1106-preview\", agent_model=\"gpt-4-1106-preview\"\n", | ||
")\n", | ||
"\n", | ||
"building_task = \"Draw two agents chatting with each other with an example dialog using matplotlib. Don't add plt.show().\"\n", | ||
"\n", | ||
"list_of_functions = [\n", | ||
" {\"name\": \"exec_python\", \"description\": \"run cell in ipython and return the execution result.\", \"function\": exec_python}\n", | ||
"]\n", | ||
"\n", | ||
"agent_list, agent_configs = builder.build(building_task, llm_config, list_of_functions)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"start_task(\n", | ||
" execution_task=building_task,\n", | ||
" agent_list=agent_list\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"builder.clear_all_agents(recycle_endpoint=True)\n", | ||
"\n", | ||
"saved_path = builder.save()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.12" | ||
}, | ||
"orig_nbformat": 4, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "e7370f93d1d0cde622a1f8e1c04877d8463912d04d973331ad4851f04de6915a" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |