Denis Davydov
commited on
Commit
·
f68e095
1
Parent(s):
31ed54e
remove unused functions
Browse files
tools.py
CHANGED
@@ -20,71 +20,6 @@ from dotenv import load_dotenv
|
|
20 |
# Load environment variables
|
21 |
load_dotenv()
|
22 |
|
23 |
-
def search_wikipedia(query: str) -> str:
|
24 |
-
"""Search Wikipedia specifically for factual information."""
|
25 |
-
try:
|
26 |
-
with DDGS() as ddgs:
|
27 |
-
# Try multiple Wikipedia search strategies
|
28 |
-
search_queries = [
|
29 |
-
f"site:en.wikipedia.org {query}", # English Wikipedia specifically
|
30 |
-
f"{query} site:wikipedia.org", # Alternative format
|
31 |
-
f"{query} wikipedia" # General Wikipedia search
|
32 |
-
]
|
33 |
-
|
34 |
-
for search_query in search_queries:
|
35 |
-
try:
|
36 |
-
results = list(ddgs.text(search_query, max_results=3))
|
37 |
-
|
38 |
-
if results:
|
39 |
-
# Filter for relevant Wikipedia results
|
40 |
-
wiki_results = []
|
41 |
-
for result in results:
|
42 |
-
title = result.get('title', 'No title')
|
43 |
-
body = result.get('body', 'No content')
|
44 |
-
url = result.get('href', '')
|
45 |
-
|
46 |
-
# Only include if it's actually Wikipedia and relevant
|
47 |
-
if 'wikipedia.org' in url.lower() and any(term in title.lower() or term in body.lower() for term in query.lower().split()):
|
48 |
-
wiki_results.append(f"Title: {title}\nContent: {body}\nSource: {url}\n")
|
49 |
-
|
50 |
-
if wiki_results:
|
51 |
-
return "\n---\n".join(wiki_results)
|
52 |
-
|
53 |
-
except Exception:
|
54 |
-
continue # Try next search query
|
55 |
-
|
56 |
-
return "" # No good results found
|
57 |
-
|
58 |
-
except Exception as e:
|
59 |
-
return f"Wikipedia search failed: {str(e)}"
|
60 |
-
|
61 |
-
def search_general(query: str) -> str:
|
62 |
-
"""General web search as fallback."""
|
63 |
-
try:
|
64 |
-
with DDGS() as ddgs:
|
65 |
-
results = list(ddgs.text(query, max_results=5))
|
66 |
-
|
67 |
-
if not results:
|
68 |
-
return ""
|
69 |
-
|
70 |
-
# Format general results
|
71 |
-
formatted_results = []
|
72 |
-
for result in results:
|
73 |
-
title = result.get('title', 'No title')
|
74 |
-
body = result.get('body', 'No content')
|
75 |
-
url = result.get('href', '')
|
76 |
-
|
77 |
-
# Prioritize reliable sources
|
78 |
-
if any(domain in url.lower() for domain in ['wikipedia.org', 'britannica.com', 'edu', 'gov']):
|
79 |
-
formatted_results.insert(0, f"Title: {title}\nContent: {body}\nSource: {url}\n")
|
80 |
-
else:
|
81 |
-
formatted_results.append(f"Title: {title}\nContent: {body}\nSource: {url}\n")
|
82 |
-
|
83 |
-
return "\n---\n".join(formatted_results)
|
84 |
-
|
85 |
-
except Exception as e:
|
86 |
-
return f"General search failed: {str(e)}"
|
87 |
-
|
88 |
def file_download_tool_func(task_id: str) -> str:
|
89 |
"""Downloads a file associated with a GAIA task ID."""
|
90 |
try:
|
|
|
20 |
# Load environment variables
|
21 |
load_dotenv()
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def file_download_tool_func(task_id: str) -> str:
|
24 |
"""Downloads a file associated with a GAIA task ID."""
|
25 |
try:
|