anthropic-tools


Nameanthropic-tools JSON
Version 1.0.7 PyPI version JSON
download
home_pagehttps://github.com/rizerphe/anthropic-tools
SummarySimplifies the usage of Anthropic Claude's tool use by generating the schemas and parsing the responses for you.
upload_time2024-04-25 14:17:06
maintainerNone
docs_urlNone
authorrizerphe
requires_python<4.0,>=3.8
licenseMIT
keywords nlp anthropic claude claude3 claude-api wrapper functions typing docstring docstrings decorators signatures parsing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Anthropic tools

The `anthropic-tools` library simplifies the usage of Anthropics’s [tool use](https://docs.anthropic.com/claude/docs/tool-use) feature. It abstracts away the complexity of parsing function signatures and docstrings by providing developers with a clean and intuitive interface. It's a near-clone of my [openai-functions](https://openai-functions.readthedocs.io) library that does the same with OpenAI.

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![PyPI version](https://badge.fury.io/py/anthropic-tools.svg)](https://badge.fury.io/py/anthropic-tools) [![Documentation Status](https://readthedocs.org/projects/anthropic-tools/badge/?version=latest)](https://anthropic-tools.readthedocs.io/en/latest/?badge=latest)

## Installation

You can install `anthropic-tools` from PyPI using pip:

```
pip install anthropic-tools
```

## Usage

1. Import the necessary modules and provide your API key:

```python
import enum
import anthropic
from anthropic_tools import Conversation

client = anthropic.Anthropic(
    api_key="<YOUR_API_KEY>",
)
```

2. Create a `Conversation` instance:

```python
conversation = Conversation(client)
```

3. Define your tools using the `@conversation.add_tool` decorator:

```python
class Unit(enum.Enum):
    FAHRENHEIT = "fahrenheit"
    CELSIUS = "celsius"

@conversation.add_tool()
def get_current_weather(location: str, unit: Unit = Unit.FAHRENHEIT) -> dict:
    """Get the current weather in a given location.

    Args:
        location (str): The city and state, e.g., San Francisco, CA
        unit (Unit): The unit to use, e.g., fahrenheit or celsius
    """
    return {
        "location": location,
        "temperature": "72",
        "unit": unit.value,
        "forecast": ["sunny", "windy"],
    }
```

4. Ask the AI a question:

```python
response = conversation.ask("What's the weather in San Francisco?")
# Should return three messages, the last one's content being something like:
# The current weather in San Francisco is 72 degrees Fahrenheit and it is sunny and windy.
```

You can read more about how to use `Conversation` [here](https://anthropic-tools.readthedocs.io/en/latest/conversation.html).

## More barebones use - just schema generation and result parsing:

```python
from anthropic_tools import ToolWrapper

wrapper = ToolWrapper(get_current_weather)
schema = wrapper.schema
result = wrapper({"location": "San Francisco, CA"})
```

Or you could use [skills](https://anthropic-tools.readthedocs.io/en/latest/skills.html).

## How it Works

`anthropic-tools` takes care of the following tasks:

- Parsing the function signatures (with type annotations) and docstrings.
- Sending the conversation and tool descriptions to Anthropic Claude.
- Deciding whether to call a tool based on the model's response.
- Calling the appropriate function with the provided arguments.
- Updating the conversation with the tool response.
- Repeating the process until the model generates a user-facing message.

This abstraction allows developers to focus on defining their functions and adding user messages without worrying about the details of tool use.

## Note

Please note that `anthropic-tools` is an unofficial project not maintained by Anthropic. Use it at your discretion.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rizerphe/anthropic-tools",
    "name": "anthropic-tools",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "nlp, anthropic, claude, claude3, claude-api, wrapper, functions, typing, docstring, docstrings, decorators, signatures, parsing",
    "author": "rizerphe",
    "author_email": "44440399+rizerphe@users.noreply.github.com",
    "download_url": "https://files.pythonhosted.org/packages/8c/66/a10d6859ecd7d4ee2caebf61b930dd7016d887002df630ce480843b88187/anthropic_tools-1.0.7.tar.gz",
    "platform": null,
    "description": "# Anthropic tools\n\nThe `anthropic-tools` library simplifies the usage of Anthropics\u2019s [tool use](https://docs.anthropic.com/claude/docs/tool-use) feature. It abstracts away the complexity of parsing function signatures and docstrings by providing developers with a clean and intuitive interface. It's a near-clone of my [openai-functions](https://openai-functions.readthedocs.io) library that does the same with OpenAI.\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![PyPI version](https://badge.fury.io/py/anthropic-tools.svg)](https://badge.fury.io/py/anthropic-tools) [![Documentation Status](https://readthedocs.org/projects/anthropic-tools/badge/?version=latest)](https://anthropic-tools.readthedocs.io/en/latest/?badge=latest)\n\n## Installation\n\nYou can install `anthropic-tools` from PyPI using pip:\n\n```\npip install anthropic-tools\n```\n\n## Usage\n\n1. Import the necessary modules and provide your API key:\n\n```python\nimport enum\nimport anthropic\nfrom anthropic_tools import Conversation\n\nclient = anthropic.Anthropic(\n    api_key=\"<YOUR_API_KEY>\",\n)\n```\n\n2. Create a `Conversation` instance:\n\n```python\nconversation = Conversation(client)\n```\n\n3. Define your tools using the `@conversation.add_tool` decorator:\n\n```python\nclass Unit(enum.Enum):\n    FAHRENHEIT = \"fahrenheit\"\n    CELSIUS = \"celsius\"\n\n@conversation.add_tool()\ndef get_current_weather(location: str, unit: Unit = Unit.FAHRENHEIT) -> dict:\n    \"\"\"Get the current weather in a given location.\n\n    Args:\n        location (str): The city and state, e.g., San Francisco, CA\n        unit (Unit): The unit to use, e.g., fahrenheit or celsius\n    \"\"\"\n    return {\n        \"location\": location,\n        \"temperature\": \"72\",\n        \"unit\": unit.value,\n        \"forecast\": [\"sunny\", \"windy\"],\n    }\n```\n\n4. Ask the AI a question:\n\n```python\nresponse = conversation.ask(\"What's the weather in San Francisco?\")\n# Should return three messages, the last one's content being something like:\n# The current weather in San Francisco is 72 degrees Fahrenheit and it is sunny and windy.\n```\n\nYou can read more about how to use `Conversation` [here](https://anthropic-tools.readthedocs.io/en/latest/conversation.html).\n\n## More barebones use - just schema generation and result parsing:\n\n```python\nfrom anthropic_tools import ToolWrapper\n\nwrapper = ToolWrapper(get_current_weather)\nschema = wrapper.schema\nresult = wrapper({\"location\": \"San Francisco, CA\"})\n```\n\nOr you could use [skills](https://anthropic-tools.readthedocs.io/en/latest/skills.html).\n\n## How it Works\n\n`anthropic-tools` takes care of the following tasks:\n\n- Parsing the function signatures (with type annotations) and docstrings.\n- Sending the conversation and tool descriptions to Anthropic Claude.\n- Deciding whether to call a tool based on the model's response.\n- Calling the appropriate function with the provided arguments.\n- Updating the conversation with the tool response.\n- Repeating the process until the model generates a user-facing message.\n\nThis abstraction allows developers to focus on defining their functions and adding user messages without worrying about the details of tool use.\n\n## Note\n\nPlease note that `anthropic-tools` is an unofficial project not maintained by Anthropic. Use it at your discretion.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simplifies the usage of Anthropic Claude's tool use by generating the schemas and parsing the responses for you.",
    "version": "1.0.7",
    "project_urls": {
        "Documentation": "https://anthropic-tools.readthedocs.io/",
        "Homepage": "https://github.com/rizerphe/anthropic-tools"
    },
    "split_keywords": [
        "nlp",
        " anthropic",
        " claude",
        " claude3",
        " claude-api",
        " wrapper",
        " functions",
        " typing",
        " docstring",
        " docstrings",
        " decorators",
        " signatures",
        " parsing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fc511101eb20e442b54e015c1f324f897b20db7bdc7c428030caadc7da38e866",
                "md5": "c8e94055e2a96b432d6fdefcadf771b2",
                "sha256": "5144d9a93c583870c2b6d7744b4b79e105da5cd1e5b9975ee1e8d56f378134b5"
            },
            "downloads": -1,
            "filename": "anthropic_tools-1.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c8e94055e2a96b432d6fdefcadf771b2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 23921,
            "upload_time": "2024-04-25T14:17:04",
            "upload_time_iso_8601": "2024-04-25T14:17:04.946900Z",
            "url": "https://files.pythonhosted.org/packages/fc/51/1101eb20e442b54e015c1f324f897b20db7bdc7c428030caadc7da38e866/anthropic_tools-1.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8c66a10d6859ecd7d4ee2caebf61b930dd7016d887002df630ce480843b88187",
                "md5": "764ecda51c68cdeb6645b1a9f9997013",
                "sha256": "c594f7f405ee208f4a32ffaede098fb00efbddc8d714dc601dceddfd7ca51c4b"
            },
            "downloads": -1,
            "filename": "anthropic_tools-1.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "764ecda51c68cdeb6645b1a9f9997013",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 15979,
            "upload_time": "2024-04-25T14:17:06",
            "upload_time_iso_8601": "2024-04-25T14:17:06.222444Z",
            "url": "https://files.pythonhosted.org/packages/8c/66/a10d6859ecd7d4ee2caebf61b930dd7016d887002df630ce480843b88187/anthropic_tools-1.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-25 14:17:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rizerphe",
    "github_project": "anthropic-tools",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "anthropic-tools"
}
        
Elapsed time: 0.26053s