Skip to content

Commit 6318ceb

Browse files
committed
stash
1 parent 64bc583 commit 6318ceb

File tree

9 files changed

+31
-31
lines changed

9 files changed

+31
-31
lines changed

examples/async_create.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
# Regular Task
15-
async def create_regular_task():
15+
async def create_regular_task() -> None:
1616
res = await client.tasks.create(
1717
task="""
1818
Find top 10 Hacker News articles and return the title and url.
@@ -23,7 +23,7 @@ async def create_regular_task():
2323

2424

2525
# Structured Output
26-
async def create_structured_task():
26+
async def create_structured_task() -> None:
2727
class HackerNewsPost(BaseModel):
2828
title: str
2929
url: str
@@ -44,7 +44,7 @@ class SearchResult(BaseModel):
4444
# Main
4545

4646

47-
async def main():
47+
async def main() -> None:
4848
await asyncio.gather(
4949
#
5050
create_regular_task(),

examples/async_retrieve.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
# Regular Task
15-
async def retrieve_regular_task():
15+
async def retrieve_regular_task() -> None:
1616
"""
1717
Retrieves a regular task and waits for it to finish.
1818
"""
@@ -39,7 +39,7 @@ async def retrieve_regular_task():
3939
print("Done")
4040

4141

42-
async def retrieve_structured_task():
42+
async def retrieve_structured_task() -> None:
4343
"""
4444
Retrieves a structured task and waits for it to finish.
4545
"""
@@ -84,7 +84,7 @@ class SearchResult(BaseModel):
8484
# Main
8585

8686

87-
async def main():
87+
async def main() -> None:
8888
await asyncio.gather(
8989
#
9090
retrieve_regular_task(),

examples/async_run.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
# Regular Task
15-
async def run_regular_task():
15+
async def run_regular_task() -> None:
1616
regular_result = await client.tasks.run(
1717
task="""
1818
Find top 10 Hacker News articles and return the title and url.
@@ -27,7 +27,7 @@ async def run_regular_task():
2727

2828

2929
# Structured Output
30-
async def run_structured_task():
30+
async def run_structured_task() -> None:
3131
class HackerNewsPost(BaseModel):
3232
title: str
3333
url: str
@@ -52,7 +52,7 @@ class SearchResult(BaseModel):
5252
print("Structured Task Done")
5353

5454

55-
async def main():
55+
async def main() -> None:
5656
await asyncio.gather(
5757
#
5858
run_regular_task(),

examples/async_stream.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
# Regular Task
16-
async def stream_regular_task():
16+
async def stream_regular_task() -> None:
1717
regular_task = await client.tasks.create(
1818
task="""
1919
Find top 10 Hacker News articles and return the title and url.
@@ -36,7 +36,7 @@ async def stream_regular_task():
3636

3737

3838
# Structured Output
39-
async def stream_structured_task():
39+
async def stream_structured_task() -> None:
4040
class HackerNewsPost(BaseModel):
4141
title: str
4242
url: str
@@ -70,7 +70,7 @@ class SearchResult(BaseModel):
7070
# Main
7171

7272

73-
async def main():
73+
async def main() -> None:
7474
await asyncio.gather(
7575
#
7676
stream_regular_task(),

examples/create.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
# Regular Task
14-
def create_regular_task():
14+
def create_regular_task() -> None:
1515
res = client.tasks.create(
1616
task="""
1717
Find top 10 Hacker News articles and return the title and url.
@@ -25,7 +25,7 @@ def create_regular_task():
2525

2626

2727
# Structured Output
28-
def create_structured_task():
28+
def create_structured_task() -> None:
2929
class HackerNewsPost(BaseModel):
3030
title: str
3131
url: str

examples/retrieve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
# Regular Task
15-
def retrieve_regular_task():
15+
def retrieve_regular_task() -> None:
1616
"""
1717
Retrieves a regular task and waits for it to finish.
1818
"""
@@ -42,7 +42,7 @@ def retrieve_regular_task():
4242
retrieve_regular_task()
4343

4444

45-
def retrieve_structured_task():
45+
def retrieve_structured_task() -> None:
4646
"""
4747
Retrieves a structured task and waits for it to finish.
4848
"""

examples/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
# Regular Task
14-
def run_regular_task():
14+
def run_regular_task() -> None:
1515
regular_result = client.tasks.run(
1616
task="""
1717
Find top 10 Hacker News articles and return the title and url.
@@ -29,7 +29,7 @@ def run_regular_task():
2929

3030

3131
# Structured Output
32-
def run_structured_task():
32+
def run_structured_task() -> None:
3333
class HackerNewsPost(BaseModel):
3434
title: str
3535
url: str

examples/stream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
# Regular Task
15-
def stream_regular_task():
15+
def stream_regular_task() -> None:
1616
regular_task = client.tasks.create(
1717
task="""
1818
Find top 10 Hacker News articles and return the title and url.
@@ -38,7 +38,7 @@ def stream_regular_task():
3838

3939

4040
# Structured Output
41-
def stream_structured_task():
41+
def stream_structured_task() -> None:
4242
class HackerNewsPost(BaseModel):
4343
title: str
4444
url: str

src/browser_use_sdk/resources/tasks.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -417,42 +417,42 @@ def retrieve(
417417
def stream(
418418
self,
419419
task_id: str,
420-
structured_output_json: None | NotGiven = NOT_GIVEN,
420+
structured_output_json: type[T],
421421
*,
422422
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
423423
# The extra values given here take precedence over values defined on the client or passed to this method.
424424
extra_headers: Headers | None = None,
425425
extra_query: Query | None = None,
426426
extra_body: Body | None = None,
427427
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
428-
) -> Iterator[TaskView]: ...
428+
) -> Iterator[TaskViewWithOutput[T]]: ...
429429

430430
@overload
431431
def stream(
432432
self,
433433
task_id: str,
434-
structured_output_json: type[T],
434+
structured_output_json: None | NotGiven = NOT_GIVEN,
435435
*,
436436
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
437437
# The extra values given here take precedence over values defined on the client or passed to this method.
438438
extra_headers: Headers | None = None,
439439
extra_query: Query | None = None,
440440
extra_body: Body | None = None,
441441
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
442-
) -> Iterator[TaskViewWithOutput[T]]: ...
442+
) -> Iterator[TaskView]: ...
443443

444444
def stream(
445445
self,
446446
task_id: str,
447-
structured_output_json: type[BaseModel] | None | NotGiven = NOT_GIVEN,
447+
structured_output_json: type[T] | None | NotGiven = NOT_GIVEN,
448448
*,
449449
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
450450
# The extra values given here take precedence over values defined on the client or passed to this method.
451451
extra_headers: Headers | None = None,
452452
extra_query: Query | None = None,
453453
extra_body: Body | None = None,
454454
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
455-
) -> Iterator[Union[TaskView, TaskViewWithOutput[BaseModel]]]:
455+
) -> Iterator[TaskView | TaskViewWithOutput[T]]:
456456
"""
457457
Stream the task view as it is updated until the task is finished.
458458
"""
@@ -466,14 +466,15 @@ def stream(
466466
):
467467
if structured_output_json is not None and isinstance(structured_output_json, type):
468468
if res.done_output is None:
469-
yield TaskViewWithOutput[BaseModel](
469+
yield TaskViewWithOutput[T](
470470
**res.model_dump(),
471471
parsed_output=None,
472472
)
473473
else:
474-
parsed_output = structured_output_json.model_validate_json(res.done_output)
474+
schema: type[T] = structured_output_json
475+
parsed_output: T = schema.model_validate_json(res.done_output)
475476

476-
yield TaskViewWithOutput[BaseModel](
477+
yield TaskViewWithOutput[T](
477478
**res.model_dump(),
478479
parsed_output=parsed_output,
479480
)
@@ -1246,7 +1247,7 @@ def stream(
12461247
extra_query: Query | None = None,
12471248
extra_body: Body | None = None,
12481249
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
1249-
) -> AsyncIterator[TaskView] | AsyncIterator[TaskViewWithOutput[T]]:
1250+
) -> AsyncIterator[TaskView | TaskViewWithOutput[T]]:
12501251
"""
12511252
Stream the task view as it is updated until the task is finished.
12521253
"""
@@ -1259,7 +1260,6 @@ async def _gen() -> AsyncIterator[TaskView | TaskViewWithOutput[T]]:
12591260
extra_body=extra_body,
12601261
timeout=timeout,
12611262
):
1262-
# If a schema (type[T]) is passed, wrap with parsed_output[T]
12631263
if structured_output_json is not None and isinstance(structured_output_json, type):
12641264
if res.done_output is None:
12651265
yield TaskViewWithOutput[T](

0 commit comments

Comments
 (0)