Skip to content

Instantly share code, notes, and snippets.

View john-adeojo's full-sized avatar

John Adeojo john-adeojo

View GitHub Profile
class Analogy(dspy.Signature):
"""Generate a distinct, analogous question from the initial question"""
question = dspy.InputField(desc="Initial question")
analogy = dspy.OutputField(desc="Generate a distinct analogous question based on initial question")
class ExampleQuestionAnswer(dspy.Signature):
"""Generate an answer to the analogous question"""
question = dspy.InputField(desc="The analogous question")
answer = dspy.OutputField(desc="Answer the analogous question")
class ChainOfThoughtHint(dspy.Module):
def __init__(self):
super().__init__()
# define modules
self.predict = dspy.ChainOfThoughtWithHint('question -> answer')
def forward(self, question):
# Declare program to execute
return self.predict(question=question)
class ChainOfThoughtProg(dspy.Module):
def __init__(self):
super().__init__()
# define modules
self.predict = dspy.ChainOfThought('question -> answer')
def forward(self, question):
# Declare program to execute
return self.predict(question=question)
class Baseline(dspy.Module):
def __init__(self):
super().__init__()
# define modules
self.predict = dspy.Predict('question -> answer')
def forward(self, question):
# Declare program to execute
return self.predict(question=question)
Given the fields `question`, produce the fields `answer`.
---
Follow the following format.
Question: ${question}
Reasoning: Let's think step by step in order to ${produce the answer}. We ...
Answer: ${answer}
Select the best candidate response
---
Question: Oliver had $9, then he saved $5 from his allowance and spent $4 on a frisbee and $3 on a puzzle. His friend gives him another $8 as it's his birthday. How much money does Oliver have left?
Answer: 15
---
Follow the following format.
Select the best candidate response
---
Follow the following format.
Question: Initial question
Context: The candidate answers
Answer: Use the candidate answers to generate a response to the initial question
Given the fields `question`, produce the fields `answer`.
---
Follow the following format.
Question: ${question}
Reasoning: Let's think step by step in order to ${produce the answer}. We ...
Answer: ${answer}
Select the best candidate response
---
Question: Oliver had $9, then he saved $5 from his allowance and spent $4 on a frisbee and $3 on a puzzle. His friend gives him another $8 as it's his birthday. How much money does Oliver have left?
Answer: 15
---
Follow the following format.
Select the best candidate response
---
Follow the following format.
Question: Initial question
Context: The candidate answers
Answer: Use the candidate answers to generate a response to the initial question