-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathgenerate_data.py
43 lines (29 loc) · 882 Bytes
/
generate_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from typing import Iterator, List
from _context import sm
from pydantic import BaseModel
class Movie(BaseModel):
title: str
year: int
class MovieCharecter(BaseModel):
name: str
actor: str
class MovieQuote(BaseModel):
quote: str
movie: Movie
charecter: MovieCharecter
class QuotesList(BaseModel):
quotes: List[MovieQuote]
def gen_quotes(n: int = 10) -> Iterator[MovieQuote]:
"""Generate a list of quotes from famous movies."""
for q in sm.generate_data(
llm_provider="openai",
llm_model="gpt-4o-mini",
prompt=f"Generate {n} quotes from famous movies",
response_model=QuotesList,
).quotes:
yield q
if __name__ == "__main__":
for quote in gen_quotes(n=20):
print(
f"{quote.charecter.name} from {quote.movie.title} ({quote.movie.year}): {quote.quote!r}"
)