Skip to main content

Tool utilities for language models

Project description

toolla

toola is a simple wrapper for the Anthropic API tool use. It has a Chat class that will automatically execute functions that are passed to the chat as tools.

Installation

pip install toolla

In order to make calls to the Anthropic API you must have the ANTHROPIC_API_KEY environment variable set.

export ANTHROPIC_API_KEY=...

Quickstart

Begin by defining the functions you'd like to use as tools

def add(x: int, y: int) -> int:
    """
    A function that adds two numbers

    x: The first integer
    y: The second integer
    """
    return x + y

The format of the docstring is important. The first line MUST be a description of the function. Any remaining lines that contain the char : will be considered arguments to the function along with their descriptions. The Chat class automatically generates tool schema to be used in the API when you create a Chat instance. Simply pass in the functions you want to include as tools

from toolla.chat import Chat

chat = Chat(tools=[add])

Then call chat to use the tool

result = chat("What is 4911+4131?")
print(result)

The result variable will store whatever is returned by the tool. Text responses will be printed to stdout. You should see text printed similar to

To answer your question about what 4911 + 4131 is, I can use the "add" function that's available to me. Let me calculate that for you.
Calling function add
Done.
9042

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

toolla-0.0.2.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

toolla-0.0.2-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page