-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathskyvern_wrapper_example.py
More file actions
73 lines (55 loc) · 1.64 KB
/
skyvern_wrapper_example.py
File metadata and controls
73 lines (55 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Run the Skyvern wrapper without installing Skyvern.
This uses a fake Skyvern-shaped client so the example is deterministic:
python examples/skyvern_wrapper_example.py
Then open the BrowserTrace UI:
browsertrace
"""
from __future__ import annotations
import asyncio
import os
from dataclasses import asdict, dataclass
from browsertrace import Tracer
from browsertrace.integrations.skyvern import wrap_skyvern
@dataclass
class DemoTaskResult:
task_run_id: str
status: str
url: str
prompt: str
invoice_total: str
def model_dump(self, exclude_none: bool = True) -> dict[str, str]:
return asdict(self)
class DemoSkyvernClient:
async def run_task(
self,
*,
url: str,
prompt: str,
wait_for_completion: bool = False,
) -> DemoTaskResult:
await asyncio.sleep(0)
return DemoTaskResult(
task_run_id="tsk_demo_001",
status="completed",
url=url,
prompt=prompt,
invoice_total="$42.00",
)
async def main() -> None:
tracer = Tracer(home=os.environ.get("BROWSERTRACE_HOME"))
skyvern = wrap_skyvern(
DemoSkyvernClient(),
tracer,
name="demo: skyvern invoice extraction",
)
result = await skyvern.run_task(
url="https://example.com/invoice",
prompt="extract the invoice total",
wait_for_completion=True,
)
skyvern.close()
print(f"Recorded Skyvern task: {result.task_run_id}")
print(f"BrowserTrace run id: {skyvern.bt_run.id}")
print("Open the local UI with: browsertrace")
if __name__ == "__main__":
asyncio.run(main())