Decorators
decorators.Generation
Generation utilities for decorators for automatic logging and instrumentation of functions and methods.
current_generation
Get the current generation from the context variable.
Returns:
Name | Description |
---|---|
Optional[[Generation](/sdk/python/references/logger/components/generation)] | The current generation instance if one exists, |
otherwise None.
generation
Decorator for tracking AI model generations with Maxim logging.
This decorator wraps functions to automatically create and manage Generation objects for tracking AI model calls, including inputs, outputs, and metadata. The decorated function must be called within a @trace or @span decorated context.
Arguments:
Name | Type | Description |
---|---|---|
logger | Optional[Logger] | Maxim logger instance. If None, uses the current |
logger from context.
id
Optional[Union[Callable, str]] - Generation ID. Can be a string or a callable that returns a string. If None, generates a UUID.name
Optional[str] - Human-readable name for the generation.maxim_prompt_id
Optional[str] - ID of the Maxim prompt template used.tags
Optional[Dict[str, str]] - Key-value pairs for tagging the generation.evaluators
Optional[List[str]] - List of evaluator names to run on this generation.evaluator_variables
Optional[Dict[str, str]] - Variables to pass to evaluators.
Returns:
Name | Description |
---|---|
Callable | The decorator function that wraps the target function. |
Raises:
ValueError
- If no logger is found or if called outside of a trace/span context when raise_exceptions is True.
Example: