- Notifications
You must be signed in to change notification settings - Fork0
Generate Anthropic Claude tool use schemas based on type annotations and function docstrings.
License
rizerphe/anthropic-tools
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Theanthropic-tools
library simplifies the usage of Anthropics’stool 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 myopenai-functions library that does the same with OpenAI.
You can installanthropic-tools
from PyPI using pip:
pip install anthropic-tools
- Import the necessary modules and provide your API key:
importenumimportanthropicfromanthropic_toolsimportConversationclient=anthropic.Anthropic(api_key="<YOUR_API_KEY>",)
- Create a
Conversation
instance:
conversation=Conversation(client)
- Define your tools using the
@conversation.add_tool
decorator:
classUnit(enum.Enum):FAHRENHEIT="fahrenheit"CELSIUS="celsius"@conversation.add_tool()defget_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"], }
- Ask the AI a question:
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 useConversation
here.
fromanthropic_toolsimportToolWrapperwrapper=ToolWrapper(get_current_weather)schema=wrapper.schemaresult=wrapper({"location":"San Francisco, CA"})
Or you could useskills.
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.
Please note thatanthropic-tools
is an unofficial project not maintained by Anthropic. Use it at your discretion.
About
Generate Anthropic Claude tool use schemas based on type annotations and function docstrings.