Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save OctAg0nO/3e3d3755d27a30c44e8aba58aa2f64d6 to your computer and use it in GitHub Desktop.
Save OctAg0nO/3e3d3755d27a30c44e8aba58aa2f64d6 to your computer and use it in GitHub Desktop.
# Synthetic data generation using DSPy
from typing import List
import dspy
llm = dspy.OpenAI(model='gpt-3.5-turbo',api_key=openai_key)
dspy.settings.configure(lm=llm)
class FactGeneration(dspy.Signature):
"""Generate facts and their veracity"""
sindex = dspy.InputField(desc="a random string")
fact = dspy.OutputField(desc="a statement")
veracity = dspy.OutputField(desc="a boolean True or False")
fact_generator = dspy.Predict(FactGeneration, n=15)
response = fact_generator(sindex="1")
few_shot_examples: List[dspy.Example] = [
dspy.Example({'fact': fact, 'answer': veracity})
for fact, veracity in zip(response.completions.fact, response.completions.veracity)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment