File size: 464 Bytes
6a20b44
 
 
82fe4f3
6a20b44
396c58d
 
 
 
82fe4f3
6a20b44
396c58d
6a20b44
 
396c58d
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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", [])