DSPy
DSPy is the framework for programming—rather than prompting—language models.
Opik integrates with DSPy to log traces for all DSPy calls.
Getting started
First, ensure you have both opik
and dspy
installed:
pip install opik dspy
In addition, you can configure Opik using the opik configure
command which will prompt you for the correct local server address or if you are using the Cloud platfrom your API key:
opik configure
Logging DSPy calls
To log a DSPy pipeline run, you can use the OpikCallback
. This callback will log each DSPy run to Opik:
import dspy
from opik.integrations.dspy.callback import OpikCallback
project_name = "DSPY"
lm = dspy.LM(
model="openai/gpt-4o-mini",
)
dspy.configure(lm=lm)
opik_callback = OpikCallback(project_name=project_name)
dspy.settings.configure(
callbacks=[opik_callback],
)
cot = dspy.ChainOfThought("question -> answer")
cot(question="What is the meaning of life?")
Each run will now be logged to the Opik platform: