Amalia commited on
Commit ·
574f383
1
Parent(s): db859b9
tavily is just generating problems for me
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import gradio as gr
|
|
| 4 |
import requests
|
| 5 |
import inspect
|
| 6 |
import pandas as pd
|
|
|
|
| 7 |
from smolagents import CodeAgent, tool, InferenceClientModel
|
| 8 |
from langchain_community.tools.tavily_search import TavilySearchResults
|
| 9 |
from langchain_community.document_loaders import WikipediaLoader, ArxivLoader
|
|
@@ -53,18 +54,13 @@ def modulus(a: int, b: int) -> int:
|
|
| 53 |
return a % b
|
| 54 |
|
| 55 |
@tool
|
| 56 |
-
def web_search(query: str) -> str:
|
| 57 |
"""Search Tavily for a query and return maximum 3 results.
|
| 58 |
-
|
| 59 |
Args:
|
| 60 |
-
query: The search query.
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
|
| 65 |
-
for doc in search_docs
|
| 66 |
-
])
|
| 67 |
-
return {"web_results": formatted_search_docs}
|
| 68 |
|
| 69 |
@tool
|
| 70 |
def arxiv_search(query: str) -> str:
|
|
|
|
| 4 |
import requests
|
| 5 |
import inspect
|
| 6 |
import pandas as pd
|
| 7 |
+
from typing import Dict, List
|
| 8 |
from smolagents import CodeAgent, tool, InferenceClientModel
|
| 9 |
from langchain_community.tools.tavily_search import TavilySearchResults
|
| 10 |
from langchain_community.document_loaders import WikipediaLoader, ArxivLoader
|
|
|
|
| 54 |
return a % b
|
| 55 |
|
| 56 |
@tool
|
| 57 |
+
def web_search(query: str, max_results: int) -> Dict[str, str]:
|
| 58 |
"""Search Tavily for a query and return maximum 3 results.
|
|
|
|
| 59 |
Args:
|
| 60 |
+
query: The search query.
|
| 61 |
+
max_results: The maximum number of results to return."""
|
| 62 |
+
search_docs = TavilySearchResults(max_results=max_results).invoke(input=query)
|
| 63 |
+
return {"web_results": search_docs}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
@tool
|
| 66 |
def arxiv_search(query: str) -> str:
|