Skip to content

Commit e30726f

Browse files
committed
Update to os.py and
1 parent 075e365 commit e30726f

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

operate/actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
add_grid_to_image,
1818
capture_mini_screenshot_with_cursor,
1919
)
20-
from operate.utils.operate import get_last_assistant_message
20+
from operate.utils.os import get_last_assistant_message
2121
from operate.prompts import (
2222
format_vision_prompt,
2323
format_accurate_mode_vision_prompt,

operate/dialog.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
ANSI_BRIGHT_MAGENTA,
1717
style,
1818
)
19-
from operate.utils.operate import (
20-
keyboard_type,
19+
from operate.utils.os import (
20+
type,
2121
search,
22-
mouse_click,
22+
click,
2323
)
2424
from operate.actions import get_next_action, summarize
2525
from operate.utils.misc import parse_response
@@ -139,9 +139,9 @@ def main(model, terminal_prompt, voice_mode=False):
139139
if action_type == "SEARCH":
140140
function_response = search(action_detail)
141141
elif action_type == "TYPE":
142-
function_response = keyboard_type(action_detail)
142+
function_response = type(action_detail)
143143
elif action_type == "CLICK":
144-
function_response = mouse_click(action_detail)
144+
function_response = click(action_detail)
145145
else:
146146
print(
147147
f"{ANSI_GREEN}[Self-Operating Computer]{ANSI_RED}[Error] something went wrong :({ANSI_RESET}"

operate/utils/operate.py renamed to operate/utils/os.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from operate.utils.misc import convert_percent_to_decimal
77

88

9-
def keyboard_type(text):
9+
def type(text):
1010
"""
1111
Types the given text using the keyboard.
1212
@@ -53,6 +53,31 @@ def search(text):
5353
return "Open program: " + text
5454

5555

56+
def click(click_detail):
57+
"""
58+
Perform a mouse click at the specified coordinates.
59+
60+
Args:
61+
click_detail (dict): A dictionary containing the coordinates of the click.
62+
63+
Returns:
64+
str: The description of the click if successful, otherwise "We failed to click".
65+
"""
66+
try:
67+
x = convert_percent_to_decimal(click_detail["x"])
68+
y = convert_percent_to_decimal(click_detail["y"])
69+
70+
if click_detail and isinstance(x, float) and isinstance(y, float):
71+
click_at_percentage(x, y)
72+
return click_detail["description"]
73+
else:
74+
return "We failed to click"
75+
76+
except Exception as e:
77+
print(f"Error parsing JSON: {e}")
78+
return "We failed to click"
79+
80+
5681
def click_at_percentage(
5782
x_percentage, y_percentage, duration=0.2, circle_radius=50, circle_duration=0.5
5883
):
@@ -92,31 +117,6 @@ def click_at_percentage(
92117
return "Successfully clicked"
93118

94119

95-
def mouse_click(click_detail):
96-
"""
97-
Perform a mouse click at the specified coordinates.
98-
99-
Args:
100-
click_detail (dict): A dictionary containing the coordinates of the click.
101-
102-
Returns:
103-
str: The description of the click if successful, otherwise "We failed to click".
104-
"""
105-
try:
106-
x = convert_percent_to_decimal(click_detail["x"])
107-
y = convert_percent_to_decimal(click_detail["y"])
108-
109-
if click_detail and isinstance(x, float) and isinstance(y, float):
110-
click_at_percentage(x, y)
111-
return click_detail["description"]
112-
else:
113-
return "We failed to click"
114-
115-
except Exception as e:
116-
print(f"Error parsing JSON: {e}")
117-
return "We failed to click"
118-
119-
120120
def get_last_assistant_message(messages):
121121
"""
122122
Retrieve the last message from the assistant in the messages array.

0 commit comments

Comments
 (0)