Function Calling
Function Calling
llama_cpp_agent.function_calling
get_enum_type(enum)
Determine the JSON schema type for an enum based on its members.
Source code in llama_cpp_agent/function_calling.py
get_openai_type(py_type)
Map Python types to JSON schema types and handle special cases like Enums, Lists, and Unions.
Source code in llama_cpp_agent/function_calling.py
LlamaCppFunctionTool
Callable class representing a tool for handling function calls in the LlamaCpp environment.
Parameters:
-
function_tool(Union[Type[BaseModel], Callable, Tuple[Dict[str, Any], Callable]]) –The function tool, can be either a pydantic model with run method, a python function or a tuple of a OpenAI tool specification and a function as callback.
-
has_markdown_code_block(bool, default:False) –Flag indicating whether the response contains an extra markdown code block field.
-
has_triple_quoted_string(bool, default:False) –Flag indicating whether the response contains an extra triple-quoted string field.
-
**additional_parameters–Additional parameters to pass to the Pydantic model during function call.
Attributes:
-
model(Type[BaseModel]) –The Pydantic model representing the function parameters.
-
look_for_field_string(bool) –Flag indicating whether to look for a field string in the response.
-
has_markdown_code_block(bool) –Flag indicating whether the response contains a markdown code block.
-
has_triple_quoted_string(bool) –Flag indicating whether the response contains a triple-quoted string.
-
additional_parameters(dict) –Additional parameters to pass to the Pydantic model during function call.
Methods:
-
__call__–Calls the Pydantic model with the provided keyword arguments.
Source code in llama_cpp_agent/function_calling.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
from_pydantic_model_and_callable(pydantic_model, tool_function)
staticmethod
Converts an OpenAI tool schema and a callable function into a LlamaCppFunctionTool Args: pydantic_model(BaseModel): Pydantic Model representing the arguments to the tool. tool_function(Callable): Callable function that will be invoked when the agent uses it and will be passed the fields of the pydantic model.
Returns:
-
LlamaCppFunctionTool–The LlamaCppFunctionTool instance.
Source code in llama_cpp_agent/function_calling.py
from_openai_tool(openai_tool_schema, tool_function)
staticmethod
Converts an OpenAI tool schema and a callable function into a LlamaCppFunctionTool Args: openai_tool_schema(dict): OpenAI tool description dictionary. tool_function(Callable): Callable function that will be invoked when the agent uses it.
Returns:
-
LlamaCppFunctionTool–The LlamaCppFunctionTool instance.
Source code in llama_cpp_agent/function_calling.py
from_llama_index_tool(llama_index_tool)
staticmethod
Converts a llama-index tool into a LlamaCppFunctionTool Args: llama_index_tool(["BaseTool"]): OpenAI tool description dictionary.
Returns:
-
LlamaCppFunctionTool–The LlamaCppFunctionTool instance.
Source code in llama_cpp_agent/function_calling.py
__call__(*args, **kwargs)
Calls the Pydantic model with the provided keyword arguments.
Returns:
-
BaseModel–An instance of the Pydantic model.