mirascope.core.anthropic.tool
Module tool
The OpenAITool
class for easy tool usage with OpenAI LLM calls.
Usage
Class AnthropicToolConfig
A tool configuration for Anthropic-specific features.
Bases:
ToolConfigAttributes
Name | Type | Description |
---|---|---|
cache_control | _CacheControl | - |
Class AnthropicTool
A class for defining tools for Anthropic LLM calls.
Example:
from mirascope.core import prompt_template
from mirascope.core.anthropic import anthropic_call
def format_book(title: str, author: str) -> str:
return f"{title} by {author}"
@anthropic_call("claude-3-5-sonnet-20240620", tools=[format_book])
def recommend_book(genre: str) -> str:
return f"Recommend a {genre} book"
response = recommend_book("fantasy")
if tool := response.tool: # returns an `AnthropicTool` instance
print(tool.call())
Bases:
BaseToolAttributes
Name | Type | Description |
---|---|---|
tool_call | SkipJsonSchema[ToolUseBlock] | - |
Function tool_schema
Constructs a ToolParam
tool schema from the BaseModel
schema defined.
Example:
from mirascope.core.anthropic import AnthropicTool
def format_book(title: str, author: str) -> str:
return f"{title} by {author}"
tool_type = AnthropicTool.type_from_fn(format_book)
print(tool_type.tool_schema()) # prints the Anthropic-specific tool schema
Parameters
Name | Type | Description |
---|---|---|
cls | Any | - |
Returns
Type | Description |
---|---|
ToolParam | - |
Function from_tool_call
Constructs an AnthropicTool
instance from a tool_call
.
Parameters
Name | Type | Description |
---|---|---|
cls | Any | - |
tool_call | ToolUseBlock | The Anthropic tool call from which to construct this tool instance. |
allow_partial= False | bool | - |
Returns
Type | Description |
---|---|
AnthropicTool | - |