Predict is DSPy’s basic prompting module. Give it a signature describing input and output fields; once instantiated, it becomes a callable program that builds a prompt, calls a language model, and returns the requested outputs. section 2.2 section 3.3.2
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 question-answering program shows how to instantiate Predict with a signature and call it with an input. section 2.2
A Predict program can serve as a starting point for different tasks:
- For question answering, map a question to an answer. section 2.2
- For intent classification, pass a message and candidate labels, then receive an intent label. Calling the program for each test message requires a language-model call each time. section 3.3.2
Predict provides a baseline rather than optimizing the prompt by itself. Its modular interface makes it possible to change prompting techniques or language models without rewriting the surrounding application; account for call and token costs when running it over many inputs. section 2.2 section 3.3.2 section 1.2.1
