forked from openai/openai-cua-sample-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
90 lines (80 loc) · 2.43 KB
/
cli.py
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
83
84
85
86
87
88
89
90
import argparse
from agent.agent import Agent
from computers import (
BrowserbaseBrowser,
ScrapybaraBrowser,
ScrapybaraUbuntu,
LocalPlaywrightComputer,
DockerComputer,
)
def acknowledge_safety_check_callback(message: str) -> bool:
response = input(
f"Safety Check Warning: {message}\nDo you want to acknowledge and proceed? (y/n): "
).lower()
return response.lower().strip() == "y"
def main():
parser = argparse.ArgumentParser(
description="Select a computer environment from the available options."
)
parser.add_argument(
"--computer",
choices=[
"local-playwright",
"docker",
"browserbase",
"scrapybara-browser",
"scrapybara-ubuntu",
],
help="Choose the computer environment to use.",
default="local-playwright",
)
parser.add_argument(
"--input",
type=str,
help="Initial input to use instead of asking the user.",
default=None,
)
parser.add_argument(
"--debug",
action="store_true",
help="Enable debug mode for detailed output.",
)
parser.add_argument(
"--show",
action="store_true",
help="Show images during the execution.",
)
parser.add_argument(
"--start-url",
type=str,
help="Start the browsing session with a specific URL (only for browser environments).",
default="https://bing.com",
)
args = parser.parse_args()
computer_mapping = {
"local-playwright": LocalPlaywrightComputer,
"docker": DockerComputer,
"browserbase": BrowserbaseBrowser,
"scrapybara-browser": ScrapybaraBrowser,
"scrapybara-ubuntu": ScrapybaraUbuntu,
}
ComputerClass = computer_mapping[args.computer]
with ComputerClass() as computer:
agent = Agent(
computer=computer,
acknowledge_safety_check_callback=acknowledge_safety_check_callback,
)
items = []
while True:
user_input = args.input or input("> ")
items.append({"role": "user", "content": user_input})
output_items = agent.run_full_turn(
items,
print_steps=True,
show_images=args.show,
debug=args.debug,
)
items += output_items
args.input = None
if __name__ == "__main__":
main()