66from pydantic import BaseModel , Field
77
88
9- class Furniture (BaseModel ):
10- type : str = Field (description = "the type of furniture " )
11- style : str = Field (description = "style of the furniture " )
12- colour : str = Field (description = "colour " )
9+ class Person (BaseModel ):
10+ first_name : str = Field (description = "first name " )
11+ last_name : str = Field (description = "last name " )
12+ dob : str = Field (description = "date of birth " )
1313
14- furniture_request = "I'd like a blue mid century chair"
1514
16- parser = PydanticOutputParser (pydantic_object = Furniture )
15+ class PeopleList (BaseModel ):
16+ people : list [Person ] = Field (description = "A list of people" )
17+
18+
19+ model = ChatOpenAI (model = "gpt-4" )
20+ people_data = model .predict (
21+ "Generate a list of 10 fake peoples information. Only return the list. Each person should have a first name, last name and date of birth." )
22+
23+ parser = PydanticOutputParser (pydantic_object = PeopleList )
1724
1825prompt = PromptTemplate (
1926 template = "Answer the user query.\n {format_instructions}\n {query}\n " ,
@@ -22,10 +29,10 @@ class Furniture(BaseModel):
2229 "format_instructions" : parser .get_format_instructions ()},
2330)
2431
25- _input = prompt .format_prompt (query = furniture_request )
32+ _input = prompt .format_prompt (query = people_data )
2633
2734model = ChatOpenAI ()
2835output = model .predict (_input .to_string ())
2936
3037parsed = parser .parse (output )
31- print (parsed . colour )
38+ print (parsed )
0 commit comments