Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1168,7 +1168,7 @@ def knowledge_base_tool(query: str):
|
|
| 1168 |
@tool
|
| 1169 |
def google_search_tool(query: str):
|
| 1170 |
"""Perform a Google search using the SERPER API."""
|
| 1171 |
-
return
|
| 1172 |
|
| 1173 |
|
| 1174 |
# Initialize Redis connection
|
|
@@ -1205,12 +1205,12 @@ tavily_tool = TavilySearchResults(
|
|
| 1205 |
exclude_domains=['example.com'],
|
| 1206 |
)
|
| 1207 |
|
| 1208 |
-
def validate_tavily_results(
|
| 1209 |
"""
|
| 1210 |
Fetch and validate results from TavilySearchResults.
|
| 1211 |
Ensures that results do not lead to 'Page Not Found' pages.
|
| 1212 |
"""
|
| 1213 |
-
results = tavily_tool.search()
|
| 1214 |
valid_results = []
|
| 1215 |
|
| 1216 |
for result in results:
|
|
@@ -1241,12 +1241,17 @@ def validate_tavily_results(tavily_tool):
|
|
| 1241 |
|
| 1242 |
return valid_results
|
| 1243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1244 |
|
| 1245 |
|
| 1246 |
#Compile all tool functions into a list
|
| 1247 |
tools = [
|
| 1248 |
knowledge_base_tool, # Tool for querying the knowledge base and retrieving responses
|
| 1249 |
-
|
| 1250 |
#google_search_tool, # Tool for performing a Google search and retrieving search result snippets
|
| 1251 |
]
|
| 1252 |
|
|
|
|
| 1168 |
@tool
|
| 1169 |
def google_search_tool(query: str):
|
| 1170 |
"""Perform a Google search using the SERPER API."""
|
| 1171 |
+
return tavily_tool_with_validation(query)
|
| 1172 |
|
| 1173 |
|
| 1174 |
# Initialize Redis connection
|
|
|
|
| 1205 |
exclude_domains=['example.com'],
|
| 1206 |
)
|
| 1207 |
|
| 1208 |
+
def validate_tavily_results(query):
|
| 1209 |
"""
|
| 1210 |
Fetch and validate results from TavilySearchResults.
|
| 1211 |
Ensures that results do not lead to 'Page Not Found' pages.
|
| 1212 |
"""
|
| 1213 |
+
results = tavily_tool.search(query=query)
|
| 1214 |
valid_results = []
|
| 1215 |
|
| 1216 |
for result in results:
|
|
|
|
| 1241 |
|
| 1242 |
return valid_results
|
| 1243 |
|
| 1244 |
+
# Define a custom tool for Tavily
|
| 1245 |
+
def tavily_tool_with_validation(query):
|
| 1246 |
+
valid_results = validate_tavily_results(query)
|
| 1247 |
+
return "\n".join([f"{res.get('title')}: {res.get('url')}" for res in valid_results])
|
| 1248 |
+
|
| 1249 |
|
| 1250 |
|
| 1251 |
#Compile all tool functions into a list
|
| 1252 |
tools = [
|
| 1253 |
knowledge_base_tool, # Tool for querying the knowledge base and retrieving responses
|
| 1254 |
+
google_search_tool,
|
| 1255 |
#google_search_tool, # Tool for performing a Google search and retrieving search result snippets
|
| 1256 |
]
|
| 1257 |
|