Skip to content

Instantly share code, notes, and snippets.

@heathermiller
Created January 11, 2024 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heathermiller/27f656ef3d0aab34a0e27e7061e81bef to your computer and use it in GitHub Desktop.
Save heathermiller/27f656ef3d0aab34a0e27e7061e81bef to your computer and use it in GitHub Desktop.
DSPy 2
# Define the predictor. Notice we're just changing the class. The signature BasicQA is unchanged.
generate_answer_with_chain_of_thought = dspy.ChainOfThought(BasicQA)
# Call the predictor on the same input.
pred = generate_answer_with_chain_of_thought(question=dev_example.question)
# Print the input, the chain of thought, and the prediction.
print(f"Question: {dev_example.question}")
print(f"Thought: {pred.rationale.split('.', 1)[1].strip()}")
print(f"Predicted Answer: {pred.answer}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment