Instrumenting your DSPy application with Parea AI
nn.Module
),trace_dspy
to trace the execution of your DSPy modules.
TurnOffPareaLogging
context manager.
After optimization, you will likely want to assess the performance of your module as outlined below.
contextvars
.
That means, if you are using threading or multi-processing in your DSPy application, the traces of the DSPy modules in that get orphaned from the main trace.
There is an existing issue in Python’s standard library and a great explanation in the FastAPI repo that discusses this limitation.
To avoid this, you need to manually copy over the context to the new thread/process via contextvars.copy_context()
.
See the below example:
Threading & Multi-processing in Python
attach_evals_to_module
) and convert the DSPy examples to dictionaries (convert_dspy_examples_to_parea_dicts
).
attach_evals_to_module
.
This will automatically apply your list of evals to the module whenever you call it. See the example below for more details.
Example: Attach Evaluation to Module