Skip to content

Commit

Permalink
Merge pull request #80 from PathOnAI/replay-cleanup
Browse files Browse the repository at this point in the history
fix a bug in action to to_python_code, when no bid, skip high element
  • Loading branch information
IBMC265 authored Sep 25, 2024
2 parents fa68c8f + a1811d4 commit eece7b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 7 additions & 3 deletions litewebagent/action/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 2 additions & 3 deletions litewebagent/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit eece7b2

Please sign in to comment.