-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorder_food.py
More file actions
82 lines (70 loc) · 2.81 KB
/
Copy pathorder_food.py
File metadata and controls
82 lines (70 loc) · 2.81 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
77
78
79
80
81
82
from scrapybara.tools import BashTool, ComputerTool, EditTool
from scrapybara.anthropic import Anthropic
from scrapybara.prompts import UBUNTU_SYSTEM_PROMPT
from scrapybara import Scrapybara
from playwright.sync_api import sync_playwright
from mistralai import Mistral
api_key = "X1ZHa8fUIXvz9wy9nJOXhbKSRbEwexJx"
model = "mistral-large-latest"
client = Mistral(api_key=api_key)
chat_response = client.chat.complete(
model= model,
messages = [
{
"role": "user",
"content": "I'm stressed and i want to get some food from dominos. choose 3 items that will help me feel better. just say the name of the items, no other text, separated by commas",
},
]
)
items = chat_response.choices[0].message.content
print("Mistral AI chose the following items: ", items)
print("Ordering these items via Scrapybara...")
# Initialize the Scrapybara client
client = Scrapybara(api_key="scrapy-a90ef477-a167-4d50-a0ae-465ba3ab0a29")
# Start an Ubuntu instance
instance = client.start_ubuntu(timeout_hours=1)
# Start the browser and connect via CDP
cdp_url = instance.browser.start().cdp_url
playwright = sync_playwright().start()
browser = playwright.chromium.connect_over_cdp(cdp_url)
stream_url = instance.get_stream_url().stream_url
def print_step(step):
print(step.text)
# Updated prompt: use Domino's website (which ideally avoids captchas) and order a pizza.
prompt_text = (
"Go to Domino's Pizza website (https://www.dominos.com), log into my account "
"Click on DELIVERY button"
"Fill out the address with 475 Via Ortega, Stanford, CA 94305"
"Select today's date for the delivery and the earliest time available"
f"order the following items: {items}"
"Click on continue checkout"
# "Fill in with my information: Sophia Sharif, sophiasharif@ucla.edu, 650-555-1234"
# "select I'll sign up later"
# "select leave it at the door"
# "click pay with cash upon delivery"
)
def attempt_order(model):
"""Run the ordering task using the given AI model."""
return client.act(
model=model,
tools=[
BashTool(instance),
ComputerTool(instance),
EditTool(instance),
],
system=UBUNTU_SYSTEM_PROMPT,
prompt=prompt_text,
on_step=print_step,
)
# Try using Anthropic as the primary model.
try:
response = attempt_order(Anthropic())
except Exception as e:
print("Encountered an error with Anthropic:", e)
print("Falling back to Mistral model...")
# Check for any indications of bot protection (like "captcha" or "security check")
if "captcha" in response.text.lower() or "security check" in response.text.lower():
print("Detected a captcha or security check in the response. Switching to Mistral model...")
response = attempt_order(Anthropic())
print("Final response:")
print(response.text)