@@ -1236,7 +1236,7 @@ def stream(
1236
1236
timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
1237
1237
) -> AsyncIterator [TaskView ]: ...
1238
1238
1239
- def stream (
1239
+ async def stream (
1240
1240
self ,
1241
1241
task_id : str ,
1242
1242
structured_output_json : type [T ] | None | NotGiven = NOT_GIVEN ,
@@ -1252,32 +1252,29 @@ def stream(
1252
1252
Stream the task view as it is updated until the task is finished.
1253
1253
"""
1254
1254
1255
- async def _gen () -> AsyncIterator [TaskView | TaskViewWithOutput [T ]]:
1256
- async for res in self ._watch (
1257
- task_id = task_id ,
1258
- extra_headers = extra_headers ,
1259
- extra_query = extra_query ,
1260
- extra_body = extra_body ,
1261
- timeout = timeout ,
1262
- ):
1263
- if structured_output_json is not None and isinstance (structured_output_json , type ):
1264
- if res .done_output is None :
1265
- yield TaskViewWithOutput [T ](
1266
- ** res .model_dump (),
1267
- parsed_output = None ,
1268
- )
1269
- else :
1270
- schema : type [T ] = structured_output_json
1271
- # pydantic returns the model instance, but the type checker can’t infer it.
1272
- parsed_output : T = schema .model_validate_json (res .done_output )
1273
- yield TaskViewWithOutput [T ](
1274
- ** res .model_dump (),
1275
- parsed_output = parsed_output ,
1276
- )
1255
+ async for res in self ._watch (
1256
+ task_id = task_id ,
1257
+ extra_headers = extra_headers ,
1258
+ extra_query = extra_query ,
1259
+ extra_body = extra_body ,
1260
+ timeout = timeout ,
1261
+ ):
1262
+ if structured_output_json is not None and isinstance (structured_output_json , type ):
1263
+ if res .done_output is None :
1264
+ yield TaskViewWithOutput [T ](
1265
+ ** res .model_dump (),
1266
+ parsed_output = None ,
1267
+ )
1277
1268
else :
1278
- yield res
1279
-
1280
- return _gen ()
1269
+ schema : type [T ] = structured_output_json
1270
+ # pydantic returns the model instance, but the type checker can’t infer it.
1271
+ parsed_output : T = schema .model_validate_json (res .done_output )
1272
+ yield TaskViewWithOutput [T ](
1273
+ ** res .model_dump (),
1274
+ parsed_output = parsed_output ,
1275
+ )
1276
+ else :
1277
+ yield res
1281
1278
1282
1279
async def _watch (
1283
1280
self ,
0 commit comments