Name | opentool-ai JSON |
Version |
0.1.8
JSON |
| download |
home_page | |
Summary | A protocol for AI agent tools |
upload_time | 2024-03-01 18:39:37 |
maintainer | |
docs_url | None |
author | Patrick Barker |
requires_python | >=3.10,<4.0 |
license | Apache 2.0 |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<!-- PROJECT LOGO -->
<br />
<p align="center">
<!-- <a href="https://github.com/agentsea/skillpacks">
<img src="https://project-logo.png" alt="Logo" width="80">
</a> -->
<h1 align="center">OpenTool</h1>
<p align="center">
A common protocol for AI agent tools
<br />
<a href="https://github.com/agentsea/opentool"><strong>Explore the docs »</strong></a>
<br />
<br />
<a href="https://github.com/agentsea/opentool">View Demo</a>
·
<a href="https://github.com/agentsea/opentool/issues">Report Bug</a>
·
<a href="https://github.com/agentsea/opentool/issues">Request Feature</a>
</p>
<br>
</p>
OpenTool provides a common potocol for AI agent tools, use them with your favorite agent framework or model.
## Installation
```
pip install opentool-ai
```
## Usage
Let's define a simple weather logger tool
```python
from opentool import Tool, action, observation
from selenium import webdriver
class WeatherLogger(Tool):
"""A simple weather logger."""
@action
def log(self, message: str) -> None:
"""Logs a message to the log file."""
with open("weather.txt", "a") as file:
file.write("***\n" + message + "\n")
@observation
def weather(self, location: str) -> str:
"""Checks the current weather from the internet using wttr.in."""
weather_api_url = f"http://wttr.in/{location}?format=%l:+%C+%t"
response = requests.get(weather_api_url)
response.raise_for_status()
return response.text
```
We mark the functions to be made available to the agent as
- `@action` if they mutate the environment
- `@observation` if they are read only.
### Function Calling
Use a tool with OpenAI function calling
```python
from openai import OpenAI
client = OpenAI()
weatherlogger = WeatherLogger()
schemas = weatherlogger.json_schema()
messages = []
messages.append({"role": "system", "content": "Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous."})
messages.append({"role": "user", "content": "What is the weather in Paris?"})
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + openai.api_key,
}
json_data = {"model": model, "messages": messages, "tools": schemas}
response = requests.post(
"https://api.openai.com/v1/chat/completions",
headers=headers,
json=json_data,
)
assistant_message = response.json()["choices"][0]["message"]
messages.append(assistant_message)
assistant_message
```
```json
{
"role": "assistant",
"tool_calls": [
{
"id": "call_RYXaDjxpUCfWmpXU7BZEYVqS",
"type": "function",
"function": {
"name": "weather",
"arguments": "{\n \"location\": \"Paris\"}"
}
}
]
}
```
Then to use this action
```python
for tool in assistant_message["tool_calls"]:
action = weatherlogger.find_action(tool["function"]["name"])
args = json.loads(tool["function"]["arguments"])
resp = weatherlogger.use(action, **args)
```
## Available Tools
:computer: [AgentDesk](https://github.com/agentsea/agentdesk) provides AI agents with a full GUI desktop locally or in the cloud.
## Roadmap
- [ ] Integrate with langchain
- [ ] Integrate with babyagi
- [ ] Integrate with autogen
- [ ] Integrate with llamaindex
Raw data
{
"_id": null,
"home_page": "",
"name": "opentool-ai",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "Patrick Barker",
"author_email": "patrickbarkerco@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5d/3e/dabd63205a92fe8388d0b352ff7a061e5c2a261d15d1406b44b3e6335434/opentool_ai-0.1.8.tar.gz",
"platform": null,
"description": "<!-- PROJECT LOGO -->\n<br />\n<p align=\"center\">\n <!-- <a href=\"https://github.com/agentsea/skillpacks\">\n <img src=\"https://project-logo.png\" alt=\"Logo\" width=\"80\">\n </a> -->\n\n <h1 align=\"center\">OpenTool</h1>\n\n <p align=\"center\">\n A common protocol for AI agent tools\n <br />\n <a href=\"https://github.com/agentsea/opentool\"><strong>Explore the docs \u00bb</strong></a>\n <br />\n <br />\n <a href=\"https://github.com/agentsea/opentool\">View Demo</a>\n \u00b7\n <a href=\"https://github.com/agentsea/opentool/issues\">Report Bug</a>\n \u00b7\n <a href=\"https://github.com/agentsea/opentool/issues\">Request Feature</a>\n </p>\n <br>\n</p>\n\nOpenTool provides a common potocol for AI agent tools, use them with your favorite agent framework or model.\n\n## Installation\n\n```\npip install opentool-ai\n```\n\n## Usage\n\nLet's define a simple weather logger tool\n\n```python\nfrom opentool import Tool, action, observation\nfrom selenium import webdriver\n\n\nclass WeatherLogger(Tool):\n \"\"\"A simple weather logger.\"\"\"\n\n @action\n def log(self, message: str) -> None:\n \"\"\"Logs a message to the log file.\"\"\"\n\n with open(\"weather.txt\", \"a\") as file:\n file.write(\"***\\n\" + message + \"\\n\")\n\n @observation\n def weather(self, location: str) -> str:\n \"\"\"Checks the current weather from the internet using wttr.in.\"\"\"\n\n weather_api_url = f\"http://wttr.in/{location}?format=%l:+%C+%t\"\n response = requests.get(weather_api_url)\n response.raise_for_status()\n return response.text\n\n```\n\nWe mark the functions to be made available to the agent as\n\n- `@action` if they mutate the environment\n- `@observation` if they are read only.\n\n### Function Calling\n\nUse a tool with OpenAI function calling\n\n```python\nfrom openai import OpenAI\n\nclient = OpenAI()\n\nweatherlogger = WeatherLogger()\nschemas = weatherlogger.json_schema()\n\nmessages = []\nmessages.append({\"role\": \"system\", \"content\": \"Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\"})\nmessages.append({\"role\": \"user\", \"content\": \"What is the weather in Paris?\"})\n\nheaders = {\n \"Content-Type\": \"application/json\",\n \"Authorization\": \"Bearer \" + openai.api_key,\n}\njson_data = {\"model\": model, \"messages\": messages, \"tools\": schemas}\nresponse = requests.post(\n \"https://api.openai.com/v1/chat/completions\",\n headers=headers,\n json=json_data,\n)\n\nassistant_message = response.json()[\"choices\"][0][\"message\"]\nmessages.append(assistant_message)\nassistant_message\n```\n\n```json\n{\n \"role\": \"assistant\",\n \"tool_calls\": [\n {\n \"id\": \"call_RYXaDjxpUCfWmpXU7BZEYVqS\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"weather\",\n \"arguments\": \"{\\n \\\"location\\\": \\\"Paris\\\"}\"\n }\n }\n ]\n}\n```\n\nThen to use this action\n\n```python\nfor tool in assistant_message[\"tool_calls\"]:\n action = weatherlogger.find_action(tool[\"function\"][\"name\"])\n args = json.loads(tool[\"function\"][\"arguments\"])\n resp = weatherlogger.use(action, **args)\n```\n\n## Available Tools\n\n:computer: [AgentDesk](https://github.com/agentsea/agentdesk) provides AI agents with a full GUI desktop locally or in the cloud.\n\n## Roadmap\n\n- [ ] Integrate with langchain\n- [ ] Integrate with babyagi\n- [ ] Integrate with autogen\n- [ ] Integrate with llamaindex\n",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "A protocol for AI agent tools",
"version": "0.1.8",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d9584ea4a292150bf848a768d7b00997a62de7a3827b9c1d5eee991f1c218a0e",
"md5": "85dd5b509e74ee24611b382fe3777395",
"sha256": "b4f50fb14fca76fb3a2a542ce41fb11c772844a0997a16a0937822a42a8ab5d1"
},
"downloads": -1,
"filename": "opentool_ai-0.1.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "85dd5b509e74ee24611b382fe3777395",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<4.0",
"size": 18953,
"upload_time": "2024-03-01T18:39:35",
"upload_time_iso_8601": "2024-03-01T18:39:35.474877Z",
"url": "https://files.pythonhosted.org/packages/d9/58/4ea4a292150bf848a768d7b00997a62de7a3827b9c1d5eee991f1c218a0e/opentool_ai-0.1.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5d3edabd63205a92fe8388d0b352ff7a061e5c2a261d15d1406b44b3e6335434",
"md5": "f6782621fe971870c1c2e743508e64f4",
"sha256": "654ddbaae2db47b6fa814c9ac3be309079cd24803c65fc61c19b49505c9742ea"
},
"downloads": -1,
"filename": "opentool_ai-0.1.8.tar.gz",
"has_sig": false,
"md5_digest": "f6782621fe971870c1c2e743508e64f4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<4.0",
"size": 12898,
"upload_time": "2024-03-01T18:39:37",
"upload_time_iso_8601": "2024-03-01T18:39:37.046619Z",
"url": "https://files.pythonhosted.org/packages/5d/3e/dabd63205a92fe8388d0b352ff7a061e5c2a261d15d1406b44b3e6335434/opentool_ai-0.1.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-01 18:39:37",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "opentool-ai"
}