Skip to content

Commit 02772a9

Browse files
committed
Improve app prints in error handling and improve prompts
1 parent 4554bf5 commit 02772a9

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

operate/models/apis.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@
2828
get_click_position_in_percent,
2929
get_label_coordinates,
3030
)
31-
from operate.utils.style import (
32-
ANSI_GREEN,
33-
ANSI_RED,
34-
ANSI_RESET,
35-
)
31+
from operate.utils.style import ANSI_GREEN, ANSI_RED, ANSI_RESET, ANSI_BRIGHT_MAGENTA
3632
import pkg_resources
3733

3834

@@ -131,7 +127,7 @@ def call_gpt_4_vision_preview(messages):
131127

132128
except Exception as e:
133129
print(
134-
f"{ANSI_GREEN}[Self-Operating Computer]{ANSI_RED}[Error] Something went wrong. Trying again {ANSI_RESET}",
130+
f"{ANSI_GREEN}[Self-Operating Computer]{ANSI_BRIGHT_MAGENTA}[Operate] That did not work. Trying again {ANSI_RESET}",
135131
e,
136132
)
137133
print(
@@ -187,9 +183,11 @@ def call_gemini_pro_vision(messages, objective):
187183

188184
except Exception as e:
189185
print(
190-
f"{ANSI_GREEN}[Self-Operating Computer]{ANSI_RED}[Error] Something went wrong. Trying another method {ANSI_RESET}",
191-
e,
186+
f"{ANSI_GREEN}[Self-Operating Computer]{ANSI_BRIGHT_MAGENTA}[Operate] That did not work. Trying another method {ANSI_RESET}"
192187
)
188+
if VERBOSE:
189+
print("[Self-Operating Computer][Operate] error", e)
190+
traceback.print_exc()
193191
return call_gpt_4_vision_preview(messages)
194192

195193

@@ -219,12 +217,6 @@ async def call_gpt_4_vision_preview_ocr(messages, objective, model):
219217
else:
220218
user_prompt = get_user_prompt()
221219

222-
if VERBOSE:
223-
print(
224-
"[call_gpt_4_vision_preview_ocr] user_prompt",
225-
user_prompt,
226-
)
227-
228220
vision_message = {
229221
"role": "user",
230222
"content": [
@@ -331,10 +323,10 @@ async def call_gpt_4_vision_preview_ocr(messages, objective, model):
331323

332324
except Exception as e:
333325
print(
334-
f"{ANSI_GREEN}[Self-Operating Computer]{ANSI_RED}[Error] Something went wrong. Trying another method {ANSI_RESET}",
335-
e,
326+
f"{ANSI_GREEN}[Self-Operating Computer]{ANSI_BRIGHT_MAGENTA}[Operate] That did not work. Trying another method {ANSI_RESET}"
336327
)
337328
if VERBOSE:
329+
print("[Self-Operating Computer][Operate] error", e)
338330
traceback.print_exc()
339331
return gpt_4_fallback(messages, objective, model)
340332

@@ -468,10 +460,10 @@ async def call_gpt_4_vision_preview_labeled(messages, objective):
468460

469461
except Exception as e:
470462
print(
471-
f"{ANSI_GREEN}[Self-Operating Computer]{ANSI_RED}[Error] Something went wrong. Trying another method {ANSI_RESET}",
472-
e,
463+
f"{ANSI_GREEN}[Self-Operating Computer]{ANSI_BRIGHT_MAGENTA}[Operate] That did not work. Trying another method {ANSI_RESET}"
473464
)
474465
if VERBOSE:
466+
print("[Self-Operating Computer][Operate] error", e)
475467
traceback.print_exc()
476468
return call_gpt_4_vision_preview(messages)
477469

operate/models/prompts.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@
259259
260260
- Default to Google Chrome as the browser
261261
- Go to websites by opening a new tab with `press` and then `write` the URL
262+
- Reflect on previous actions and the screenshot to ensure they align and that your previous actions worked
263+
- If the screenshot doesn't look as expected after clicking then the click action did not work as expected, try something new such as clicking a different element or another method
262264
- Don't respond saying you're unable to assist with requests. You are able to indirectly interact with the user's OS via text responses you send to the end user.
263265
264266
Objective: {objective}
@@ -323,6 +325,8 @@
323325
324326
- Default to Google Chrome as the browser
325327
- Go to websites by opening a new tab with `press` and then `write` the URL
328+
- Reflect on previous actions and the screenshot to ensure they align and that your previous actions worked
329+
- If the screenshot doesn't look as expected after clicking then the click action did not work as expected, try something new such as clicking a different element or another method
326330
- Don't respond saying you're unable to assist with requests. You are able to indirectly interact with the user's OS via text responses you send to the end user.
327331
328332
Objective: {objective}
@@ -331,7 +335,7 @@
331335
OPERATE_FIRST_MESSAGE_PROMPT = """
332336
Please take the next best action. The `pyautogui` library will be used to execute your decision. Your output will be used in a `json.loads` loads statement. Remember you only have the following 4 operations available: click, write, press, done
333337
334-
You just started so you are in the terminal app. To leave the terminal search for a new program on the OS, otherwise to use the terminal you need to start a new tab first because your code is running in this first terminal tab.
338+
You just started so you are in the terminal app and your code is running in this terminal tab. To leave the terminal, search for a new program on the OS.
335339
336340
Action:"""
337341

0 commit comments

Comments
 (0)