From a1811d4971d3beb85aee0eea512e0a1511383695 Mon Sep 17 00:00:00 2001 From: IBMC265 Date: Tue, 24 Sep 2024 23:49:34 -0700 Subject: [PATCH] fix a bug in action to to_python_code, when no bid, skip high element --- litewebagent/action/highlevel.py | 10 +++++++--- litewebagent/utils/utils.py | 5 ++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/litewebagent/action/highlevel.py b/litewebagent/action/highlevel.py index e4931ff..ce0cb0d 100644 --- a/litewebagent/action/highlevel.py +++ b/litewebagent/action/highlevel.py @@ -497,16 +497,20 @@ def extract_bid_from_action(action: str) -> str: if match: return match.group(1) else: - raise ValueError("No bid found in the action string") + return None # Return None if no bid is found # Modified execute_action function def execute_action(action: str): # Extract the bid from the action extracted_code = extract_code(action) bid = extract_bid_from_action(extracted_code) - # Highlight the element - highlight_element_by_bid(page, bid, action) + if bid: + # Highlight the element only if a bid is found + highlight_element_by_bid(page, bid, action) + else: + # Log that no bid was found, no highlight will be made + print("No bid found in the action string. Skipping highlight.") """ python_code += """\n""" python_code += f'action="""{highlevel_code}"""\n' diff --git a/litewebagent/utils/utils.py b/litewebagent/utils/utils.py index ab1e5d0..438226d 100644 --- a/litewebagent/utils/utils.py +++ b/litewebagent/utils/utils.py @@ -221,13 +221,12 @@ def query_openai_model(system_msg, prompt, screenshot_path, num_outputs): def execute_action(action, action_set, page, context, task_description, interactive_elements, log_folder): code, function_calls = action_set.to_python_code(action) for function_name, function_args in function_calls: - print(function_name, function_args) extracted_number = parse_function_args(function_args) result = search_interactive_elements(interactive_elements, extracted_number) - print(result) result['action'] = action result["url"] = page.url result['task_description'] = task_description + logger.info(result) file_path = os.path.join(log_folder, 'flow', 'steps.json') append_to_steps_json(result, file_path) @@ -297,7 +296,7 @@ def search_interactive_elements(interactive_elements, extracted_number): 'title': element.get('title'), 'ariaLabel': element.get('ariaLabel') } - return None # Return None if no matching element is found + return {} # Return empty dictionary if no matching element is found def parse_function_args(function_args):