1+ import asyncio
2+
3+ from pydantic import BaseModel , Field # pyright: ignore [reportUnknownVariableType]
4+
15import workflowai
26from workflowai import Model , Run
3- from pydantic import BaseModel , Field
4- import asyncio
57
68
79class NameExtractionInput (BaseModel ):
810 """Input containing a sentence with a person's name."""
11+
912 sentence : str = Field (description = "A sentence containing a person's name." )
1013
1114
1215class NameExtractionOutput (BaseModel ):
1316 """Output containing the extracted first and last name."""
17+
1418 first_name : str = Field (
1519 default = "" ,
16- description = "The person's first name extracted from the sentence."
20+ description = "The person's first name extracted from the sentence." ,
1721 )
1822 last_name : str = Field (
1923 default = "" ,
20- description = "The person's last name extracted from the sentence."
24+ description = "The person's last name extracted from the sentence." ,
2125 )
2226
2327
24- @workflowai .agent (id = ' name-extractor' , model = Model .GPT_4O_MINI_LATEST )
25- async def extract_name (input : NameExtractionInput ) -> Run [NameExtractionOutput ]:
28+ @workflowai .agent (id = " name-extractor" , model = Model .GPT_4O_MINI_LATEST )
29+ async def extract_name (_ : NameExtractionInput ) -> Run [NameExtractionOutput ]:
2630 """
2731 Extract a person's first and last name from a sentence.
2832 Be precise and consider cultural variations in name formats.
@@ -38,21 +42,21 @@ async def main():
3842 "Dr. Maria Garcia-Rodriguez presented her research." ,
3943 "The report was written by James van der Beek last week." ,
4044 ]
41-
45+
4246 for sentence in sentences :
4347 print (f"\n Processing: { sentence } " )
44-
48+
4549 # Initial extraction
4650 run = await extract_name (NameExtractionInput (sentence = sentence ))
47-
51+
4852 print (f"Extracted: { run .output .first_name } { run .output .last_name } " )
49-
53+
5054 # Double check with a simple confirmation
51- run = await run .reply (user_response = "Are you sure?" )
52-
55+ run = await run .reply (user_message = "Are you sure?" )
56+
5357 print ("\n After double-checking:" )
5458 print (f"Final extraction: { run .output .first_name } { run .output .last_name } " )
5559
5660
5761if __name__ == "__main__" :
58- asyncio .run (main ())
62+ asyncio .run (main ())
0 commit comments