13
13
14
14
# Regular Task
15
15
async def stream_regular_task () -> None :
16
- regular_task = await client .tasks .create (
16
+ task = await client .tasks .create_task (
17
17
task = """
18
18
Find top 10 Hacker News articles and return the title and url.
19
19
""" ,
20
20
llm = "gemini-2.5-flash" ,
21
21
)
22
22
23
- print (f"Regular Task ID: { regular_task .id } " )
23
+ print (f"Regular Task ID: { task .id } " )
24
24
25
- async for res in client .tasks .stream (regular_task .id ):
26
- print (f"Regular Task Status: { res .status } " )
27
-
28
- if len (res .steps ) > 0 :
29
- last_step = res .steps [- 1 ]
30
- print (f"Regular Task Step: { last_step .url } ({ last_step .next_goal } )" )
31
- for action in last_step .actions :
32
- print (f" - Regular Task Action: { action } " )
25
+ async for step in task .stream ():
26
+ print (f"Regular Task Status: { step .number } " )
33
27
34
28
print ("Regular Task Done" )
35
29
@@ -43,26 +37,24 @@ class HackerNewsPost(BaseModel):
43
37
class SearchResult (BaseModel ):
44
38
posts : List [HackerNewsPost ]
45
39
46
- structured_task = await client .tasks .create (
40
+ task = await client .tasks .create_task (
47
41
task = """
48
42
Find top 10 Hacker News articles and return the title and url.
49
43
""" ,
50
44
llm = "gpt-4.1" ,
51
- structured_output_json = SearchResult ,
45
+ schema = SearchResult ,
52
46
)
53
47
54
- print (f"Structured Task ID: { structured_task .id } " )
48
+ print (f"Structured Task ID: { task .id } " )
49
+
50
+ async for step in task .stream ():
51
+ print (f"Structured Task Step { step .number } : { step .url } ({ step .next_goal } )" )
55
52
56
- async for res in client .tasks .stream (structured_task .id , structured_output_json = SearchResult ):
57
- print (f"Structured Task Status: { res .status } " )
53
+ result = await task .complete ()
58
54
59
- if res .status == "finished" :
60
- if res .parsed_output is None :
61
- print ("Structured Task No output" )
62
- else :
63
- for post in res .parsed_output .posts :
64
- print (f" - Structured Task Post: { post .title } - { post .url } " )
65
- break
55
+ if result .parsed_output is not None :
56
+ for post in result .parsed_output .posts :
57
+ print (f" - { post .title } - { post .url } " )
66
58
67
59
print ("Structured Task Done" )
68
60
0 commit comments