-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_tab.py
More file actions
76 lines (63 loc) · 2.2 KB
/
multi_tab.py
File metadata and controls
76 lines (63 loc) · 2.2 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
74
75
76
"""Multi-tab comparison — open several sites, gather info, compare.
Opens each URL in its own tab, asks Northstar to extract a value from each,
then prints a summary. Useful for price comparison, competitive analysis,
or any task that needs cross-site data.
"""
import json
import os
from tzafon import Lightcone
from _cua import get_messages, DONE_TOOL
client = Lightcone()
TOOL = {
"type": "computer_use",
"display_width": 1280,
"display_height": 720,
"environment": "desktop",
}
URLS = [
"https://example.com/product-a",
"https://example.com/product-b",
"https://example.com/product-c",
]
def ask_model_about_screenshot(screenshot_url, prompt):
"""One-shot: send a screenshot + question, get a text answer."""
response = client.responses.create(
model="tzafon.northstar-cua-fast",
tools=[TOOL, DONE_TOOL],
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": prompt},
{"type": "input_image", "image_url": screenshot_url, "detail": "auto"},
],
}
],
)
texts = get_messages(response.output)
return texts[0] if texts else "(no response)"
with client.computer.create(kind="desktop") as computer:
results = []
for i, url in enumerate(URLS):
if i == 0:
computer.navigate(url)
else:
client.computers.tabs.create(computer.id, url=url)
computer.wait(3)
screenshot_url = computer.get_screenshot_url(computer.screenshot())
answer = ask_model_about_screenshot(
screenshot_url,
"Look at this page and tell me the product name and price. "
"Reply with just: <name> — $<price>",
)
print(f"Tab {i + 1} ({url}): {answer}")
results.append(answer)
# Compare results.
summary = (
"Here are the results:\n"
+ "\n".join(f"- {r}" for r in results)
+ "\n\nWhich is the cheapest? Reply in one sentence."
)
screenshot_url = computer.get_screenshot_url(computer.screenshot())
verdict = ask_model_about_screenshot(screenshot_url, summary)
print(f"\nVerdict: {verdict}")