Understanding Toolkits
In SmartGraph, a toolkit is a collection of functions that can be used by an AI assistant to perform specific tasks. Toolkits are based on the abstractToolkit
class and must implement certain methods and properties.
The Base Toolkit Class
Creating a Custom Toolkit
Let’s walk through creating a custom toolkit using the WeatherToolkit as an example:- Inherit from the
Toolkit
base class. - Implement the required properties:
name
,description
,functions
, andschemas
. - Define the functions that the toolkit will provide (e.g.,
get_temperature
). - Specify the schema for each function, including parameters and their types.
Using a Toolkit with CompletionComponent
Once you have created a custom toolkit, you can use it with a CompletionComponent to enhance your AI assistant’s capabilities. Here’s an example:- We create an instance of the
WeatherToolkit
. - We pass the toolkit to the
CompletionComponent
when initializing it. - The AI assistant can now use the functions provided by the WeatherToolkit to answer weather-related questions.
Best Practices for Creating and Using Toolkits
- Modularity: Design toolkits to be modular and focused on specific functionalities.
- Error Handling: Implement robust error handling in toolkit functions.
- Documentation: Provide clear descriptions for toolkit functions and their parameters.
- API Key Management: Use environment variables for sensitive information like API keys.
- Asynchronous Design: Make toolkit functions asynchronous when dealing with I/O operations.
- Testing: Create unit tests for your toolkit functions to ensure reliability.
- Versioning: Consider versioning your toolkits if you plan to make breaking changes.