OpikCallback¶
- class opik.integrations.dspy.OpikCallback(project_name: str | None = None)¶
Bases:
BaseCallback
- on_module_start(call_id: str, instance: Any, inputs: Dict[str, Any]) None ¶
A handler triggered when forward() method of a module (subclass of dspy.Module) is called.
- Parameters:
call_id – A unique identifier for the call. Can be used to connect start/end handlers.
instance – The Module instance.
inputs – The inputs to the module’s forward() method. Each arguments is stored as a key-value pair in a dictionary.
- on_module_end(call_id: str, outputs: Any | None, exception: Exception | None = None) None ¶
A handler triggered after forward() method of a module (subclass of dspy.Module) is executed.
- Parameters:
call_id – A unique identifier for the call. Can be used to connect start/end handlers.
outputs – The outputs of the module’s forward() method. If the method is interrupted by an exception, this will be None.
exception – If an exception is raised during the execution, it will be stored here.
- on_lm_start(call_id: str, instance: Any, inputs: Dict[str, Any]) None ¶
A handler triggered when __call__ method of dspy.LM instance is called.
- Parameters:
call_id – A unique identifier for the call. Can be used to connect start/end handlers.
instance – The LM instance.
inputs – The inputs to the LM’s __call__ method. Each arguments is stored as a key-value pair in a dictionary.
- on_lm_end(call_id: str, outputs: Dict[str, Any] | None, exception: Exception | None = None) None ¶
A handler triggered after __call__ method of dspy.LM instance is executed.
- Parameters:
call_id – A unique identifier for the call. Can be used to connect start/end handlers.
outputs – The outputs of the LM’s __call__ method. If the method is interrupted by an exception, this will be None.
exception – If an exception is raised during the execution, it will be stored here.
- flush() None ¶
Sends pending Opik data to the backend