{"id":25803550,"url":"https://github.com/lixelv/openai-tools-decorator","last_synced_at":"2025-02-27T17:56:24.099Z","repository":{"id":271018626,"uuid":"912160561","full_name":"lixelv/openai-tools-decorator","owner":"lixelv","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-09T01:29:00.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T20:52:06.138Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lixelv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-04T19:16:03.000Z","updated_at":"2025-02-09T01:29:03.000Z","dependencies_parsed_at":"2025-01-04T20:34:52.501Z","dependency_job_id":"824aec2d-e7f8-4290-9103-66bf8ede01b8","html_url":"https://github.com/lixelv/openai-tools-decorator","commit_stats":null,"previous_names":["lixelv/openai-tools-decorator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lixelv%2Fopenai-tools-decorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lixelv%2Fopenai-tools-decorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lixelv%2Fopenai-tools-decorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lixelv%2Fopenai-tools-decorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lixelv","download_url":"https://codeload.github.com/lixelv/openai-tools-decorator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241041033,"owners_count":19898975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-27T17:56:21.970Z","updated_at":"2025-02-27T17:56:24.087Z","avatar_url":"https://github.com/lixelv.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# openai_tools_decorator\n\nA lightweight Python library that streamlines creating and invoking “tools” (functions) in your OpenAI ChatCompletion-based projects. It lets you register and call both **synchronous** and **asynchronous** functions via decorators.\n\n## Installation\n\n```bash\npip install openai_tools_decorator\n```\n\n## Quick Start\n\n### 1. Import and Initialization\n\n```python\nfrom openai_tools_decorator import OpenAIT\n\nclient = OpenAIT()\n```\n\n### 2. Adding Tools\n\n```python\n@client.add_tool(\n    {\n        \"description\": \"Get current weather for a city\",\n    }\n)\ndef get_weather(city: str):\n    return f\"Weather in {city}: 25°C\"\n```\n\n### 3. Using Tools with Chat\n\n```python\nuser_input = \"How cold is it in Moscow right now?\"\nresponse = await client.run_with_tool(\n    user_input,\n    messages=[],\n    model=\"gpt-4o\"\n)\nprint(response)  # The assistant’s response, possibly including a tool call\n```\n\n### 4. Removing Tools\n\nTo remove a tool, use `remove_tool` with function's name as an argument:\n\n```python\nclient.remove_tool(\"get_weather\")\n```\n\nIf the tool is not found, `remove_tool` will raise `ValueError`.\n\n## Example\n\n```python\nimport asyncio\nimport aiohttp\nfrom openai_tools_decorator import OpenAIT\n\nclient = OpenAIT()\napi_key = \"\u003cYOUR_API_KEY\u003e\"\n\nasync def fetch_url(url):\n    async with aiohttp.ClientSession() as session:\n        async with session.get(url) as resp:\n            return await resp.text()\n\n@client.add_tool(\n    {\n        \"description\": \"Fetch weather from an API\",\n    }\n)\nasync def get_weather(city: str):\n    url = f\"https://api.openweathermap.org/data/2.5/weather?q={city}\u0026appid={api_key}\u0026units=metric\"\n    return await fetch_url(url)\n\nasync def main():\n    question = \"What's the temperature in London?\"\n    result = await client.run_with_tool(question, messages=[])\n    print(\"Assistant says:\", result)\n\nasyncio.run(main())\n```\n\n## Key Points\n\n-   You can register **sync and async ** functions.\n-   Tools are automatically registered and described for the OpenAI model.\n-   The model decides whether to call a tool during the dialogue.\n-   You can quickly remove unnecessary tools using `remove_tool`.\n\n## License\n\nDistributed under MIT or any other license of your choice. Contributions and feedback are always welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flixelv%2Fopenai-tools-decorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flixelv%2Fopenai-tools-decorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flixelv%2Fopenai-tools-decorator/lists"}