Tools¶
Tools are user-defined functions that an LLM (Large Language Model) can ask the user to invoke on its behalf. This greatly enhances the capabilities of LLMs by enabling them to perform specific tasks, access external data, interact with other systems, and more.
Mirascope enables defining tools in a provider-agnostic way, which can be used across all supported LLM providers without modification.
Diagram illustrating how tools are called
When an LLM decides to use a tool, it indicates the tool name and argument values in its response. It's important to note that the LLM doesn't actually execute the function; instead, you are responsible for calling the tool and (optionally) providing the output back to the LLM in a subsequent interaction. For more details on such iterative tool-use flows, check out the Tool Message Parameters section below as well as the section on Agents.
sequenceDiagram
participant YC as Your Code
participant LLM
YC->>LLM: Call with prompt and function definitions
loop Tool Calls
LLM->>LLM: Decide to respond or call functions
LLM->>YC: Respond with function to call and arguments
YC->>YC: Execute function with given arguments
YC->>LLM: Call with prompt and function result
end
LLM->>YC: Final response
Basic Usage and Syntax¶
API Documentation
There are two ways of defining tools in Mirascope: BaseTool
and functions.
You can consider the functional definitions a shorthand form of writing the BaseTool
version of the same tool. Under the hood, tools defined as functions will get converted automatically into their corresponding BaseTool
.
Let's take a look at a basic example of each using Mirascope vs. official provider SDKs:
Mirascope
from mirascope.core import BaseTool, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, Messages, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, Messages, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, Messages, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, Messages, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, Messages, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, Messages, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, Messages, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, Messages, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, Messages, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, openai, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, anthropic, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, mistral, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, google, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, groq, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, cohere, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, litellm, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, azure, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseTool, bedrock, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import Messages, openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import Messages, anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import Messages, mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import Messages, google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import Messages, groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import Messages, cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import Messages, litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import Messages, azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import Messages, bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import openai, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import anthropic, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import mistral, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import google, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import groq, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import cohere, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import litellm, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import azure, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import bedrock, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
from mirascope.core import BaseMessageParam, bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
# Output: Patrick Rothfuss
else:
print(response.content)
Official SDK
import json
from openai import OpenAI
client = OpenAI()
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
def identify_author(book: str) -> str:
completion = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": f"Who wrote {book}"}],
tools=[
{
"function": {
"name": "get_book_author",
"description": "Returns the author of the book with the given title.",
"parameters": {
"properties": {"title": {"type": "string"}},
"required": ["title"],
"type": "object",
},
},
"type": "function",
}
],
)
if tool_calls := completion.choices[0].message.tool_calls:
if tool_calls[0].function.name == "get_book_author":
return get_book_author(**json.loads(tool_calls[0].function.arguments))
return str(completion.choices[0].message.content)
author = identify_author("The Name of the Wind")
print(author)
from anthropic import Anthropic
client = Anthropic()
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
def identify_author(book: str) -> str:
message = client.messages.create(
model="claude-3-5-sonnet-20240620",
max_tokens=1024,
messages=[{"role": "user", "content": f"Who wrote {book}?"}],
tools=[
{
"name": "get_book_author",
"description": "Returns the author of the book with the given title.",
"input_schema": {
"properties": {"title": {"type": "string"}},
"required": ["title"],
"type": "object",
},
}
],
)
content = ""
for block in message.content:
if block.type == "tool_use":
if block.name == "get_book_author":
return get_book_author(**block.input) # pyright: ignore [reportCallIssue]
else:
content += block.text
return content
author = identify_author("The Name of the Wind")
print(author)
import json
import os
from typing import cast
from mistralai import Mistral
client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
def identify_author(book: str) -> str | None:
completion = client.chat.complete(
model="mistral-large-latest",
messages=[{"role": "user", "content": f"Who wrote {book}?"}],
tools=[
{
"function": {
"name": "get_book_author",
"description": "Returns the author of the book with the given title.",
"parameters": {
"properties": {"title": {"type": "string"}},
"required": ["title"],
"type": "object",
},
},
"type": "function",
}
],
)
if not completion or not completion.choices:
return None
if tool_calls := completion.choices[0].message.tool_calls:
if tool_calls[0].function.name == "get_book_author":
return get_book_author(
**json.loads(cast(str, tool_calls[0].function.arguments))
)
return cast(str, completion.choices[0].message.content)
author = identify_author("The Name of the Wind")
print(author)
from google.genai import Client
from google.genai.types import FunctionDeclaration, Tool, GenerateContentConfig
client = Client()
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
def identify_author(book: str) -> str:
response = client.models.generate_content(
model="gemini-1.5-flash",
contents={"parts": [{"text": f"Who wrote {book}?"}]},
config=GenerateContentConfig(
tools=[
Tool(
function_declarations=[
FunctionDeclaration(
**{
"name": "get_book_author",
"description": "Returns the author of the book with the given title.",
"parameters": {
"properties": {"title": {"type": "string"}},
"required": ["title"],
"type": "object",
},
}
)
]
)
]
),
)
if tool_calls := [
function_call
for function_call in (response.function_calls or [])
if function_call.args
]:
if tool_calls[0].name == "get_book_author":
return get_book_author(**dict((tool_calls[0].args or {}).items())) # pyright: ignore [reportArgumentType]
return response.text or ""
author = identify_author("The Name of the Wind")
print(author)
import json
from groq import Groq
client = Groq()
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
def identify_author(book: str) -> str:
completion = client.chat.completions.create(
model="llama-3.1-70b-versatile",
messages=[{"role": "user", "content": f"Who wrote {book}?"}],
tools=[
{
"function": {
"name": "get_book_author",
"description": "Returns the author of the book with the given title.",
"parameters": {
"properties": {"title": {"type": "string"}},
"required": ["title"],
"type": "object",
},
},
"type": "function",
}
],
)
if tool_calls := completion.choices[0].message.tool_calls:
if tool_calls[0].function.name == "get_book_author":
return get_book_author(**json.loads(tool_calls[0].function.arguments))
return str(completion.choices[0].message.content)
author = identify_author("The Name of the Wind")
print(author)
from typing import cast
from cohere import Client
from cohere.types import Tool, ToolParameterDefinitionsValue
client = Client()
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
def identify_author(book: str) -> str:
response = client.chat(
model="command-r-plus",
message=f"Who wrote {book}?",
tools=[
Tool(
name="get_book_author",
description="Returns the author of the book with the given title.",
parameter_definitions={
"title": ToolParameterDefinitionsValue(
description=None, type="string", required=True
)
},
)
],
)
if tool_calls := response.tool_calls:
if tool_calls[0].name == "get_book_author":
return get_book_author(**(cast(dict[str, str], tool_calls[0].parameters)))
return response.text
author = identify_author("The Name of the Wind")
print(author)
import json
from litellm import completion
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
def identify_author(book: str) -> str:
response = completion(
model="gpt-4o-mini",
messages=[{"role": "user", "content": f"Who wrote {book}"}],
tools=[
{
"function": {
"name": "get_book_author",
"description": "Returns the author of the book with the given title.",
"parameters": {
"properties": {"title": {"type": "string"}},
"required": ["title"],
"type": "object",
},
},
"type": "function",
}
],
)
if tool_calls := response.choices[0].message.tool_calls: # pyright: ignore [reportAttributeAccessIssue]
if tool_calls[0].function.name == "get_book_author":
return get_book_author(**json.loads(tool_calls[0].function.arguments))
return str(response.choices[0].message.content) # pyright: ignore [reportAttributeAccessIssue]
author = identify_author("The Name of the Wind")
print(author)
import json
from azure.ai.inference import ChatCompletionsClient
from azure.ai.inference.models import (
ChatCompletionsToolDefinition,
ChatRequestMessage,
FunctionDefinition,
)
from azure.core.credentials import AzureKeyCredential
client = ChatCompletionsClient(
endpoint="YOUR_ENDPOINT", credential=AzureKeyCredential("YOUR_KEY")
)
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
def identify_author(book: str) -> str:
completion = client.complete(
model="gpt-4o-mini",
messages=[
ChatRequestMessage({"role": "user", "content": f"Who wrote {book}?"})
],
tools=[
ChatCompletionsToolDefinition(
function=FunctionDefinition(
name="get_book_author",
description="Returns the author of the book with the given title.",
parameters={
"properties": {"title": {"type": "string"}},
"required": ["title"],
"type": "object",
},
)
)
],
)
if tool_calls := completion.choices[0].message.tool_calls:
if tool_calls[0].function.name == "get_book_author":
return get_book_author(**json.loads(tool_calls[0].function.arguments))
return str(completion.choices[0].message.content)
author = identify_author("The Name of the Wind")
print(author)
import boto3
bedrock_client = boto3.client(service_name="bedrock-runtime")
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
def identify_author(book: str) -> str:
messages = [{"role": "user", "content": [{"text": f"Who wrote {book}?"}]}]
tool_config = {
"tools": [
{
"toolSpec": {
"name": "get_book_author",
"description": "Returns the author of the book with the given title.",
"inputSchema": {
"json": {
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "The title of the book.",
}
},
"required": ["title"],
}
},
}
}
]
}
response = bedrock_client.converse(
modelId="anthropic.claude-3-haiku-20240307-v1:0",
messages=messages,
toolConfig=tool_config,
)
content = ""
output_message = response["output"]["message"]
messages.append(output_message)
stop_reason = response["stopReason"]
if stop_reason == "tool_use":
tool_requests = output_message["content"]
for tool_request in tool_requests:
if "toolUse" in tool_request:
tool = tool_request["toolUse"]
if tool["name"] == "get_book_author":
return get_book_author(**tool["input"])
for content_piece in output_message["content"]:
if "text" in content_piece:
content += content_piece["text"]
return content
author = identify_author("The Name of the Wind")
print(author)
In this example we:
- Define the
GetBookAuthor
/get_book_author
tool (a dummy method for the example) - Set the
tools
argument in thecall
decorator to give the LLM access to the tool. - We call
identify_author
, which automatically generates the corresponding provider-specific tool schema under the hood. - Check if the response from
identify_author
contains a tool, which is theBaseTool
instance constructed from the underlying tool call- If yes, we call the constructed tool's
call
method and print its output. This calls the tool with the arguments provided by the LLM. - If no, we print the content of the response (assuming no tool was called).
- If yes, we call the constructed tool's
The core idea to understand here is that the LLM is asking us to call the tool on its behalf with arguments that it has provided. In the above example, the LLM chooses to call the tool to get the author rather than relying on its world knowledge.
This is particularly important for buildling applications with access to live information and external systems.
For the purposes of this example we are showing just a single tool call. Generally, you would then give the tool call's output back to the LLM and make another call so the LLM can generate a response based on the output of the tool. We cover this in more detail in the section on Agents
Accessing Original Tool Call¶
All provider-specific BaseTool
instances have a tool_call
property for accessing the original LLM tool call.
from mirascope.core import BaseTool, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, Messages, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, Messages, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, Messages, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, Messages, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, Messages, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, Messages, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, Messages, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, Messages, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, Messages, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, openai, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, anthropic, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, mistral, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, google, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, groq, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, cohere, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, litellm, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, azure, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseTool, bedrock, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import Messages, openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import Messages, anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import Messages, mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import Messages, google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import Messages, groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import Messages, cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import Messages, litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import Messages, azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import Messages, bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import openai, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import anthropic, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import mistral, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import google, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import groq, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import cohere, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import litellm, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import azure, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import bedrock, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
from mirascope.core import BaseMessageParam, bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
print(f"Original tool call: {tool.tool_call}")
else:
print(response.content)
Reasoning for provider-specific BaseTool
objects
The reason that we have provider-specific tools (e.g. OpenAITool
) is to provide proper type hints and safety when accessing the original tool call.
Supported Field Types¶
While Mirascope provides a consistent interface, type support varies among providers:
Type | Anthropic | Cohere | Gemini | Groq | Mistral | OpenAI |
---|---|---|---|---|---|---|
str | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
int | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
float | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
bool | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
bytes | ✓ | ✓ | - | ✓ | ✓ | ✓ |
list | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
set | ✓ | ✓ | - | ✓ | ✓ | ✓ |
tuple | ✓ | ✓ | - | ✓ | ✓ | - |
dict | ✓ | ✓ | ✓ | ✓ | ✓ | - |
Literal/Enum | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
BaseModel | ✓ | - | ✓ | ✓ | ✓ | ✓ |
Nested ($def) | ✓ | - | - | ✓ | ✓ | ✓ |
Legend: ✓ (Supported), - (Not Supported)
Consider provider-specific capabilities when working with advanced type structures. Even for supported types, LLM outputs may sometimes be incorrect or of the wrong type. In such cases, prompt engineering or error handling (like retries and reinserting validation errors) may be necessary.
Parallel Tool Calls¶
In certain cases the LLM will ask to call multiple tools in the same response. Mirascope makes calling all such tools simple:
from mirascope.core import BaseTool, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, openai, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, anthropic, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, mistral, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, google, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, groq, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, cohere, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, litellm, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, azure, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, bedrock, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import Messages, openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import Messages, anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import Messages, mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import Messages, google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import Messages, groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import Messages, cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import Messages, litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import Messages, azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import Messages, bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import openai, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import anthropic, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import mistral, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import google, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import groq, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import cohere, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import litellm, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import azure, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import bedrock, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
@prompt_template("Who wrote {books}?")
def identify_authors(books: list[str]): ...
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
response = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
if tools := response.tools:
for tool in tools:
print(tool.call())
else:
print(response.content)
If your tool calls are I/O-bound, it's often worth writing async tools so that you can run all of the tools calls in parallel for better efficiency.
Streaming Tools¶
Mirascope supports streaming responses with tools, which is useful for long-running tasks or real-time updates:
from mirascope.core import BaseTool, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor], stream=True
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor], stream=True
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, openai, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, anthropic, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, mistral, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, google, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, groq, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, cohere, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, litellm, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, azure, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, bedrock, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor], stream=True
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor], stream=True
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author], stream=True
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author], stream=True
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import openai, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import anthropic, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import mistral, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import google, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import groq, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import cohere, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import litellm, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import azure, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author], stream=True)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import bedrock, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author], stream=True
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author], stream=True)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author], stream=True
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
When are tools returned?
When we identify that a tool is being streamed, we will internally reconstruct the tool from the streamed response. This means that the tool won't be returned until the full tool has been streamed and reconstructed on your behalf.
Not all providers support streaming tools
Currently only OpenAI, Anthropic, Mistral, and Groq support streaming tools. All other providers will always return None
for tools.
If you think we're missing any, let us know!
Streaming Partial Tools¶
You can also stream intermediate partial tools and their deltas (rather than just the fully constructed tool) by setting stream={"partial_tools": True}
:
from mirascope.core import BaseTool, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call(
"gpt-4o-mini",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call(
"claude-3-5-sonnet-20240620",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call(
"mistral-large-latest",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call(
"gemini-1.5-flash",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call(
"llama-3.1-70b-versatile",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call(
"command-r-plus",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call(
"gpt-4o-mini",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call(
"gpt-4o-mini",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call(
"gpt-4o-mini",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call(
"claude-3-5-sonnet-20240620",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call(
"mistral-large-latest",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call(
"gemini-1.5-flash",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call(
"llama-3.1-70b-versatile",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call(
"command-r-plus",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call(
"gpt-4o-mini",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call(
"gpt-4o-mini",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, Messages, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, openai, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call(
"gpt-4o-mini",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, anthropic, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call(
"claude-3-5-sonnet-20240620",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, mistral, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call(
"mistral-large-latest",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, google, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call(
"gemini-1.5-flash",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, groq, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call(
"llama-3.1-70b-versatile",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, cohere, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call(
"command-r-plus",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, litellm, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call(
"gpt-4o-mini",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, azure, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call(
"gpt-4o-mini",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseTool, bedrock, prompt_template
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, openai
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call(
"gpt-4o-mini",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, anthropic
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call(
"claude-3-5-sonnet-20240620",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, mistral
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call(
"mistral-large-latest",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, google
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call(
"gemini-1.5-flash",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, groq
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call(
"llama-3.1-70b-versatile",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, cohere
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call(
"command-r-plus",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, litellm
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call(
"gpt-4o-mini",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, azure
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call(
"gpt-4o-mini",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, BaseTool, bedrock
from pydantic import Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(..., description="The title of the book.")
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0",
tools=[GetBookAuthor],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call(
"gpt-4o-mini",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call(
"claude-3-5-sonnet-20240620",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call(
"mistral-large-latest",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call(
"gemini-1.5-flash",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call(
"llama-3.1-70b-versatile",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call(
"command-r-plus",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call(
"gpt-4o-mini",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call(
"gpt-4o-mini",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> str:
return f"Who wrote {books}?"
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call(
"gpt-4o-mini",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call(
"claude-3-5-sonnet-20240620",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call(
"mistral-large-latest",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call(
"gemini-1.5-flash",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call(
"llama-3.1-70b-versatile",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call(
"command-r-plus",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call(
"gpt-4o-mini",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call(
"gpt-4o-mini",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import Messages, bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> Messages.Type:
return Messages.User(f"Who wrote {books}?")
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import openai, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call(
"gpt-4o-mini",
tools=[get_book_author],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import anthropic, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call(
"claude-3-5-sonnet-20240620",
tools=[get_book_author],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import mistral, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call(
"mistral-large-latest",
tools=[get_book_author],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import google, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call(
"gemini-1.5-flash",
tools=[get_book_author],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import groq, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call(
"llama-3.1-70b-versatile",
tools=[get_book_author],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import cohere, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call(
"command-r-plus",
tools=[get_book_author],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import litellm, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call(
"gpt-4o-mini",
tools=[get_book_author],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import azure, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call(
"gpt-4o-mini",
tools=[get_book_author],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import bedrock, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0",
tools=[get_book_author],
stream={"partial_tools": True},
)
@prompt_template("Who wrote {book}?")
def identify_authors(books: list[str]): ...
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, openai
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call(
"gpt-4o-mini",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, anthropic
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call(
"claude-3-5-sonnet-20240620",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, mistral
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call(
"mistral-large-latest",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call(
"gemini-1.5-flash",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, groq
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call(
"llama-3.1-70b-versatile",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, cohere
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call(
"command-r-plus",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool: # will always be None, not supported at the provider level
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, litellm
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call(
"gpt-4o-mini",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, azure
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call(
"gpt-4o-mini",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
from mirascope.core import BaseMessageParam, bedrock
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call(
"anthropic.claude-3-haiku-20240307-v1:0",
tools=[get_book_author],
stream={"partial_tools": True},
)
def identify_authors(books: list[str]) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {books}?")]
stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"])
for chunk, tool in stream:
if tool:
if tool.delta is not None: # partial tool
print(tool.delta)
else:
print(tool.call())
else:
print(chunk.content, end="", flush=True)
Tool Message Parameters¶
Generally the next step after the LLM returns a tool call is for you to call the tool on its behalf and supply the output in a subsequent call.
Let's take a look at a basic example of this:
from mirascope.core import BaseTool, Messages, openai
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[openai.OpenAIMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, anthropic
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[anthropic.AnthropicMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, mistral
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[mistral.MistralMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, google
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[google.GoogleMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, groq
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(book: str, history: list[groq.GroqMessageParam]) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, cohere
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[cohere.CohereMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, litellm
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[litellm.LiteLLMMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, azure
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str, history: list[azure.AzureMessageParam]) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, bedrock
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[bedrock.BedrockMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, openai
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[openai.OpenAIMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, anthropic
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[anthropic.AnthropicMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, mistral
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[mistral.MistralMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, google
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[google.GoogleMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, groq
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(book: str, history: list[groq.GroqMessageParam]) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, cohere
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[cohere.CohereMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, litellm
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[litellm.LiteLLMMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, azure
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str, history: list[azure.AzureMessageParam]) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseTool, Messages, bedrock
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[bedrock.BedrockMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, BaseTool, openai, prompt_template
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[openai.OpenAIMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, BaseTool, anthropic, prompt_template
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[anthropic.AnthropicMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, BaseTool, mistral, prompt_template
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[mistral.MistralMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, BaseTool, google, prompt_template
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[google.GoogleMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, BaseTool, groq, prompt_template
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[groq.GroqMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, BaseTool, cohere, prompt_template
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[cohere.CohereMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, BaseTool, litellm, prompt_template
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[litellm.LiteLLMMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, BaseTool, azure, prompt_template
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[azure.AzureMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, BaseTool, bedrock, prompt_template
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[bedrock.BedrockMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, BaseTool, openai
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[openai.OpenAIMessageParam]
) -> list[openai.OpenAIMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, BaseTool, anthropic
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[anthropic.AnthropicMessageParam]
) -> list[anthropic.AnthropicMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, BaseTool, mistral
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[mistral.MistralMessageParam]
) -> list[mistral.MistralMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, BaseTool, google
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[google.GoogleMessageParam]
) -> list[google.GoogleMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, BaseTool, groq
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[groq.GroqMessageParam]
) -> list[groq.GroqMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, BaseTool, cohere
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[cohere.CohereMessageParam]
) -> list[cohere.CohereMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, BaseTool, litellm
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[litellm.LiteLLMMessageParam]
) -> list[litellm.LiteLLMMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, BaseTool, azure
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[azure.AzureMessageParam]
) -> list[azure.AzureMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, BaseTool, bedrock
class GetBookAuthor(BaseTool):
title: str
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(
book: str, history: list[bedrock.BedrockMessageParam]
) -> list[bedrock.BedrockMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, openai
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(
book: str, history: list[openai.OpenAIMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, anthropic
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(
book: str, history: list[anthropic.AnthropicMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, mistral
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(
book: str, history: list[mistral.MistralMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, google
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(
book: str, history: list[google.GoogleMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, groq
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(book: str, history: list[groq.GroqMessageParam]) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, cohere
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(
book: str, history: list[cohere.CohereMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, litellm
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(
book: str, history: list[litellm.LiteLLMMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, azure
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str, history: list[azure.AzureMessageParam]) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, bedrock
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(
book: str, history: list[bedrock.BedrockMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, openai
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(
book: str, history: list[openai.OpenAIMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, anthropic
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(
book: str, history: list[anthropic.AnthropicMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, mistral
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(
book: str, history: list[mistral.MistralMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, google
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(
book: str, history: list[google.GoogleMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, groq
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(book: str, history: list[groq.GroqMessageParam]) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, cohere
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(
book: str, history: list[cohere.CohereMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, litellm
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(
book: str, history: list[litellm.LiteLLMMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, azure
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str, history: list[azure.AzureMessageParam]) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import Messages, bedrock
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(
book: str, history: list[bedrock.BedrockMessageParam]
) -> Messages.Type:
messages = [*history]
if book:
messages.append(Messages.User(f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, openai, prompt_template
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[openai.OpenAIMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, anthropic, prompt_template
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[anthropic.AnthropicMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, mistral, prompt_template
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[mistral.MistralMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, google, prompt_template
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[google.GoogleMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, groq, prompt_template
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[groq.GroqMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, cohere, prompt_template
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[cohere.CohereMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, litellm, prompt_template
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[litellm.LiteLLMMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, azure, prompt_template
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[azure.AzureMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseDynamicConfig, bedrock, prompt_template
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
@prompt_template(
"""
MESSAGES: {history}
USER: {query}
"""
)
def identify_author(
book: str, history: list[bedrock.BedrockMessageParam]
) -> BaseDynamicConfig:
return {"computed_fields": {"query": f"Who wrote {book}" if book else ""}}
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, openai
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(
book: str, history: list[openai.OpenAIMessageParam]
) -> list[openai.OpenAIMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, anthropic
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(
book: str, history: list[anthropic.AnthropicMessageParam]
) -> list[anthropic.AnthropicMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, mistral
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(
book: str, history: list[mistral.MistralMessageParam]
) -> list[mistral.MistralMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, google
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(
book: str, history: list[google.GoogleMessageParam]
) -> list[google.GoogleMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, groq
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(
book: str, history: list[groq.GroqMessageParam]
) -> list[groq.GroqMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, cohere
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(
book: str, history: list[cohere.CohereMessageParam]
) -> list[cohere.CohereMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, litellm
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(
book: str, history: list[litellm.LiteLLMMessageParam]
) -> list[litellm.LiteLLMMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, azure
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(
book: str, history: list[azure.AzureMessageParam]
) -> list[azure.AzureMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
from mirascope.core import BaseMessageParam, bedrock
def get_book_author(title: str) -> str:
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(
book: str, history: list[bedrock.BedrockMessageParam]
) -> list[bedrock.BedrockMessageParam]:
messages = [*history]
if book:
messages.append(BaseMessageParam(role="user", content=f"Who wrote {book}?"))
return messages
history = []
response = identify_author("The Name of the Wind", history)
history += [response.user_message_param, response.message_param]
while tool := response.tool:
tools_and_outputs = [(tool, tool.call())]
history += response.tool_message_params(tools_and_outputs)
response = identify_author("", history)
history.append(response.message_param)
print(response.content)
# Output: The Name of the Wind was written by Patrick Rothfuss.
In this example we:
- Add
history
to maintain the messages across multiple calls to the LLM. - Loop until the response no longer has tools calls.
- While there are tool calls, call the tools, append their corresponding message parameters to the history, and make a subsequent call with an empty query and updated history. We use an empty query because the original user message is already included in the history.
- Print the final response content once the LLM is done calling tools.
Validation and Error Handling¶
Since BaseTool
is a subclass of Pydantic's BaseModel
, they are validated on construction, so it's important that you handle potential ValidationError
's for building more robust applications:
from typing import Annotated
from mirascope.core import BaseTool, openai
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, anthropic
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, mistral
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, google
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, groq
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, cohere
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, litellm
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, azure
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, bedrock
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, Messages, openai
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, Messages, anthropic
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, Messages, mistral
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, Messages, google
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, Messages, groq
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, Messages, cohere
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, Messages, litellm
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, Messages, azure
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, Messages, bedrock
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, openai, prompt_template
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, anthropic, prompt_template
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, mistral, prompt_template
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, google, prompt_template
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, groq, prompt_template
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, cohere, prompt_template
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, litellm, prompt_template
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, azure, prompt_template
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseTool, bedrock, prompt_template
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, BaseTool, openai
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, BaseTool, anthropic
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, BaseTool, mistral
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, BaseTool, google
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, BaseTool, groq
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, BaseTool, cohere
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, BaseTool, litellm
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, BaseTool, azure
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, BaseTool, bedrock
from pydantic import AfterValidator, Field, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: Annotated[str, AfterValidator(is_upper)] = Field(
..., description="The title of the book."
)
def call(self) -> str:
if self.title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif self.title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import openai
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import anthropic
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import mistral
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import google
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import groq
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import cohere
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import litellm
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import azure
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import bedrock
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import Messages, openai
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import Messages, anthropic
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import Messages, mistral
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import Messages, google
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import Messages, groq
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import Messages, cohere
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import Messages, litellm
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import Messages, azure
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import Messages, bedrock
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import openai, prompt_template
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import anthropic, prompt_template
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import mistral, prompt_template
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import google, prompt_template
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import groq, prompt_template
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import cohere, prompt_template
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import litellm, prompt_template
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import azure, prompt_template
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import bedrock, prompt_template
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, openai
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, anthropic
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, mistral
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, google
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, groq
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, cohere
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, litellm
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, azure
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
from typing import Annotated
from mirascope.core import BaseMessageParam, bedrock
from pydantic import AfterValidator, ValidationError
def is_upper(v: str) -> str:
assert v.isupper(), "Must be uppercase"
return v
def get_book_author(title: Annotated[str, AfterValidator(is_upper)]) -> str:
"""Returns the author of the book with the given title
Args:
title: The title of the book.
"""
if title == "THE NAME OF THE WIND":
return "Patrick Rothfuss"
elif title == "MISTBORN: THE FINAL EMPIRE":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
try:
if tool := response.tool:
print(tool.call())
else:
print(response.content)
except ValidationError as e:
print(e)
# > 1 validation error for GetBookAuthor
# title
# Assertion failed, Must be uppercase [type=assertion_error, input_value='The Name of the Wind', input_type=str]
# For further information visit https://errors.pydantic.dev/2.8/v/assertion_error
In this example we've added additional validation, but it's important that you still handle ValidationError
's even with standard tools since they are still BaseModel
instances and will validate the field types regardless.
Few-Shot Examples¶
Just like with Response Models, you can add few-shot examples to your tools:
from mirascope.core import BaseTool, openai
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, anthropic
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, mistral
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, google
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, groq
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, cohere
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, litellm
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, azure
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, bedrock
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, openai
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, anthropic
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, mistral
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, google
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, groq
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, cohere
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, litellm
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, azure
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, Messages, bedrock
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, openai, prompt_template
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, anthropic, prompt_template
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, mistral, prompt_template
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, google, prompt_template
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, groq, prompt_template
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, cohere, prompt_template
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, litellm, prompt_template
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, azure, prompt_template
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseTool, bedrock, prompt_template
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, openai
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, anthropic
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, mistral
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, google
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, groq
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, cohere
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, litellm
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, azure
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, BaseTool, bedrock
from pydantic import ConfigDict, Field
class GetBookAuthor(BaseTool):
"""Returns the author of the book with the given title."""
title: str = Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
)
model_config = ConfigDict(
json_schema_extra={"examples": [{"title": "The Name of the Wind"}]}
)
def call(self) -> str:
if self.title == "The Name of the Wind":
return "Patrick Rothfuss"
elif self.title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[GetBookAuthor])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import openai
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import anthropic
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import mistral
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import groq
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import cohere
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import litellm
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import azure
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import bedrock
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(book: str) -> str:
return f"Who wrote {book}?"
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import Messages, openai
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import Messages, anthropic
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import Messages, mistral
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import Messages, google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import Messages, groq
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import Messages, cohere
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import Messages, litellm
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import Messages, azure
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import Messages, bedrock
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(book: str) -> Messages.Type:
return Messages.User(f"Who wrote {book}?")
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import openai, prompt_template
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import anthropic, prompt_template
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import mistral, prompt_template
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import google, prompt_template
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import groq, prompt_template
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import cohere, prompt_template
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import litellm, prompt_template
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import azure, prompt_template
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import bedrock, prompt_template
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
@prompt_template("Who wrote {book}?")
def identify_author(book: str): ...
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import BaseMessageParam, openai
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@openai.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import BaseMessageParam, anthropic
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@anthropic.call("claude-3-5-sonnet-20240620", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import BaseMessageParam, mistral
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@mistral.call("mistral-large-latest", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from mirascope.core import BaseMessageParam, google
def get_book_author(title: str) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@google.call("gemini-1.5-flash", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import BaseMessageParam, groq
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@groq.call("llama-3.1-70b-versatile", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import BaseMessageParam, cohere
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@cohere.call("command-r-plus", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import BaseMessageParam, litellm
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@litellm.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import BaseMessageParam, azure
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@azure.call("gpt-4o-mini", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
from typing import Annotated
from pydantic import Field
from mirascope.core import BaseMessageParam, bedrock
def get_book_author(
title: Annotated[
str,
Field(
...,
description="The title of the book.",
examples=["The Name of the Wind"],
),
],
) -> str:
"""Returns the author of the book with the given title
Example:
{"title": "The Name of the Wind"}
Args:
title: The title of the book.
"""
if title == "The Name of the Wind":
return "Patrick Rothfuss"
elif title == "Mistborn: The Final Empire":
return "Brandon Sanderson"
else:
return "Unknown"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[get_book_author])
def identify_author(book: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Who wrote {book}?")]
response = identify_author("The Name of the Wind")
if tool := response.tool:
print(tool.call())
else:
print(response.content)
Both approaches will result in the same tool schema with examples included. The function approach gets automatically converted to use Pydantic fields internally, making both methods equivalent in terms of functionality.
Field level examples in both styles
Both BaseTool
and function-style definitions support field level examples through Pydantic's Field
. When using function-style definitions, you'll need to wrap the type with Annotated
to use Field
.
ToolKit¶
API Documentation
The BaseToolKit
class enables:
- Organiziation of a group of tools under a single namespace.
- This can be useful for making it clear to the LLM when to use certain tools over others. For example, you could namespace a set of tools under "file_system" to indicate that those tools are specifically for interacting with the file system.
- Dynamic tool definitions.
- This can be useful for generating tool definitions that are dependent on some input or state. For example, you may want to update the description of tools based on an argument of the call being made.
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
openai,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@openai.call("gpt-4o-mini")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
anthropic,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@anthropic.call("claude-3-5-sonnet-20240620")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
mistral,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@mistral.call("mistral-large-latest")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
google,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
"""
return f"I would suggest you read some books by {author}"
@google.call("gemini-1.5-flash")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
groq,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@groq.call("llama-3.1-70b-versatile")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
cohere,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@cohere.call("command-r-plus")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
litellm,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@litellm.call("gpt-4o-mini")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
azure,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@azure.call("gpt-4o-mini")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
bedrock,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
openai,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@openai.call("gpt-4o-mini")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
anthropic,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@anthropic.call("claude-3-5-sonnet-20240620")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
mistral,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@mistral.call("mistral-large-latest")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
google,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
"""
return f"I would suggest you read some books by {author}"
@google.call("gemini-1.5-flash")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
groq,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@groq.call("llama-3.1-70b-versatile")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
cohere,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@cohere.call("command-r-plus")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
litellm,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@litellm.call("gpt-4o-mini")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
azure,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@azure.call("gpt-4o-mini")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
Messages,
bedrock,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [Messages.User(f"What {genre} author should I read?")],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
openai,
prompt_template,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@openai.call("gpt-4o-mini")
@prompt_template("What {genre} author should I read?")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {"tools": toolkit.create_tools()}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
anthropic,
prompt_template,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@anthropic.call("claude-3-5-sonnet-20240620")
@prompt_template("What {genre} author should I read?")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {"tools": toolkit.create_tools()}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
mistral,
prompt_template,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@mistral.call("mistral-large-latest")
@prompt_template("What {genre} author should I read?")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {"tools": toolkit.create_tools()}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
google,
prompt_template,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
"""
return f"I would suggest you read some books by {author}"
@google.call("gemini-1.5-flash")
@prompt_template("What {genre} author should I read?")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {"tools": toolkit.create_tools()}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
groq,
prompt_template,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@groq.call("llama-3.1-70b-versatile")
@prompt_template("What {genre} author should I read?")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {"tools": toolkit.create_tools()}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
cohere,
prompt_template,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@cohere.call("command-r-plus")
@prompt_template("What {genre} author should I read?")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {"tools": toolkit.create_tools()}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
litellm,
prompt_template,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@litellm.call("gpt-4o-mini")
@prompt_template("What {genre} author should I read?")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {"tools": toolkit.create_tools()}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
azure,
prompt_template,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@azure.call("gpt-4o-mini")
@prompt_template("What {genre} author should I read?")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {"tools": toolkit.create_tools()}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseToolKit,
bedrock,
prompt_template,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0")
@prompt_template("What {genre} author should I read?")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {"tools": toolkit.create_tools()}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseMessageParam,
BaseToolKit,
openai,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@openai.call("gpt-4o-mini")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [
BaseMessageParam(role="user", content=f"What {genre} author should I read?")
],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseMessageParam,
BaseToolKit,
anthropic,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@anthropic.call("claude-3-5-sonnet-20240620")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [
BaseMessageParam(role="user", content=f"What {genre} author should I read?")
],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseMessageParam,
BaseToolKit,
mistral,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@mistral.call("mistral-large-latest")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [
BaseMessageParam(role="user", content=f"What {genre} author should I read?")
],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseMessageParam,
BaseToolKit,
google,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
"""
return f"I would suggest you read some books by {author}"
@google.call("gemini-1.5-flash")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [
BaseMessageParam(role="user", content=f"What {genre} author should I read?")
],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseMessageParam,
BaseToolKit,
groq,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@groq.call("llama-3.1-70b-versatile")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [
BaseMessageParam(role="user", content=f"What {genre} author should I read?")
],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseMessageParam,
BaseToolKit,
cohere,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@cohere.call("command-r-plus")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [
BaseMessageParam(role="user", content=f"What {genre} author should I read?")
],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseMessageParam,
BaseToolKit,
litellm,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@litellm.call("gpt-4o-mini")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [
BaseMessageParam(role="user", content=f"What {genre} author should I read?")
],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseMessageParam,
BaseToolKit,
azure,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@azure.call("gpt-4o-mini")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [
BaseMessageParam(role="user", content=f"What {genre} author should I read?")
],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
from mirascope.core import (
BaseDynamicConfig,
BaseMessageParam,
BaseToolKit,
bedrock,
toolkit_tool,
)
class BookTools(BaseToolKit):
__namespace__ = "book_tools"
reading_level: str
@toolkit_tool
def suggest_author(self, author: str) -> str:
"""Suggests an author for the user to read based on their reading level.
User reading level: {self.reading_level}
Author you suggest must be appropriate for the user's reading level.
"""
return f"I would suggest you read some books by {author}"
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0")
def recommend_author(genre: str, reading_level: str) -> BaseDynamicConfig:
toolkit = BookTools(reading_level=reading_level)
return {
"tools": toolkit.create_tools(),
"messages": [
BaseMessageParam(role="user", content=f"What {genre} author should I read?")
],
}
response = recommend_author("fantasy", "beginner")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by J.K. Rowling
response = recommend_author("fantasy", "advanced")
if tool := response.tool:
print(tool.call())
# Output: I would suggest you read some books by Brandon Sanderson
In this example we:
- Create a
BookTools
toolkit - We set
__namespace__
equal to "book_tools" - We define the
reading_level
state of the toolkit - We define the
suggest_author
tool and mark it with@toolkit_tool
to identify the method as a tool of the toolkit - We use the
{self.reading_level}
template variable in the description of the tool. - We create the toolkit with the
reading_level
argument. - We call
create_tools
to generate the toolkit's tools. This will generate the tools on every call, ensuring that the description correctly includes the provided reading level. - We call
recommend_author
with a "beginner" reading level, and the LLM calls thesuggest_author
tool with its suggested author. - We call
recommend_author
again but with "advanced" reading level, and again the LLM calls thesuggest_author
tool with its suggested author.
The core concept to understand here is that the suggest_author
tool's description is dynamically generated on each call to recommend_author
through the toolkit.
This is why the "beginner" recommendation and "advanced" recommendations call the suggest_author
tool with authors befitting the reading level of each call.
Pre-Made Tools and ToolKits¶
Mirascope provides several pre-made tools and toolkits to help you get started quickly:
Dependencies Required
Pre-made tools and toolkits require installing the dependencies listed in the "Dependencies" column for each tool/toolkit.
For example:
Pre-Made Tools¶
API Documentation
Tool | Primary Use | Dependencies | Key Features | Characteristics |
---|---|---|---|---|
DuckDuckGoSearch |
Web Searching | duckduckgo-search |
• Multiple query support • Title/URL/snippet extraction • Result count control • Automated formatting |
• Privacy-focused search • Async support (AsyncDuckDuckGoSearch) • Automatic filtering • Structured results |
HTTPX |
Advanced HTTP Requests | httpx |
• Full HTTP method support (GET/POST/PUT/DELETE) • Custom header support • File upload/download • Form data handling |
• Async support (AsyncHTTPX) • Configurable timeouts • Comprehensive error handling • Redirect control |
ParseURLContent |
Web Content Extraction | beautifulsoup4 , httpx |
• HTML content fetching • Main content extraction • Element filtering • Text normalization |
• Automatic cleaning • Configurable parser • Timeout settings • Error handling |
Requests |
Simple HTTP Requests | requests |
• Basic HTTP methods • Simple API • Response text retrieval • Basic authentication |
• Minimal configuration • Intuitive interface • Basic error handling • Lightweight implementation |
Example using DuckDuckGoSearch:
from mirascope.core import openai
from mirascope.tools import DuckDuckGoSearch
@openai.call("gpt-4o-mini", tools=[DuckDuckGoSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import anthropic
from mirascope.tools import DuckDuckGoSearch
@anthropic.call("claude-3-5-sonnet-20240620", tools=[DuckDuckGoSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import mistral
from mirascope.tools import DuckDuckGoSearch
@mistral.call("mistral-large-latest", tools=[DuckDuckGoSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import google
from mirascope.tools import DuckDuckGoSearch
@google.call("gemini-1.5-flash", tools=[DuckDuckGoSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import groq
from mirascope.tools import DuckDuckGoSearch
@groq.call("llama-3.1-70b-versatile", tools=[DuckDuckGoSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import cohere
from mirascope.tools import DuckDuckGoSearch
@cohere.call("command-r-plus", tools=[DuckDuckGoSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import litellm
from mirascope.tools import DuckDuckGoSearch
@litellm.call("gpt-4o-mini", tools=[DuckDuckGoSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import bedrock
from mirascope.tools import DuckDuckGoSearch
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[DuckDuckGoSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import openai, Messages
from mirascope.tools import DuckDuckGoSearch
@openai.call("gpt-4o-mini", tools=[DuckDuckGoSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import anthropic, Messages
from mirascope.tools import DuckDuckGoSearch
@anthropic.call("claude-3-5-sonnet-20240620", tools=[DuckDuckGoSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import mistral, Messages
from mirascope.tools import DuckDuckGoSearch
@mistral.call("mistral-large-latest", tools=[DuckDuckGoSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import google, Messages
from mirascope.tools import DuckDuckGoSearch
@google.call("gemini-1.5-flash", tools=[DuckDuckGoSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import groq, Messages
from mirascope.tools import DuckDuckGoSearch
@groq.call("llama-3.1-70b-versatile", tools=[DuckDuckGoSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import cohere, Messages
from mirascope.tools import DuckDuckGoSearch
@cohere.call("command-r-plus", tools=[DuckDuckGoSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import litellm, Messages
from mirascope.tools import DuckDuckGoSearch
@litellm.call("gpt-4o-mini", tools=[DuckDuckGoSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import azure, Messages
from mirascope.tools import DuckDuckGoSearch
@azure.call("gpt-4o-mini", tools=[DuckDuckGoSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import bedrock, Messages
from mirascope.tools import DuckDuckGoSearch
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[DuckDuckGoSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import openai, prompt_template
from mirascope.tools import DuckDuckGoSearch
@openai.call("gpt-4o-mini", tools=[DuckDuckGoSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import anthropic, prompt_template
from mirascope.tools import DuckDuckGoSearch
@anthropic.call("claude-3-5-sonnet-20240620", tools=[DuckDuckGoSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import mistral, prompt_template
from mirascope.tools import DuckDuckGoSearch
@mistral.call("mistral-large-latest", tools=[DuckDuckGoSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import google, prompt_template
from mirascope.tools import DuckDuckGoSearch
@google.call("gemini-1.5-flash", tools=[DuckDuckGoSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import groq, prompt_template
from mirascope.tools import DuckDuckGoSearch
@groq.call("llama-3.1-70b-versatile", tools=[DuckDuckGoSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import cohere, prompt_template
from mirascope.tools import DuckDuckGoSearch
@cohere.call("command-r-plus", tools=[DuckDuckGoSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import litellm, prompt_template
from mirascope.tools import DuckDuckGoSearch
@litellm.call("gpt-4o-mini", tools=[DuckDuckGoSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import azure, prompt_template
from mirascope.tools import DuckDuckGoSearch
@azure.call("gpt-4o-mini", tools=[DuckDuckGoSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import bedrock, prompt_template
from mirascope.tools import DuckDuckGoSearch
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[DuckDuckGoSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import openai, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch
@openai.call("gpt-4o-mini", tools=[DuckDuckGoSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import anthropic, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch
@anthropic.call("claude-3-5-sonnet-20240620", tools=[DuckDuckGoSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import mistral, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch
@mistral.call("mistral-large-latest", tools=[DuckDuckGoSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import google, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch
@google.call("gemini-1.5-flash", tools=[DuckDuckGoSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import groq, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch
@groq.call("llama-3.1-70b-versatile", tools=[DuckDuckGoSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import cohere, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch
@cohere.call("command-r-plus", tools=[DuckDuckGoSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import litellm, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch
@litellm.call("gpt-4o-mini", tools=[DuckDuckGoSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import azure, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch
@azure.call("gpt-4o-mini", tools=[DuckDuckGoSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import bedrock, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[DuckDuckGoSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import openai
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@openai.call("gpt-4o-mini", tools=[CustomSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import anthropic
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@anthropic.call("claude-3-5-sonnet-20240620", tools=[CustomSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import mistral
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@mistral.call("mistral-large-latest", tools=[CustomSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import google
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@google.call("gemini-1.5-flash", tools=[CustomSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import groq
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@groq.call("llama-3.1-70b-versatile", tools=[CustomSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import cohere
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@cohere.call("command-r-plus", tools=[CustomSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import litellm
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@litellm.call("gpt-4o-mini", tools=[CustomSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import azure
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@azure.call("gpt-4o-mini", tools=[CustomSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import bedrock
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[CustomSearch])
def research(genre: str) -> str:
return f"Recommend a {genre} book and summarize the story"
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import openai, Messages
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@openai.call("gpt-4o-mini", tools=[CustomSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import anthropic, Messages
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@anthropic.call("claude-3-5-sonnet-20240620", tools=[CustomSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import mistral, Messages
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@mistral.call("mistral-large-latest", tools=[CustomSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import google, Messages
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@google.call("gemini-1.5-flash", tools=[CustomSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import groq, Messages
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@groq.call("llama-3.1-70b-versatile", tools=[CustomSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import cohere, Messages
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@cohere.call("command-r-plus", tools=[CustomSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import litellm, Messages
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@litellm.call("gpt-4o-mini", tools=[CustomSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import azure, Messages
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@azure.call("gpt-4o-mini", tools=[CustomSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import bedrock, Messages
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[CustomSearch])
def research(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book and summarize the story")
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import openai, prompt_template
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@openai.call("gpt-4o-mini", tools=[CustomSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import anthropic, prompt_template
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@anthropic.call("claude-3-5-sonnet-20240620", tools=[CustomSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import mistral, prompt_template
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@mistral.call("mistral-large-latest", tools=[CustomSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import google, prompt_template
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@google.call("gemini-1.5-flash", tools=[CustomSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import groq, prompt_template
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@groq.call("llama-3.1-70b-versatile", tools=[CustomSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import cohere, prompt_template
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@cohere.call("command-r-plus", tools=[CustomSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import litellm, prompt_template
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@litellm.call("gpt-4o-mini", tools=[CustomSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import azure, prompt_template
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@azure.call("gpt-4o-mini", tools=[CustomSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import bedrock, prompt_template
from mirascope.tools import DuckDuckGoSearch
from mirascope.tools import DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[CustomSearch])
@prompt_template("Recommend a {genre} book and summarize the story")
def research(genre: str): ...
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import openai, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@openai.call("gpt-4o-mini", tools=[CustomSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import anthropic, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@anthropic.call("claude-3-5-sonnet-20240620", tools=[CustomSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import mistral, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@mistral.call("mistral-large-latest", tools=[CustomSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import google, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@google.call("gemini-1.5-flash", tools=[CustomSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import groq, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@groq.call("llama-3.1-70b-versatile", tools=[CustomSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import cohere, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@cohere.call("command-r-plus", tools=[CustomSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import litellm, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@litellm.call("gpt-4o-mini", tools=[CustomSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import azure, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@azure.call("gpt-4o-mini", tools=[CustomSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
from mirascope.core import bedrock, BaseMessageParam
from mirascope.tools import DuckDuckGoSearch, DuckDuckGoSearchConfig
config = DuckDuckGoSearchConfig(max_results_per_query=5)
CustomSearch = DuckDuckGoSearch.from_config(config)
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0", tools=[CustomSearch])
def research(genre: str) -> list[BaseMessageParam]:
return [
BaseMessageParam(
role="user", content=f"Recommend a {genre} book and summarize the story"
)
]
response = research("fantasy")
if tool := response.tool:
print(tool.call())
Pre-Made ToolKits¶
API Documentation
ToolKit | Primary Use | Dependencies | Tools and Features | Characteristics |
---|---|---|---|---|
FileSystemToolKit |
File System Operations | None | • ReadFile: File content reading • WriteFile: Content writing • ListDirectory: Directory listing • CreateDirectory: Directory creation • DeleteFile: File deletion |
• Path traversal protection • File size limits • Extension validation • Robust error handling • Base directory isolation |
DockerOperationToolKit |
Code & Command Execution | docker , docker engine |
• ExecutePython: Python code execution with optional package installation • ExecuteShell: Shell command execution |
• Docker container isolation • Memory limits • Network control • Security restrictions • Resource cleanup |
Example using FileSystemToolKit:
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, openai
from mirascope.tools import FileSystemToolKit
@openai.call("gpt-4o-mini")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'."
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, anthropic
from mirascope.tools import FileSystemToolKit
@anthropic.call("claude-3-5-sonnet-20240620")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'."
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, mistral
from mirascope.tools import FileSystemToolKit
@mistral.call("mistral-large-latest")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'."
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, google
from mirascope.tools import FileSystemToolKit
@google.call("gemini-1.5-flash")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'."
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, groq
from mirascope.tools import FileSystemToolKit
@groq.call("llama-3.1-70b-versatile")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'."
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, cohere
from mirascope.tools import FileSystemToolKit
@cohere.call("command-r-plus")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'."
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, litellm
from mirascope.tools import FileSystemToolKit
@litellm.call("gpt-4o-mini")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'."
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, azure
from mirascope.tools import FileSystemToolKit
@azure.call("gpt-4o-mini")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'."
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, bedrock
from mirascope.tools import FileSystemToolKit
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'."
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, openai
from mirascope.tools import FileSystemToolKit
@openai.call("gpt-4o-mini")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, anthropic
from mirascope.tools import FileSystemToolKit
@anthropic.call("claude-3-5-sonnet-20240620")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, mistral
from mirascope.tools import FileSystemToolKit
@mistral.call("mistral-large-latest")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, google
from mirascope.tools import FileSystemToolKit
@google.call("gemini-1.5-flash")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, groq
from mirascope.tools import FileSystemToolKit
@groq.call("llama-3.1-70b-versatile")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, cohere
from mirascope.tools import FileSystemToolKit
@cohere.call("command-r-plus")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, litellm
from mirascope.tools import FileSystemToolKit
@litellm.call("gpt-4o-mini")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, azure
from mirascope.tools import FileSystemToolKit
@azure.call("gpt-4o-mini")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, Messages, bedrock
from mirascope.tools import FileSystemToolKit
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
Messages.User(
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, openai, prompt_template
from mirascope.tools import FileSystemToolKit
@openai.call("gpt-4o-mini")
@prompt_template("Write a blog post about '{topic}' as a '{output_file.name}'.")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, anthropic, prompt_template
from mirascope.tools import FileSystemToolKit
@anthropic.call("claude-3-5-sonnet-20240620")
@prompt_template("Write a blog post about '{topic}' as a '{output_file.name}'.")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, mistral, prompt_template
from mirascope.tools import FileSystemToolKit
@mistral.call("mistral-large-latest")
@prompt_template("Write a blog post about '{topic}' as a '{output_file.name}'.")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, google, prompt_template
from mirascope.tools import FileSystemToolKit
@google.call("gemini-1.5-flash")
@prompt_template("Write a blog post about '{topic}' as a '{output_file.name}'.")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, groq, prompt_template
from mirascope.tools import FileSystemToolKit
@groq.call("llama-3.1-70b-versatile")
@prompt_template("Write a blog post about '{topic}' as a '{output_file.name}'.")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, cohere, prompt_template
from mirascope.tools import FileSystemToolKit
@cohere.call("command-r-plus")
@prompt_template("Write a blog post about '{topic}' as a '{output_file.name}'.")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, litellm, prompt_template
from mirascope.tools import FileSystemToolKit
@litellm.call("gpt-4o-mini")
@prompt_template("Write a blog post about '{topic}' as a '{output_file.name}'.")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, azure, prompt_template
from mirascope.tools import FileSystemToolKit
@azure.call("gpt-4o-mini")
@prompt_template("Write a blog post about '{topic}' as a '{output_file.name}'.")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, bedrock, prompt_template
from mirascope.tools import FileSystemToolKit
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0")
@prompt_template("Write a blog post about '{topic}' as a '{output_file.name}'.")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, BaseMessageParam, openai
from mirascope.tools import FileSystemToolKit
@openai.call("gpt-4o-mini")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
BaseMessageParam(
role="user",
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, BaseMessageParam, anthropic
from mirascope.tools import FileSystemToolKit
@anthropic.call("claude-3-5-sonnet-20240620")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
BaseMessageParam(
role="user",
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, BaseMessageParam, mistral
from mirascope.tools import FileSystemToolKit
@mistral.call("mistral-large-latest")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
BaseMessageParam(
role="user",
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, BaseMessageParam, google
from mirascope.tools import FileSystemToolKit
@google.call("gemini-1.5-flash")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
BaseMessageParam(
role="user",
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, BaseMessageParam, groq
from mirascope.tools import FileSystemToolKit
@groq.call("llama-3.1-70b-versatile")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
BaseMessageParam(
role="user",
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, BaseMessageParam, cohere
from mirascope.tools import FileSystemToolKit
@cohere.call("command-r-plus")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
BaseMessageParam(
role="user",
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, BaseMessageParam, litellm
from mirascope.tools import FileSystemToolKit
@litellm.call("gpt-4o-mini")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
BaseMessageParam(
role="user",
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, BaseMessageParam, azure
from mirascope.tools import FileSystemToolKit
@azure.call("gpt-4o-mini")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
BaseMessageParam(
role="user",
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
from pathlib import Path
from mirascope.core import BaseDynamicConfig, BaseMessageParam, bedrock
from mirascope.tools import FileSystemToolKit
@bedrock.call("anthropic.claude-3-haiku-20240307-v1:0")
def write_blog_post(topic: str, output_file: Path) -> BaseDynamicConfig:
toolkit = FileSystemToolKit(base_directory=output_file.parent)
return {
"messages": [
BaseMessageParam(
role="user",
content=f"Write a blog post about '{topic}' as a '{output_file.name}'.",
)
],
"tools": toolkit.create_tools(),
}
response = write_blog_post("machine learning", Path("introduction.html"))
if tool := response.tool:
result = tool.call()
print(result)
Next Steps¶
Tools can significantly extend LLM capabilities, enabling more interactive and dynamic applications. We encourage you to explore and experiment with tools to enhance your projects and the find the best fit for your specific needs.
Mirascope hopes to provide a simple and clean interface that is both easy to learn and easy to use; however, we understand that LLM tools can be a difficult concept regardless of the supporting tooling.
Join our community and ask us any questions you might have, we're here to help!
Next, we recommend learning about how to build Agents that take advantage of these tools.