Update tools.py
Browse files
tools.py
CHANGED
|
@@ -60,52 +60,52 @@ class HubStatsTool(Tool):
|
|
| 60 |
return f"Error fetching models for {author}: {str(e)}"
|
| 61 |
|
| 62 |
|
| 63 |
-
@tool
|
| 64 |
-
def search_item_ctrl_f(text: str, nth_result: int = 1) -> str:
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
@tool
|
| 82 |
-
def go_back() -> None:
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
@tool
|
| 88 |
-
def close_popups() -> str:
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
def save_screenshot(step_log: ActionStep, agent: CodeAgent) -> None:
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
| 60 |
return f"Error fetching models for {author}: {str(e)}"
|
| 61 |
|
| 62 |
|
| 63 |
+
# @tool
|
| 64 |
+
# def search_item_ctrl_f(text: str, nth_result: int = 1) -> str:
|
| 65 |
+
# """
|
| 66 |
+
# Searches for text on the current page via Ctrl + F and jumps to the nth occurrence.
|
| 67 |
+
# Args:
|
| 68 |
+
# text: The text to search for
|
| 69 |
+
# nth_result: Which occurrence to jump to (default: 1)
|
| 70 |
+
# """
|
| 71 |
+
# elements = driver.find_elements(By.XPATH, f"//*[contains(text(), '{text}')]")
|
| 72 |
+
# if nth_result > len(elements):
|
| 73 |
+
# raise Exception(f"Match n°{nth_result} not found (only {len(elements)} matches found)")
|
| 74 |
+
# result = f"Found {len(elements)} matches for '{text}'."
|
| 75 |
+
# elem = elements[nth_result - 1]
|
| 76 |
+
# driver.execute_script("arguments[0].scrollIntoView(true);", elem)
|
| 77 |
+
# result += f"Focused on element {nth_result} of {len(elements)}"
|
| 78 |
+
# return result
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
# @tool
|
| 82 |
+
# def go_back() -> None:
|
| 83 |
+
# """Goes back to previous page."""
|
| 84 |
+
# driver.back()
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
# @tool
|
| 88 |
+
# def close_popups() -> str:
|
| 89 |
+
# """
|
| 90 |
+
# Closes any visible modal or pop-up on the page. Use this to dismiss pop-up windows! This does not work on cookie consent banners.
|
| 91 |
+
# """
|
| 92 |
+
# webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
# def save_screenshot(step_log: ActionStep, agent: CodeAgent) -> None:
|
| 96 |
+
# sleep(1.0) # Let JavaScript animations happen before taking the screenshot
|
| 97 |
+
# driver = helium.get_driver()
|
| 98 |
+
# current_step = step_log.step_number
|
| 99 |
+
# if driver is not None:
|
| 100 |
+
# for step_logs in agent.logs: # Remove previous screenshots from logs for lean processing
|
| 101 |
+
# if isinstance(step_log, ActionStep) and step_log.step_number <= current_step - 2:
|
| 102 |
+
# step_logs.observations_images = None
|
| 103 |
+
# png_bytes = driver.get_screenshot_as_png()
|
| 104 |
+
# image = Image.open(BytesIO(png_bytes))
|
| 105 |
+
# print(f"Captured a browser screenshot: {image.size} pixels")
|
| 106 |
+
# step_log.observations_images = [image.copy()] # Create a copy to ensure it persists, important!
|
| 107 |
+
|
| 108 |
+
# # Update observations with current URL
|
| 109 |
+
# url_info = f"Current url: {driver.current_url}"
|
| 110 |
+
# step_log.observations = url_info if step_logs.observations is None else step_log.observations + "\n" + url_info
|
| 111 |
+
# return
|