Tools
Note
This class is still in an early experimental stage.
This section documents the Tool class.
prompt_templates.tools
Tool
A standardized tool that can be converted to various agent framework formats.
Source code in prompt_templates/tools.py
__call__
Make the tool directly callable with the function's arguments.
This method allows you to use the tool instance directly as a function, passing through any arguments to the underlying function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
Any
|
Positional arguments to pass to the function |
()
|
**kwargs |
Any
|
Keyword arguments to pass to the function |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The result of calling the underlying function |
Examples:
Note that the output here always depends on the specific tool function you load.
>>> from prompt_templates import ToolLoader
>>> tool = ToolLoader.from_hub(repo_id="MoritzLaurer/example_tools", filename="get_stock_price.py")
>>> result = tool(ticker="AAPL", days="5d")
>>> # This specific tool always returns a dictionary with the following keys
>>> isinstance(result, dict)
True
>>> sorted(result.keys())
['currency', 'prices', 'timestamps']
>>> result['currency']
'USD'
Source code in prompt_templates/tools.py
return_uninstalled_dependencies
Check if all required dependencies are installed.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: List of uninstalled dependencies that need to be installed for the function to work. |
Examples:
Check if there are any uninstalled dependencies:
>>> from prompt_templates import ToolLoader
>>> tool = ToolLoader.from_hub(repo_id="MoritzLaurer/example_tools", filename="get_stock_price.py")
>>> uninstalled = tool.return_uninstalled_dependencies()
>>> if uninstalled:
... print(f"Please install these packages: {uninstalled}")
Source code in prompt_templates/tools.py
to_openai_function
Convert to OpenAI function format.