97e91a83f3
Ruff / Ruff (push) Waiting to run
Test / Core Tests (push) Waiting to run
Test / Offline Coverage Tests (Python 3.10) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.11) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.12) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.13) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.9) (push) Waiting to run
Test / Full Coverage (Python 3.11) (push) Waiting to run
Test / Core Provider Tests (OpenAI) (push) Blocked by required conditions
Test / Core Provider Tests (Anthropic) (push) Blocked by required conditions
Test / Core Provider Tests (Google) (push) Blocked by required conditions
Test / Core Provider Tests (Other) (push) Blocked by required conditions
Test / Anthropic Tests (push) Blocked by required conditions
Test / Gemini Tests (push) Blocked by required conditions
Test / Google GenAI Tests (push) Blocked by required conditions
Test / Vertex AI Tests (push) Blocked by required conditions
Test / OpenAI Tests (push) Blocked by required conditions
Test / Writer Tests (push) Blocked by required conditions
Test / Auto Client Tests (push) Blocked by required conditions
ty / type-check (push) Waiting to run
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
import openai
|
|
import instructor
|
|
from collections.abc import Iterable
|
|
from pydantic import BaseModel, ConfigDict
|
|
|
|
client = instructor.from_openai(openai.OpenAI())
|
|
|
|
|
|
class SyntheticQA(BaseModel):
|
|
question: str
|
|
answer: str
|
|
|
|
model_config = ConfigDict(
|
|
json_schema_extra={
|
|
"examples": [
|
|
{"question": "What is the capital of France?", "answer": "Paris"},
|
|
{
|
|
"question": "What is the largest planet in our solar system?",
|
|
"answer": "Jupiter",
|
|
},
|
|
{
|
|
"question": "Who wrote 'To Kill a Mockingbird'?",
|
|
"answer": "Harper Lee",
|
|
},
|
|
{
|
|
"question": "What element does 'O' represent on the periodic table?",
|
|
"answer": "Oxygen",
|
|
},
|
|
]
|
|
}
|
|
)
|
|
|
|
|
|
def get_synthetic_data() -> Iterable[SyntheticQA]:
|
|
return client.chat.completions.create(
|
|
model="gpt-3.5-turbo",
|
|
messages=[
|
|
{"role": "system", "content": "Generate synthetic examples"},
|
|
{
|
|
"role": "user",
|
|
"content": "Generate the exact examples you see in the examples of this prompt. ",
|
|
},
|
|
],
|
|
response_model=Iterable[SyntheticQA],
|
|
) # type: ignore
|
|
|
|
|
|
if __name__ == "__main__":
|
|
for example in get_synthetic_data():
|
|
print(example)
|
|
"""
|
|
question='What is the capital of France?' answer='Paris'
|
|
question='What is the largest planet in our solar system?' answer='Jupiter'
|
|
question="Who wrote 'To Kill a Mockingbird'?" answer='Harper Lee'
|
|
question="What element does 'O' represent on the periodic table?" answer='Oxygen'
|
|
"""
|