math / tools /serpapi_tools.py
vimj1915's picture
Update tools/serpapi_tools.py
82fe4f3 verified
Raw History Blame Contribute Delete
464 Bytes
# tools/serpapi_tools.py
import os
from serpapi import GoogleSearch # ✅ Correct import
def search_serpapi(query: str):
"""
Use SerpAPI to search Google and return organic results.
"""
search = GoogleSearch({
"q": query,
"location": "United States",
"hl": "en",
"gl": "us",
"api_key": os.getenv("SERPAPI_API_KEY")
})
results = search.get_dict()
return results.get("organic_results", [])