Skip to content

Commit 39bf0c3

Browse files
committed
fixes
1 parent 48150a1 commit 39bf0c3

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

README.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ from browser_use_sdk import BrowserUse
1616

1717
client = BrowserUse(api_key="bu_...")
1818

19-
result = client.tasks.run(
19+
task = client.tasks.create_task(
2020
task="Search for the top 10 Hacker News posts and return the title and url."
21+
llm="gpt-4.1",
2122
)
2223

23-
result.done_output
24+
result = task.complete()
25+
26+
result.output
2427
```
2528

2629
> The full API of this library can be found in [api.md](api.md).
@@ -38,16 +41,18 @@ class SearchResult(BaseModel):
3841
posts: List[HackerNewsPost]
3942

4043
async def main() -> None:
41-
result = await client.tasks.run(
44+
task = await client.tasks.create_task(
4245
task="""
4346
Find top 10 Hacker News articles and return the title and url.
4447
""",
45-
structured_output_json=SearchResult,
48+
schema=SearchResult,
4649
)
4750

48-
if structured_result.parsed_output is not None:
51+
result = await task.complete()
52+
53+
if result.parsed_output is not None:
4954
print("Top HackerNews Posts:")
50-
for post in structured_result.parsed_output.posts:
55+
for post in result.parsed_output.posts:
5156
print(f" - {post.title} - {post.url}")
5257

5358
asyncio.run(main())
@@ -73,25 +78,18 @@ async def main() -> None:
7378
task="""
7479
Find top 10 Hacker News articles and return the title and url.
7580
""",
76-
structured_output_json=SearchResult,
81+
schema=SearchResult,
7782
)
7883

79-
async for update in client.tasks.stream(task.id, structured_output_json=SearchResult):
80-
if len(update.steps) > 0:
81-
last_step = update.steps[-1]
82-
print(f"{update.status}: {last_step.url} ({last_step.next_goal})")
83-
else:
84-
print(f"{update.status}")
84+
async for step in task.stream():
85+
print(f"Step {step.number}: {step.url} ({step.next_goal})")
8586

86-
if update.status == "finished":
87-
if update.parsed_output is None:
88-
print("No output...")
89-
else:
90-
print("Top HackerNews Posts:")
91-
for post in update.parsed_output.posts:
92-
print(f" - {post.title} - {post.url}")
87+
result = await task.complete()
9388

94-
break
89+
if result.parsed_output is not None:
90+
print("Top HackerNews Posts:")
91+
for post in result.parsed_output.posts:
92+
print(f" - {post.title} - {post.url}")
9593

9694
asyncio.run(main())
9795
```
@@ -105,7 +103,7 @@ Browser Use SDK lets you easily verify the signature and structure of the payloa
105103
```py
106104
import uvicorn
107105
import os
108-
from browser_use_sdk.lib.webhooks import Webhook, verify_webhook_event_signature
106+
from browser_use_sdk import Webhook, verify_webhook_event_signature
109107

110108
from fastapi import FastAPI, Request, HTTPException
111109

@@ -153,10 +151,11 @@ client = AsyncBrowserUse(
153151

154152

155153
async def main() -> None:
156-
task = await client.tasks.run(
154+
task = await client.tasks.create_task(
157155
task="Search for the top 10 Hacker News posts and return the title and url.",
158156
)
159-
print(task.done_output)
157+
158+
print(task.id)
160159

161160

162161
asyncio.run(main())
@@ -468,6 +467,7 @@ a proof of concept, but know that we will not be able to merge it as-is. We sugg
468467
an issue first to discuss with us!
469468

470469
On the other hand, contributions to the README are always very welcome!
470+
471471
## Installation
472472

473473
```sh
@@ -530,4 +530,3 @@ except ApiError as e:
530530
print(e.status_code)
531531
print(e.body)
532532
```
533-

examples/async_stream.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ async def stream_regular_task() -> None:
2525
async for step in task.stream():
2626
print(f"Regular Task Status: {step.number}")
2727

28+
result = await task.complete()
29+
30+
if result.output is not None:
31+
print(f"Regular Task Output: {result.output}")
32+
2833
print("Regular Task Done")
2934

3035

@@ -53,6 +58,8 @@ class SearchResult(BaseModel):
5358
result = await task.complete()
5459

5560
if result.parsed_output is not None:
61+
print("Structured Task Output:")
62+
5663
for post in result.parsed_output.posts:
5764
print(f" - {post.title} - {post.url}")
5865

0 commit comments

Comments
 (0)