Update tools.py
Browse files
tools.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from smolagents import DuckDuckGoSearchTool, VisitWebpageTool, FinalAnswerTool
|
| 2 |
-
from smolagents import Tool
|
| 3 |
import random
|
| 4 |
from huggingface_hub import list_models
|
| 5 |
|
|
@@ -58,3 +58,34 @@ class HubStatsTool(Tool):
|
|
| 58 |
except Exception as e:
|
| 59 |
return f"Error fetching models for {author}: {str(e)}"
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from smolagents import DuckDuckGoSearchTool, VisitWebpageTool, FinalAnswerTool
|
| 2 |
+
from smolagents import Tool, tool
|
| 3 |
import random
|
| 4 |
from huggingface_hub import list_models
|
| 5 |
|
|
|
|
| 58 |
except Exception as e:
|
| 59 |
return f"Error fetching models for {author}: {str(e)}"
|
| 60 |
|
| 61 |
+
|
| 62 |
+
@tool
|
| 63 |
+
def search_item_ctrl_f(text: str, nth_result: int = 1) -> str:
|
| 64 |
+
"""
|
| 65 |
+
Searches for text on the current page via Ctrl + F and jumps to the nth occurrence.
|
| 66 |
+
Args:
|
| 67 |
+
text: The text to search for
|
| 68 |
+
nth_result: Which occurrence to jump to (default: 1)
|
| 69 |
+
"""
|
| 70 |
+
elements = driver.find_elements(By.XPATH, f"//*[contains(text(), '{text}')]")
|
| 71 |
+
if nth_result > len(elements):
|
| 72 |
+
raise Exception(f"Match n°{nth_result} not found (only {len(elements)} matches found)")
|
| 73 |
+
result = f"Found {len(elements)} matches for '{text}'."
|
| 74 |
+
elem = elements[nth_result - 1]
|
| 75 |
+
driver.execute_script("arguments[0].scrollIntoView(true);", elem)
|
| 76 |
+
result += f"Focused on element {nth_result} of {len(elements)}"
|
| 77 |
+
return result
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
@tool
|
| 81 |
+
def go_back() -> None:
|
| 82 |
+
"""Goes back to previous page."""
|
| 83 |
+
driver.back()
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
@tool
|
| 87 |
+
def close_popups() -> str:
|
| 88 |
+
"""
|
| 89 |
+
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.
|
| 90 |
+
"""
|
| 91 |
+
webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
|