mirascope.core.base.toolkit
Module toolkit
The module for defining the toolkit class for LLM call tools.
Usage
Attribute P
Type: ParamSpec('P')
Function is_toolkit_tool
Returns
Type | Description |
---|---|
bool | - |
Class ToolKitToolMethod
Bases:
NamedTupleClass BaseToolKit
A class for defining tools for LLM call tools.
The class should have methods decorated with @toolkit_tool
to create tools.
Example:
from mirascope.core.base import BaseToolKit, toolkit_tool
from mirascope.core import openai
class BookRecommendationToolKit(BaseToolKit):
'''A toolkit for recommending books.'''
__namespace__: ClassVar[str | None] = 'book_tools'
reading_level: Literal["beginner", "advanced"]
@toolkit_tool
def format_book(self, title: str, author: str) -> str:
'''Returns the title and author of a book nicely formatted.
Reading level: {self.reading_level}
'''
return f"{title} by {author}"
@openai.call(model="gpt-4o")
def recommend_book(genre: str, reading_level: Literal["beginner", "advanced"]):
'''Recommend a {genre} book.'''
toolkit = BookRecommendationToolKit(reading_level=reading_level)
return {"tools": toolkit.create_tools()}
response = recommend_book("fantasy", "beginner")
if tool := response.tool:
output = tool.call()
print(output)
#> The Name of the Wind by Patrick Rothfuss
else:
print(response.content)
#> Sure! I would recommend...
Bases: BaseModel, ABC
Attributes
Name | Type | Description |
---|---|---|
model_config | ConfigDict(arbitrary_types_allowed=True) | - |
Function create_tools
The method to create the tools.
Parameters
Name | Type | Description |
---|---|---|
self | Any | - |
Function toolkit_tool
Parameters
Name | Type | Description |
---|---|---|
method | (_BaseToolKitT, P) => str | type[_BaseToolT] | - |
Returns
Type | Description |
---|---|
(_BaseToolKitT, P) => str | type[_BaseToolT] | - |