Spaces:
Runtime error
Runtime error
tools.py
CHANGED
|
@@ -16,7 +16,28 @@ from typing import Optional, Tuple
|
|
| 16 |
from huggingface_hub import list_models
|
| 17 |
from pathlib import Path
|
| 18 |
import json
|
|
|
|
|
|
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def wiki_search(query: str) -> str:
|
| 21 |
"""Search Wikipedia for a query and return maximum 2 results.
|
| 22 |
|
|
|
|
| 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 |
|
| 22 |
+
def excel_search(excel_path: str ) -> str:
|
| 23 |
+
"""Given the path to an excel file, return the excel file contents as raw text.
|
| 24 |
+
|
| 25 |
+
Args:
|
| 26 |
+
excel_path: The path to where the excel file is stored."""
|
| 27 |
+
loader = UnstructuredExcelLoader(excel_path, mode="elements")
|
| 28 |
+
raw_excel_docs = loader.load()
|
| 29 |
+
formatted_search_docs = "\n\n---\n\n".join(
|
| 30 |
+
[
|
| 31 |
+
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
|
| 32 |
+
for doc in raw_excel_docs
|
| 33 |
+
])
|
| 34 |
+
return {"excel_results": formatted_search_docs}
|
| 35 |
+
|
| 36 |
+
excel_search_tool = Tool(
|
| 37 |
+
name="excel_search",
|
| 38 |
+
func=excel_search,
|
| 39 |
+
description="Searches for and retrieves information in an Excel Document using the given path."
|
| 40 |
+
)
|
| 41 |
def wiki_search(query: str) -> str:
|
| 42 |
"""Search Wikipedia for a query and return maximum 2 results.
|
| 43 |
|