Spaces:
Build error
Build error
File size: 1,742 Bytes
aa8ca9f 7e9feed aa8ca9f 7e9feed | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import os
import requests
from smolagents import tool
import arxiv
@tool
def search_in_google(query: str) -> str:
"""
Perform a Google search using the provided query and return the first result.
Args:
query (str): The search query to perform a web search on Google.
"""
GOOGLE_CUSTOM_SEARCH_API_KEY = os.getenv("GOOGLE_CUSTOM_SEARCH_API_KEY")
GOOGLE_CUSTOM_SEARCH_SEARCH_ENGINE_ID = os.getenv("GOOGLE_CUSTOM_SEARCH_SEARCH_ENGINE_ID")
response = requests.get(f"https://www.googleapis.com/customsearch/v1?key={GOOGLE_CUSTOM_SEARCH_API_KEY}&cx={GOOGLE_CUSTOM_SEARCH_SEARCH_ENGINE_ID}&q={query}")
response_json = response.json()
search_results = response_json.get("items", [])
processed_results = []
for result in search_results:
title = result.get("title")
link = result.get("link")
snippet = result.get("snippet")
processed_results.append(f"Title: {title}\nLink: {link}\nSnippet: {snippet}\n")
return "\n".join(processed_results)
@tool
def search_in_arxiv(query: str) -> str:
"""
Perform a search in arXiv for research articles using the provided query and return the first result.
Args:
query (str): The search query to perform a web search on arXiv.
"""
search = arxiv.Search(
query=query,
max_results=10,
sort_by=arxiv.SortCriterion.SubmittedDate,
sort_order=arxiv.SortOrder.Descending,
)
results = list(search.results())
processed_results = []
# Display metadata and summaries
for doc in results:
processed_results.append(f"Title: {doc.title}\nSummary: {doc.summary}\nLink: {doc.entry_id}\n")
return "\n".join(processed_results) |