|
|
@ -49,6 +49,7 @@ class GoogleSearchAPIWrapper(BaseModel):
|
|
|
|
google_api_key: Optional[str] = None
|
|
|
|
google_api_key: Optional[str] = None
|
|
|
|
google_cse_id: Optional[str] = None
|
|
|
|
google_cse_id: Optional[str] = None
|
|
|
|
k: int = 10
|
|
|
|
k: int = 10
|
|
|
|
|
|
|
|
siterestrict: bool = False
|
|
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
class Config:
|
|
|
|
"""Configuration for this pydantic object."""
|
|
|
|
"""Configuration for this pydantic object."""
|
|
|
@ -56,11 +57,10 @@ class GoogleSearchAPIWrapper(BaseModel):
|
|
|
|
extra = Extra.forbid
|
|
|
|
extra = Extra.forbid
|
|
|
|
|
|
|
|
|
|
|
|
def _google_search_results(self, search_term: str, **kwargs: Any) -> List[dict]:
|
|
|
|
def _google_search_results(self, search_term: str, **kwargs: Any) -> List[dict]:
|
|
|
|
res = (
|
|
|
|
cse = self.search_engine.cse()
|
|
|
|
self.search_engine.cse()
|
|
|
|
if self.siterestrict:
|
|
|
|
.list(q=search_term, cx=self.google_cse_id, **kwargs)
|
|
|
|
cse = cse.siterestrict()
|
|
|
|
.execute()
|
|
|
|
res = cse.list(q=search_term, cx=self.google_cse_id, **kwargs).execute()
|
|
|
|
)
|
|
|
|
|
|
|
|
return res.get("items", [])
|
|
|
|
return res.get("items", [])
|
|
|
|
|
|
|
|
|
|
|
|
@root_validator()
|
|
|
|
@root_validator()
|
|
|
|