marvin.utilities.python
PythonFunction
¶
A Pydantic model representing a Python function.
Attributes:
Name | Type | Description |
---|---|---|
function |
Callable
|
The original function object. |
signature |
Signature
|
The signature object of the function. |
name |
str
|
The name of the function. |
docstring |
Optional[str]
|
The docstring of the function. |
parameters |
List[ParameterModel]
|
The parameters of the function. |
return_annotation |
Optional[Any]
|
The return annotation of the function. |
source_code |
str
|
The source code of the function. |
bound_parameters |
dict[str, Any]
|
The parameters of the function bound with values. |
return_value |
Optional[Any]
|
The return value of the function call. |
from_function
classmethod
¶
Create a PythonFunction instance from a function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable
|
The function to create a PythonFunction instance from. |
required |
**kwargs
|
Additional keyword arguments to set as attributes on the PythonFunction instance. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
PythonFunction |
PythonFunction
|
The created PythonFunction instance. |
from_function_call
classmethod
¶
Create a PythonFunction instance from a function call.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable
|
The function to call. |
required |
*args
|
Positional arguments to pass to the function call. |
()
|
|
**kwargs
|
Keyword arguments to pass to the function call. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
PythonFunction |
PythonFunction
|
The created PythonFunction instance, with the return value of the function call set as an attribute. |