ToolManager
This module contains the tool manager.
The tool manager is used to manage the toold that can be called by the bot.
Define a function using the OpenAITool model from models.py and add it to the tool manager using the add_tool method.
The tool should return a string.
The tool can optionally take keyword arguments, the keyword arguments should be defined in the OpenAITool model.
Call the tool using the call_function method for synchronous functions or the async_call_function method for asynchronous.
OpenAIToolMapping
dataclass
¶
OpenAI tool mapping
This class represents an OpenAI tool mapping.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool_definition
|
OpenAITool
|
The description of the tool |
required |
function
|
Callable
|
The function to call |
required |
Source code in src/simple_openai/tool_manager.py
20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
ToolManager
¶
Tool manager
This class manages the tools that can be called by the bot.
Source code in src/simple_openai/tool_manager.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
add_tool(tool_definition, function)
¶
Add a tool to the tool manager
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool_definition
|
OpenAITool
|
The tool definition |
required |
function
|
Callable
|
The function to call |
required |
Source code in src/simple_openai/tool_manager.py
44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
async_call_function(function_name, **kwargs)
async
¶
Call a function
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function_name
|
str
|
The name of the function to call |
required |
**kwargs
|
dict[str, Any]
|
The keyword arguments to pass to the function |
{}
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The result of the function |
Source code in src/simple_openai/tool_manager.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
call_function(function_name, **kwargs)
¶
Call a function
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function_name
|
str
|
The name of the function to call |
required |
**kwargs
|
dict[str, Any]
|
The keyword arguments to pass to the function |
{}
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The result of the function |
Source code in src/simple_openai/tool_manager.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
get_json_tool_list()
¶
Get the list of tools
Returns:
Type | Description |
---|---|
list[OpenAITool] | None
|
list[open_ai_models.OpenAITool] | None: The list of tools or None if there are no tools |
Source code in src/simple_openai/tool_manager.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|