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

(Bug Fix) Fixes ModuleNotFoundError: No module named 'playwright._imp… #20

Closed
wants to merge 6 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def step(self, action):
if action_name == 'search':
try:
search_bar = self.browser.find_element_by_id('search_input')
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception:
pass
else:
Expand Down Expand Up @@ -95,6 +97,8 @@ def get_available_actions(self):
# Determine if a search bar is available
try:
search_bar = self.browser.find_element_by_id('search_input')
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception:
has_search_bar = False
else:
Expand Down
4 changes: 4 additions & 0 deletions agentboard/environment/academia_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def step(self, action, action_path=None):
action_path = self.action_path
try:
action_type, params = parse_action(action)
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
observation = "ERROR | " + type(e).__name__ + "(" + str(e) + ")"
done = False
Expand All @@ -121,6 +123,8 @@ def step(self, action, action_path=None):
observation = "You can use following valid actions: {}".format(self.get_action_space(with_input=False))
else:
observation = "ERROR | Invalid action: {}.".format(action_type)
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
observation = "ERROR | " + type(e).__name__ + "(" + str(e) + ")"
done = False
Expand Down
4 changes: 4 additions & 0 deletions agentboard/environment/browser_env/async_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,16 @@ async def astep(
try:
self.page = await aexecute_action(action, self.page, self.context)
success = True
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
fail_error = str(e)

try:
content = await self.page.content()
screenshot = png_bytes_to_numpy(await self.page.screenshot())
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except:
await self.page.wait_for_load_state("load")
content = await self.page.content()
Expand Down
4 changes: 4 additions & 0 deletions agentboard/environment/browser_env/envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ def step(
self.observation_handler.action_processor,
)
success = True
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
fail_error = str(e)

Expand Down Expand Up @@ -354,6 +356,8 @@ def step(
self.progress_score = progress_score
self.progress_content = content_set
self.reward = self.progress_score
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
print(f"Progress score ERROR: {str(e)}")
#####
Expand Down
12 changes: 12 additions & 0 deletions agentboard/environment/browser_env/evaluation_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ def gitlab_get_project_memeber_role(page: Page, account_name: str) -> str:
return document.querySelectorAll("td.col-max-role span")[{account_idx}].outerText;
}})()"""
)
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception:
role = ""

Expand Down Expand Up @@ -213,6 +215,8 @@ def __call__(
def get_last_action(trajectory: Trajectory) -> Action:
try:
last_action = trajectory[-1]
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception:
raise ValueError(
"The last element of trajectory should be an action, add a fake stop action if needed"
Expand All @@ -224,6 +228,8 @@ def get_last_action(trajectory: Trajectory) -> Action:
def get_last_state(trajectory: Trajectory) -> StateInfo:
try:
last_state = trajectory[-2]
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception:
raise ValueError(
"The second last element of trajectory should be a state, add a fake stop action if needed"
Expand Down Expand Up @@ -419,13 +425,17 @@ def __call__(
try:
for prep_action in target["prep_actions"]:
page.evaluate(f"() => {prep_action}")
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception:
pass
try:
selected_element = str(page.evaluate(f"() => {locator}"))
if not selected_element:
selected_element = ""
selected_element = str(selected_element)
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception:
# the page is wrong, return empty
selected_element = ""
Expand Down Expand Up @@ -679,6 +689,8 @@ def clean(text: str) -> str:
if not selected_element:
selected_element = ""
selected_element = str(selected_element)
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception:
# the page is wrong, return empty
selected_element = ""
Expand Down
14 changes: 12 additions & 2 deletions agentboard/environment/browser_env/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def get_bounding_client_rect(
},
)
return response
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
return {"result": {"subtype": "error"}}

Expand Down Expand Up @@ -344,7 +346,8 @@ def dfs(node_cursor: int, depth: int) -> str:
"text": node_str,
}
tree_str += f"{indent}{node_str}\n"

except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
valid_node = False

Expand Down Expand Up @@ -534,7 +537,8 @@ def dfs(idx: int, obs_node_id: str, depth: int) -> str:
"union_bound": node["union_bound"],
"text": node_str,
}

except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
valid_node = False

Expand Down Expand Up @@ -594,13 +598,17 @@ def process(self, page: Page, client: CDPSession) -> str:
else:
tab_titles[idx] = f"Tab {idx}: {open_tabs[idx].title()}"
tab_title_str = " | ".join(tab_titles)
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception:
tab_title_str = " | ".join(
["Tab {idx}" for idx in range(len(open_tabs))]
)

try:
browser_info = self.fetch_browser_info(page, client)
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception:
page.wait_for_load_state("load", timeout=500)
browser_info = self.fetch_browser_info(page, client)
Expand Down Expand Up @@ -660,6 +668,8 @@ def __init__(self, observation_type: str):
def process(self, page: Page, client: CDPSession) -> npt.NDArray[np.uint8]:
try:
screenshot = png_bytes_to_numpy(page.screenshot())
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except:
page.wait_for_event("load")
screenshot = png_bytes_to_numpy(page.screenshot())
Expand Down
4 changes: 4 additions & 0 deletions agentboard/environment/movie_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def step(self, action, action_path=None):
action_path = self.action_path
try:
action_type, params = parse_action(action)
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
observation = "ERROR | " + type(e).__name__ + "(" + str(e) + ")"
done = False
Expand Down Expand Up @@ -143,6 +145,8 @@ def step(self, action, action_path=None):
observation = "You can use following valid actions: {}".format(self.get_action_space(with_input=False))
else:
observation = "ERROR | Invalid action: {}.".format(action_type)
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
observation = "ERROR | " + type(e).__name__ + "(" + str(e) + ")"
done = False
Expand Down
4 changes: 4 additions & 0 deletions agentboard/environment/sheet_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def step(self, action, action_path=None):
action_path = self.action_path
try:
action_type, params = parse_action(action)
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
observation = "ERROR | " + type(e).__name__ + "(" + str(e) + ")"
done = False
Expand Down Expand Up @@ -238,6 +240,8 @@ def step(self, action, action_path=None):
else:
observation = "ERROR | Invalid action: {}. Please choose another valid action from {}".format(action_type,
self.get_action_space())
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
observation_space = self.sheet_toolkits.get_all_values()[1]
self.observation_space = observation_space
Expand Down
11 changes: 8 additions & 3 deletions agentboard/environment/todo_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ def __init__(self, dataset):
try:
self.todo_toolkits = todo_toolkits()
break
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
print(f"Error on attempt {attempt + 1} to initialize todo_toolkits.")
if attempt < 4: # If not the last attempt
time.sleep(10) # Wait before retrying
else:
print("Failed to initialize todo_toolkits after multiple attempts.")
raise e

raise SystemExit("Failed to initialize todo_toolkits after multiple attempts.") from e

self.dataset = dataset
self.reset()

Expand Down Expand Up @@ -98,6 +99,8 @@ def step(self, action, action_path=None):
action_path = self.action_path
try:
action_type, params = parse_action(action)
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
observation = "ERROR | " + type(e).__name__ + "(" + str(e) + ")"
done = False
Expand Down Expand Up @@ -130,6 +133,8 @@ def step(self, action, action_path=None):
observation = "You can use following valid actions: {}".format(self.get_action_space(with_input=False))
else:
observation = "ERROR | Invalid action: {}.".format(action_type)
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
observation = "ERROR | " + type(e).__name__ + "(" + str(e) + ")"
done = False
Expand Down
4 changes: 4 additions & 0 deletions agentboard/environment/weather_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def step(self, action, action_path=None):
action_path = self.action_path
try:
action_type, params = parse_action(action)
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
observation = "ERROR | " + type(e).__name__ + "(" + str(e) + ")"
done = False
Expand Down Expand Up @@ -271,6 +273,8 @@ def step(self, action, action_path=None):
observation = "You can use following valid actions: {}".format(self.get_action_space(with_input=False))
else:
observation = "ERROR | Invalid action: {}.".format(action_type)
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
observation = "ERROR | " + type(e).__name__ + "(" + str(e) + ")"
done = False
Expand Down
10 changes: 6 additions & 4 deletions agentboard/llm/azure_gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ def generate(self, system_message, prompt):
output = self.chat_inference(prompt)
output = output.split("\n")[0]
return True, output # return success, completion
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
print(f"Error on attempt {attempt + 1}")
if attempt < self.max_retry_iters - 1: # If not the last attempt
time.sleep(self.retry_delays) # Wait before retrying

else:
print("Failed to get completion after multiple attempts.")
# raise e
raise SystemExit('Failed to get completion after multiple attempts.') from e

return False, None

Expand All @@ -130,15 +131,16 @@ def generate(self, system_message, prompt):
output = self.completion_inference(prompt)
output = output.split("\n")[0]
return True, output # return success, completion
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
print(e)
print(f"Error on attempt {attempt + 1}")
if attempt < self.max_retry_iters - 1: # If not the last attempt
time.sleep(self.retry_delays) # Wait before retrying

else:
print("Failed to get completion after multiple attempts.")
raise e
raise SystemExit('Failed to get completion after multiple attempts.') from e

return False, None

Expand Down
5 changes: 3 additions & 2 deletions agentboard/llm/claude.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ def generate(self, system_message, prompt):
for attempt in range(self.max_retry_iters):
try:
return True, self.llm_inference(prompt) # return success, completion
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
print(f"Error on attempt {attempt + 1}")
if attempt < self.max_retry_iters - 1: # If not the last attempt
time.sleep(self.retry_delays) # Wait before retrying

else:
print("Failed to get completion after multiple attempts.")
raise e
raise SystemExit('Failed to get completion after multiple attempts.') from e

return False, None

Expand Down
5 changes: 3 additions & 2 deletions agentboard/llm/openai_gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ def generate(self, system_message, prompt):
for attempt in range(self.max_retry_iters):
try:
return True, self.llm_inference(prompt) # return success, completion
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except Exception as e:
print(f"Error on attempt {attempt + 1}")
if attempt < self.max_retry_iters - 1: # If not the last attempt
time.sleep(self.retry_delays) # Wait before retrying

else:
print("Failed to get completion after multiple attempts.")
# raise e
raise SystemExit('Failed to get completion after multiple attempts.') from e

return False, None

Expand Down
8 changes: 6 additions & 2 deletions agentboard/tasks/alfworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ def evaluate_env(self, index, ob='', examples=None):

progress_rate = reward

try: example_prompt = self.agent.get_example_prompt()
except: example_prompt = None
try:
example_prompt = self.agent.get_example_prompt()
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except:
example_prompt = None
self.agentboard.log_example(index, done, progress_rate, grounding_acc_count / (i + 1), score_change_record, env_details, trajectory, example_prompt)

return progress_rate, done, grounding_acc_count / (i + 1), score_change_record, i
Expand Down
8 changes: 6 additions & 2 deletions agentboard/tasks/babyai.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,12 @@ def evaluate_env(self, id):


env_details = {"goal": self.agent.goal, "task_name": env.game_name, "difficulty": env.difficulty}
try: example_prompt = self.agent.get_example_prompt()
except: example_prompt = None
try:
example_prompt = self.agent.get_example_prompt()
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except:
example_prompt = None

progress_rate = reward

Expand Down
8 changes: 6 additions & 2 deletions agentboard/tasks/jericho.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,12 @@ def evaluate_env(self, id):
return env.won, progress_rate, step_id + 1, grounding_acc_count / (step_id + 1), score_change_record # return success, completion steps

env_details = {"goal": self.agent.goal, "task_name": env.game_name, "difficulty": env.difficulty}
try: example_prompt = self.agent.get_example_prompt()
except: example_prompt = None
try:
example_prompt = self.agent.get_example_prompt()
except SystemExit as e:
raise SystemExit(f'FATAL ERROR | {type(e).__name__} ({e})') from e
except:
example_prompt = None

progress_rate = reward

Expand Down
Loading