Forked from fsndzomga/synthetic-data-generation-dspy.py
Created
September 14, 2024 19:27
-
-
Save OctAg0nO/3e3d3755d27a30c44e8aba58aa2f64d6 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