@@ -113,6 +113,9 @@ def run(
113
113
extra_body : Body | None = None ,
114
114
timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
115
115
) -> Union [TaskView , TaskViewWithOutput [BaseModel ]]:
116
+ """
117
+ Run a new task and return the task view.
118
+ """
116
119
if structured_output_json is not None and isinstance (structured_output_json , type ):
117
120
create_task_res = self .create (
118
121
task = task ,
@@ -128,9 +131,9 @@ def run(
128
131
timeout = timeout ,
129
132
)
130
133
131
- for msg in self .stream (create_task_res .id , structured_output_json = structured_output_json ):
132
- if msg .status == "finished" :
133
- return msg
134
+ for structured_msg in self .stream (create_task_res .id , structured_output_json = structured_output_json ):
135
+ if structured_msg .status == "finished" :
136
+ return structured_msg
134
137
135
138
raise ValueError ("Task did not finish" )
136
139
@@ -341,7 +344,7 @@ def retrieve(
341
344
extra_query : Query | None = None ,
342
345
extra_body : Body | None = None ,
343
346
timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
344
- ) -> TaskView :
347
+ ) -> Union [ TaskView , TaskViewWithOutput [ BaseModel ]] :
345
348
"""
346
349
Get detailed information about a specific AI agent task.
347
350
@@ -390,14 +393,14 @@ def retrieve(
390
393
)
391
394
392
395
if res .done_output is None :
393
- return TaskViewWithOutput [structured_output_json ](
396
+ return TaskViewWithOutput [BaseModel ](
394
397
** res .model_dump (),
395
398
parsed_output = None ,
396
399
)
397
400
398
401
parsed_output = structured_output_json .model_validate_json (res .done_output )
399
402
400
- return TaskViewWithOutput [structured_output_json ](
403
+ return TaskViewWithOutput [BaseModel ](
401
404
** res .model_dump (),
402
405
parsed_output = parsed_output ,
403
406
)
@@ -462,14 +465,14 @@ def stream(
462
465
):
463
466
if structured_output_json is not None and isinstance (structured_output_json , type ):
464
467
if res .done_output is None :
465
- yield TaskViewWithOutput [structured_output_json ](
468
+ yield TaskViewWithOutput [BaseModel ](
466
469
** res .model_dump (),
467
470
parsed_output = None ,
468
471
)
469
472
else :
470
473
parsed_output = structured_output_json .model_validate_json (res .done_output )
471
474
472
- yield TaskViewWithOutput [structured_output_json ](
475
+ yield TaskViewWithOutput [BaseModel ](
473
476
** res .model_dump (),
474
477
parsed_output = parsed_output ,
475
478
)
0 commit comments