Skip to content

Instantly share code, notes, and snippets.

@fsndzomga
Last active January 28, 2024 01:14
Show Gist options
  • Save fsndzomga/cce11170d9a3f23c9ccc38e72c2a41de to your computer and use it in GitHub Desktop.
Save fsndzomga/cce11170d9a3f23c9ccc38e72c2a41de to your computer and use it in GitHub Desktop.
from dspy.teleprompt import BootstrapFewShot
from dspy.evaluate import answer_exact_match
text = "Barack Obama was not President of the USA"
# define the fact as input to the lie detector
trainset = [x.with_inputs('fact') for x in few_shot_examples]
# define the signature to be used in by the lie detector module
# for the evaluation, you need to define an answer field
class Veracity(dspy.Signature):
"Evaluate the veracity of a statement"
fact = dspy.InputField(desc="a statement")
answer = dspy.OutputField(desc="an assessment of the veracity of the statement")
class lie_detector(dspy.Module):
def __init__(self):
super().__init__()
self.lie_identification = dspy.ChainOfThought(Veracity)
def forward(self, fact):
return self.lie_identification(fact=fact)
teleprompter = BootstrapFewShot(metric=answer_exact_match)
compiled_lie_detector = teleprompter.compile(lie_detector(), trainset=trainset)
response = compiled_lie_detector(fact=text)
print(f"veracity {response.answer}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment