computer-use-ootb-internal 0.0.105__py3-none-any.whl → 0.0.107__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,194 +0,0 @@
1
- import argparse
2
- import time
3
- import json
4
- import threading
5
-
6
- from flask import Flask, request, jsonify
7
- from flask_socketio import SocketIO, emit
8
-
9
- from screeninfo import get_monitors
10
- from computer_use_ootb_internal.computer_use_demo.tools.computer import get_screen_details
11
- from computer_use_ootb_internal.run_teachmode_ootb_args import simple_teachmode_sampling_loop
12
-
13
- ###############################################################################
14
- # Shared State
15
- ###############################################################################
16
- class SharedState:
17
- def __init__(self):
18
- self.args = None # Will hold argparse-like namespace
19
- self.messages = [] # If you want to store a global chat or last session
20
-
21
- shared_state = SharedState()
22
-
23
- ###############################################################################
24
- # Flask + SocketIO Application Setup
25
- ###############################################################################
26
- app = Flask(__name__)
27
- app.config["SECRET_KEY"] = "some-secret-key" # In production, change this
28
- socketio = SocketIO(app, cors_allowed_origins="*")
29
-
30
- ###############################################################################
31
- # Utility Functions
32
- ###############################################################################
33
- def setup_default_args():
34
- """
35
- Creates argparse-like defaults.
36
- You can also parse real CLI args if you wish.
37
- """
38
- parser = argparse.ArgumentParser(description="Teachmode SocketIO Server.")
39
- parser.add_argument("--model", default="teach-mode-gpt-4o")
40
- parser.add_argument("--task", default="Help me complete data extraction on YouTube video.")
41
- parser.add_argument("--selected_screen", type=int, default=0)
42
- parser.add_argument("--user_id", default="liziqi")
43
- parser.add_argument("--trace_id", default="default_trace")
44
- parser.add_argument("--api_key_file", default="api_key.json")
45
- parser.add_argument("--api_keys", default="")
46
- parser.add_argument(
47
- "--server_url",
48
- default="http://ec2-44-234-43-86.us-west-2.compute.amazonaws.com/generate_action",
49
- help="Server URL for the session (local='http://localhost:5000/generate_action', \
50
- aws='http://ec2-44-234-43-86.us-west-2.compute.amazonaws.com/generate_action').",
51
- )
52
-
53
- # If you really want to parse sys.argv, do parser.parse_args().
54
- # But you can also return the defaults for this example:
55
- return parser.parse_args([])
56
-
57
- def apply_args_to_state(args):
58
- """
59
- Helper that prints or logs relevant arguments and stores them in shared_state.
60
- """
61
- print("[apply_args_to_state] Applying arguments:", args)
62
- shared_state.args = args
63
-
64
- def run_teachmode_task(user_input):
65
- """
66
- Calls simple_teachmode_sampling_loop and emits partial responses over SocketIO.
67
- """
68
- # 1) Log or store user input
69
- print(f"[run_teachmode_task] Received user_input: {user_input}")
70
- # Optionally store or reset message history for this session
71
- shared_state.messages = [{"role": "user", "content": user_input}]
72
-
73
- # 2) Grab arguments from shared_state
74
- args = shared_state.args
75
- if not args:
76
- print("[run_teachmode_task] No arguments in shared_state, applying defaults.")
77
- args = setup_default_args()
78
- apply_args_to_state(args)
79
-
80
- # 3) Run the sampling loop
81
- print(f"[run_teachmode_task] Starting the sampling loop with task: {args.task}")
82
- sampling_loop = simple_teachmode_sampling_loop(
83
- model=args.model,
84
- task=args.task,
85
- selected_screen=args.selected_screen,
86
- user_id=args.user_id,
87
- trace_id=args.trace_id,
88
- api_keys=args.api_keys,
89
- server_url=args.server_url
90
- )
91
-
92
- # 4) Send partial responses
93
- for loop_msg in sampling_loop:
94
- print(f"[run_teachmode_task] Emitting partial response: {loop_msg}")
95
- # You can store it in shared_state messages
96
- shared_state.messages.append({"role": "assistant", "content": loop_msg})
97
- # Emit immediately so the client sees partial responses
98
- emit("partial_response", {"role": "assistant", "content": loop_msg})
99
- time.sleep(1) # Optional delay to simulate real-time streaming
100
-
101
- # 5) Done event
102
- print("[run_teachmode_task] Completed all messages.")
103
- emit("done", {"messages": shared_state.messages, "status": "completed"})
104
-
105
- ###############################################################################
106
- # HTTP Endpoint: update_params
107
- ###############################################################################
108
- @app.route("/update_params", methods=["POST"])
109
- def update_parameters():
110
- """
111
- HTTP endpoint that allows updating the parameters (like Gradio's /update_params).
112
- Expects JSON body with fields matching the argparse Namespace (model, task, etc.)
113
- """
114
- data = request.json
115
- if not data:
116
- return jsonify({"status": "error", "message": "No JSON provided."}), 400
117
-
118
- # Build an argparse.Namespace from the JSON keys
119
- # Fallback to the existing arguments if some keys are missing
120
- old_args = shared_state.args or setup_default_args()
121
- new_args_dict = {**vars(old_args), **data} # Merge old with new
122
- new_args = argparse.Namespace(**new_args_dict)
123
- apply_args_to_state(new_args)
124
-
125
- return jsonify({
126
- "status": "success",
127
- "message": "Parameters updated",
128
- "new_args": vars(new_args)
129
- })
130
-
131
- ###############################################################################
132
- # HTTP Endpoint: get_messages
133
- ###############################################################################
134
- @app.route("/get_messages", methods=["GET"])
135
- def get_messages():
136
- """
137
- Example new function: returns the current chat messages in shared_state.
138
- """
139
- return jsonify(shared_state.messages)
140
-
141
- ###############################################################################
142
- # HTTP Endpoint: clear_messages
143
- ###############################################################################
144
- @app.route("/clear_messages", methods=["POST"])
145
- def clear_messages():
146
- """
147
- Example new function: clears the stored chat messages in shared_state.
148
- """
149
- shared_state.messages = []
150
- return jsonify({"status": "success", "message": "Chat history cleared."})
151
-
152
- ###############################################################################
153
- # SocketIO Event: run_teachmode
154
- ###############################################################################
155
- @socketio.on("run_teachmode")
156
- def handle_run_teachmode(data):
157
- """
158
- Websocket event that starts the teachmode sampling loop.
159
- `data` can include e.g. {"user_input": "..."}.
160
- """
161
- user_input = data.get("user_input", "Hello, let's start!")
162
- run_teachmode_task(user_input)
163
-
164
- ###############################################################################
165
- # SocketIO Event: connect
166
- ###############################################################################
167
- @socketio.on("connect")
168
- def on_connect():
169
- print("[SocketIO] Client connected.")
170
-
171
- @socketio.on("disconnect")
172
- def on_disconnect():
173
- print("[SocketIO] Client disconnected.")
174
-
175
- ###############################################################################
176
- # Main
177
- ###############################################################################
178
- def main():
179
- # Pre-populate shared_state with default arguments
180
- args = setup_default_args()
181
- apply_args_to_state(args)
182
-
183
- # Optional: Preload screen info if needed
184
- screens = get_monitors()
185
- print("Detected screens:", screens)
186
- screen_names, primary_index = get_screen_details()
187
- print("Screen names:", screen_names, "Default selected index:", primary_index)
188
-
189
- # Run the Flask-SocketIO app
190
- # eventlet is the default async_mode if installed, but we specify it explicitly.
191
- socketio.run(app, host="0.0.0.0", port=5001, debug=True)
192
-
193
- if __name__ == "__main__":
194
- main()
@@ -1,41 +0,0 @@
1
- import socketio
2
-
3
- # Create a Socket.IO client instance
4
- sio = socketio.Client()
5
-
6
- @sio.on('connect')
7
- def on_connect():
8
- print("Connected to the server.")
9
- # Once connected, send the event to start the teachmode process:
10
- data = {
11
- "user_input": "Hello, I'd like to open the Chrome browser."
12
- # You can add more parameters here if needed, e.g.:
13
- # "model": "teach-mode-gpt-4o",
14
- # "task": "Some task",
15
- # "user_id": "my_user",
16
- # etc.
17
- }
18
- print("Emitting 'run_teachmode' event with data:", data)
19
- sio.emit("run_teachmode", data)
20
-
21
- @sio.on('partial_response')
22
- def on_partial_response(data):
23
- print("[partial_response] =>", data)
24
-
25
- @sio.on('done')
26
- def on_done(data):
27
- print("[done] =>", data)
28
- # Since the process is completed, you can disconnect:
29
- sio.disconnect()
30
-
31
- @sio.on('disconnect')
32
- def on_disconnect():
33
- print("Disconnected from server.")
34
-
35
-
36
- if __name__ == "__main__":
37
- # Connect to the Socket.IO server (adapt host/port as needed):
38
- sio.connect("http://localhost:5001")
39
-
40
- # Keep the client alive to receive events
41
- sio.wait()