Skip to content

Instantly share code, notes, and snippets.

@fsndzomga
Created March 2, 2024 10:13
Show Gist options
  • Save fsndzomga/2b55ae7a4702346f4be99a1d41013cbe to your computer and use it in GitHub Desktop.
Save fsndzomga/2b55ae7a4702346f4be99a1d41013cbe 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