Created
March 2, 2024 10:13
-
-
Save fsndzomga/2b55ae7a4702346f4be99a1d41013cbe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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