Skip to main content
View module source on GitHub

current_generation

Get the current generation from the context variable. Returns: 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: 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: Raises:
  • ValueError - If no logger is found or if called outside of a trace/span context when raise_exceptions is True.
Example: