Functions
FUNC create_response_format
func: A function with exactly one argument
- A Pydantic model class that inherits from FunctionResponse[T]
FUNC describe_function
func: Callable function that needs to be passed to generative slot.
- Function dict of the passed function.
FUNC get_argument
func: Callable Functionkey: Arg keyval: Arg value
- an argument object representing the given parameter.
FUNC bind_function_arguments
func: The function to bind arguments for.*args: Positional arguments to bind.**kwargs: Keyword arguments to bind.
- Dictionary mapping parameter names to bound values with defaults applied.
FUNC generative
- Works with async functions as well.
- Must pass all parameters for the original function as keyword args.
- Most python type-hinters will not show the default values but will correctly infer them; this means that you can set default values in the decorated function and the only necessary values will be a session or a (context, backend).
func: Function with docstring and type hints. Implementation can be empty (…).
- An AI-powered function that generates responses using an LLM based on the
- original function’s signature and docstring.
ValueError: (raised by @generative) if the decorated function has a parameter name used by generative slotsValidationError: (raised when calling the generative slot) if the generated output cannot be parsed into the expected return type. Typically happens when the token limit for the generated output results in invalid json.TypeError: (raised when calling the generative slot) if any of the original function’s parameters were passed as positional argsPreconditionException: (raised when calling the generative slot) if the precondition validation of the args fails; catch the exception to get the validation results
Classes
CLASS FunctionResponse
Generic base class for function response formats.
CLASS FunctionDict
Return Type for a Function Component.
CLASS ArgumentDict
Return Type for a Argument Component.
CLASS Argument
An Argument.
CLASS Arguments
CLASS ArgPreconditionRequirement
Specific requirement with template for validating precondition requirements against a set of args.
CLASS PreconditionException
Exception raised when validation fails for a generative slot’s arguments.
CLASS Function
A Function.
CLASS ExtractedArgs
Used to extract the mellea args and original function args. See @generative decorator for additional notes on these fields.
These args must match those allowed by any overload of GenerativeSlot.call.
CLASS GenerativeSlot
A generative slot component.
Methods:
FUNC extract_args_and_kwargs
- a dataclass of the required args for mellea and the original function.
- Either session or (backend, context) will be non-None.
TypeError: if any of the original function’s parameters were passed as positional args