diff --git a/langchain/utilities/google_search.py b/langchain/utilities/google_search.py index 9b1ec5b6fd..7846c72a33 100644 --- a/langchain/utilities/google_search.py +++ b/langchain/utilities/google_search.py @@ -49,6 +49,7 @@ class GoogleSearchAPIWrapper(BaseModel): google_api_key: Optional[str] = None google_cse_id: Optional[str] = None k: int = 10 + siterestrict: bool = False class Config: """Configuration for this pydantic object.""" @@ -56,11 +57,10 @@ class GoogleSearchAPIWrapper(BaseModel): extra = Extra.forbid def _google_search_results(self, search_term: str, **kwargs: Any) -> List[dict]: - res = ( - self.search_engine.cse() - .list(q=search_term, cx=self.google_cse_id, **kwargs) - .execute() - ) + cse = self.search_engine.cse() + if self.siterestrict: + cse = cse.siterestrict() + res = cse.list(q=search_term, cx=self.google_cse_id, **kwargs).execute() return res.get("items", []) @root_validator()