Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced error handling in key functions #97

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions operate/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,9 @@ def get_next_action_from_openai(messages, objective, accurate_mode):
return content

except Exception as e:
print(f"Error parsing JSON: {e}")
return "Failed take action after looking at the screenshot"
return handle_exceptions(e)
# print(f"Error parsing JSON: {e}")
# return "Failed take action after looking at the screenshot"


def parse_oai_response(response):
Expand All @@ -530,7 +531,19 @@ def parse_oai_response(response):

return {"type": "UNKNOWN", "data": response}

def handle_exceptions(e):
error_messages = {
PIL.ImageError: "Error with image processing",
FileNotFoundError: "File not found error",
PermissionError: "Permission denied error",
IOError: "Input/output error",
openai.error.OpenAIError: "OpenAI API error",
requests.exceptions.RequestException: "Request error",
}

error_msg = error_messages.get(type(e), "Unknown error occurred")
print(f"Error: {error_msg}: {e}")
return error_msg
def summarize(messages, objective):
try:
screenshots_dir = "screenshots"
Expand Down Expand Up @@ -569,8 +582,7 @@ def summarize(messages, objective):
return content

except Exception as e:
print(f"Error in summarize: {e}")
return "Failed to summarize the workflow"
return handle_exceptions(e)


def mouse_click(click_detail):
Expand Down