Spaces:
Build error
Build error
File size: 800 Bytes
837e221 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
from typing import List, Dict, Any
import re
from smolagents import tool
@tool
def find_in_page(page_content: Dict[str, Any], query: str) -> List[str]:
"""
Find occurrences of a query string in page content.
Args:
page_content: Page content returned by browse_webpage
query: String to search for in the page
Returns:
List of sentences or sections containing the query
"""
results = []
if "content" in page_content:
content = page_content["content"]
# Split content into sentences
sentences = re.split(r"(?<=[.!?])\s+", content)
# Find sentences containing the query
for sentence in sentences:
if query.lower() in sentence.lower():
results.append(sentence)
return results |