base.utils¶
Base utility functions.
convert_base_model_to_tool(schema, base)
¶
Converts a BaseModel
schema to a BaseToolT
type.
By adding a docstring (if needed) and passing on fields and field information in
dictionary format, a Pydantic BaseModel
can be converted into an BaseToolT
for
performing extraction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema |
Type[BaseModel]
|
The |
required |
Returns:
Type | Description |
---|---|
Type[BaseToolT]
|
The constructed |
Source code in mirascope/base/utils.py
convert_base_type_to_tool(schema, base)
¶
Converts a BaseType
to a BaseToolT
type.
Source code in mirascope/base/utils.py
convert_function_to_tool(fn, base)
¶
Constructs a BaseToolT
type from the given function.
This method expects all function parameters to be properly documented in identical order with identical variable names, as well as descriptions of each parameter. Errors will be raised if any of these conditions are not met.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
Callable
|
The function to convert. |
required |
Returns:
Type | Description |
---|---|
Type[BaseToolT]
|
The constructed |
Raises:
Type | Description |
---|---|
ValueError
|
if the given function doesn't have a docstring. |
ValueError
|
if the given function's parameters don't have type annotations. |
ValueError
|
if a given function's parameter is in the docstring args section but the name doesn't match the docstring's parameter name. |
ValueError
|
if a given function's parameter is in the docstring args section but doesn't have a dosctring description. |
Source code in mirascope/base/utils.py
retry(fn)
¶
Decorator for retrying a function.
Source code in mirascope/base/utils.py
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 |
|
tool_fn(fn)
¶
A decorator for adding a function to a tool class.
Adding this decorator will add an fn
property to the tool class that returns the
function that the tool describes. This is convenient for calling the function given
an instance of the tool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
Callable
|
The function to add to the tool class. |
required |
Returns:
Type | Description |
---|---|
Callable[[Type[BaseToolT]], Type[BaseToolT]]
|
The decorated tool class. |