Spaces:
Runtime error
Runtime error
tools.py
CHANGED
|
@@ -16,9 +16,8 @@ from typing import Optional, Tuple
|
|
| 16 |
from huggingface_hub import list_models
|
| 17 |
from pathlib import Path
|
| 18 |
import json
|
| 19 |
-
from langchain_community.tools.tavily_search import TavilySearchResults
|
| 20 |
from langchain_community.document_loaders import UnstructuredExcelLoader
|
| 21 |
-
from
|
| 22 |
|
| 23 |
def excel_search(excel_path: str ) -> str:
|
| 24 |
"""Given the path to an excel file, return the excel file contents as raw text.
|
|
@@ -59,17 +58,18 @@ wiki_search_tool = Tool(
|
|
| 59 |
)
|
| 60 |
|
| 61 |
def web_search(query: str) -> str:
|
| 62 |
-
"""Search Tavily for a query and return maximum
|
| 63 |
|
| 64 |
Args:
|
| 65 |
query: The search query."""
|
| 66 |
-
search_docs =
|
| 67 |
formatted_search_docs = "\n\n---\n\n".join(
|
| 68 |
[
|
| 69 |
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
|
| 70 |
for doc in search_docs
|
| 71 |
])
|
| 72 |
return {"web_results": formatted_search_docs}
|
|
|
|
| 73 |
web_search_tool = Tool(
|
| 74 |
name="web_search",
|
| 75 |
func=web_search,
|
|
|
|
| 16 |
from huggingface_hub import list_models
|
| 17 |
from pathlib import Path
|
| 18 |
import json
|
|
|
|
| 19 |
from langchain_community.document_loaders import UnstructuredExcelLoader
|
| 20 |
+
from langchain_tavily import TavilySearch
|
| 21 |
|
| 22 |
def excel_search(excel_path: str ) -> str:
|
| 23 |
"""Given the path to an excel file, return the excel file contents as raw text.
|
|
|
|
| 58 |
)
|
| 59 |
|
| 60 |
def web_search(query: str) -> str:
|
| 61 |
+
"""Search Tavily for a query and return maximum 5 results. Make sure to format the args as query, not arg1.
|
| 62 |
|
| 63 |
Args:
|
| 64 |
query: The search query."""
|
| 65 |
+
search_docs = TavilySearch(max_results=5, topic="general", include_answer=True, include_image_descriptions=True).invoke(query=query)
|
| 66 |
formatted_search_docs = "\n\n---\n\n".join(
|
| 67 |
[
|
| 68 |
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
|
| 69 |
for doc in search_docs
|
| 70 |
])
|
| 71 |
return {"web_results": formatted_search_docs}
|
| 72 |
+
|
| 73 |
web_search_tool = Tool(
|
| 74 |
name="web_search",
|
| 75 |
func=web_search,
|