mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
#1915 https://developers.google.com/custom-search/v1/site_restricted_api It is possible to search unrestricted to specific sites.
This commit is contained in:
parent
c50fafb35d
commit
62e08f80de
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user