-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from rjambrecic/add-tool-imports-upstream
Add tool imports upstream
- Loading branch information
Showing
2 changed files
with
156 additions
and
4 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
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,151 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# ! pip install 'crewai[tools]'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"2024-12-12 17:28:45,612 - 8269089792 - __init__.py-__init__:18 - WARNING: flaml.automl is not available. Please install flaml[automl] to enable AutoML functionalities.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import os\n", | ||
"import tempfile\n", | ||
"from pathlib import Path\n", | ||
"\n", | ||
"from crewai_tools import FileWriterTool\n", | ||
"\n", | ||
"from autogen import AssistantAgent, UserProxyAgent\n", | ||
"from autogen.tools import Tool" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"config_list = [{\"model\": \"gpt-4\", \"api_key\": os.environ[\"OPENAI_API_KEY\"]}]\n", | ||
"user_proxy = UserProxyAgent(\n", | ||
" name=\"User\",\n", | ||
" human_input_mode=\"NEVER\",\n", | ||
")\n", | ||
"\n", | ||
"chatbot = AssistantAgent(\n", | ||
" name=\"chatbot\",\n", | ||
" llm_config={\"config_list\": config_list},\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\u001b[33mUser\u001b[0m (to chatbot):\n", | ||
"\n", | ||
"Write 'Easy Migration :)' into tool_result.txt.\n", | ||
"Use /var/folders/79/kmq3y0pj0rbgrrnf4xlq8q0c0000gn/T/tmpv3px4peq dir.\n", | ||
"\n", | ||
"\n", | ||
"--------------------------------------------------------------------------------\n", | ||
"\u001b[33mchatbot\u001b[0m (to User):\n", | ||
"\n", | ||
"\u001b[32m***** Suggested tool call (call_or8EnSzoRxayagU27crpydfF): File_Writer_Tool *****\u001b[0m\n", | ||
"Arguments: \n", | ||
"{\n", | ||
" \"args\": {\n", | ||
" \"filename\": \"tool_result.txt\",\n", | ||
" \"directory\": \"/var/folders/79/kmq3y0pj0rbgrrnf4xlq8q0c0000gn/T/tmpv3px4peq\",\n", | ||
" \"overwrite\": \"yes\",\n", | ||
" \"content\": \"Easy Migration :)\"\n", | ||
" }\n", | ||
"}\n", | ||
"\u001b[32m*********************************************************************************\u001b[0m\n", | ||
"\n", | ||
"--------------------------------------------------------------------------------\n", | ||
"\u001b[35m\n", | ||
">>>>>>>> EXECUTING FUNCTION File_Writer_Tool...\u001b[0m\n", | ||
"Using Tool: File Writer Tool\n", | ||
"\u001b[33mUser\u001b[0m (to chatbot):\n", | ||
"\n", | ||
"\u001b[32m***** Response from calling tool (call_or8EnSzoRxayagU27crpydfF) *****\u001b[0m\n", | ||
"Content successfully written to /var/folders/79/kmq3y0pj0rbgrrnf4xlq8q0c0000gn/T/tmpv3px4peq/tool_result.txt\n", | ||
"\u001b[32m**********************************************************************\u001b[0m\n", | ||
"\n", | ||
"--------------------------------------------------------------------------------\n", | ||
"\u001b[33mchatbot\u001b[0m (to User):\n", | ||
"\n", | ||
"The content 'Easy Migration :)' has been successfully written to the file /var/folders/79/kmq3y0pj0rbgrrnf4xlq8q0c0000gn/T/tmpv3px4peq/tool_result.txt.\n", | ||
"\n", | ||
"TERMINATE\n", | ||
"\n", | ||
"--------------------------------------------------------------------------------\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"with tempfile.TemporaryDirectory() as tmpdirname:\n", | ||
" crewai_tool = FileWriterTool()\n", | ||
" ag2_tool = Tool.from_crewai_tool(crewai_tool)\n", | ||
"\n", | ||
" ag2_tool.register_for_execution(user_proxy)\n", | ||
" ag2_tool.register_for_llm(chatbot)\n", | ||
"\n", | ||
" filename = \"tool_result.txt\"\n", | ||
" message = f\"\"\"Write 'Easy Migration :)' into {filename}.\n", | ||
"Use {tmpdirname} dir.\n", | ||
"\"\"\"\n", | ||
" user_proxy.initiate_chat(recipient=chatbot, message=message, max_turns=2)\n", | ||
"\n", | ||
" assert Path(tmpdirname, filename).read_text() == \"Easy Migration :)\"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"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.16" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |