A DSPy program is an instantiated module that executes calls to a language model. Its signature defines input and output fields; the module turns that interface into a prompt and returns a Prediction. section 2.9 section 3.3.2
A program is defined by its language model, signature, and module; optimization can be added to improve it. These components can be changed independently, separating concerns. section 2.9 section 4.3
Question answering
A Predict program with the signature "question -> answer" takes a question and returns an answer in a Prediction object. section 2.2 section 2.9
Listing 2.2 Question-answering example
import dspy
OPENAI_API_KEY = . . .
lm = dspy.LM(model='gpt-4o-mini', api_key=OPENAI_API_KEY)
dspy.configure(lm=lm)
prog = dspy.Predict("question -> answer")
prediction = prog(question="What is the capital of France?")
print(prediction)
A minimal Python example configures a language model, creates a Predict program, calls it, and prints its prediction. section 2.2
Programs can also serve as baseline classifiers and be tested against individual examples or datasets. Calls made in loops or across a test set require attention to token use and cost. section 3.3.2 section 4.3
