File size: 620 Bytes
5ec1ba2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from langchain_community.utilities import GoogleSerperAPIWrapper
from utils.exceptions import CustomException
from utils.logger import logger
import os

class InternetSearchAgent:
    def __init__(self) -> None:
        logger.info("INITIALIZING INTERNET SEARCH AGENT")
        self.search = GoogleSerperAPIWrapper(serper_api_key=os.environ.get("SERPER_API_KEY"))

    def query(self, query) -> str:
        try:
            output = self.search.run(query)
            return output
        except Exception as e:
            exception = CustomException(e)
            logger.error(exception)
            raise exception