GoogleSearchAPIWrapper#
- class langchain_community.utilities.google_search.GoogleSearchAPIWrapper[source]#
Bases:
BaseModel
Deprecated since version 0.0.33: Use
:class:`~langchain_google_community.GoogleSearchAPIWrapper`
instead. It will be removed in None==1.0.Wrapper for Google Search API.
Adapted from: Instructions adapted from https://stackoverflow.com/questions/ 37083058/ programmatically-searching-google-in-python-using-custom-search
TODO: DOCS for using it 1. Install google-api-python-client - If you don’t already have a Google account, sign up. - If you have never created a Google APIs Console project, read the Managing Projects page and create a project in the Google API Console. - Install the library using pip install google-api-python-client
2. Enable the Custom Search API - Navigate to the APIs & Services→Dashboard panel in Cloud Console. - Click Enable APIs and Services. - Search for Custom Search API and click on it. - Click Enable. URL for it: https://console.cloud.google.com/apis/library/customsearch.googleapis .com
3. To create an API key: - Navigate to the APIs & Services → Credentials panel in Cloud Console. - Select Create credentials, then select API key from the drop-down menu. - The API key created dialog box displays your newly created key. - You now have an API_KEY
Alternatively, you can just generate an API key here: https://developers.google.com/custom-search/docs/paid_element#api_key
4. Setup Custom Search Engine so you can search the entire web - Create a custom search engine here: https://programmablesearchengine.google.com/. - In What to search to search, pick the Search the entire Web option. After search engine is created, you can click on it and find Search engine ID
on the Overview page.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- param google_api_key: str | None = None#
- param google_cse_id: str | None = None#
- param k: int = 10#
- param siterestrict: bool = False#
- results(query: str, num_results: int, search_params: Dict[str, str] | None = None) List[Dict] [source]#
Run query through GoogleSearch and return metadata.
- Parameters:
query (str) – The query to search for.
num_results (int) – The number of results to return.
search_params (Dict[str, str] | None) – Parameters to be passed on search
- Returns:
snippet - The description of the result. title - The title of the result. link - The link to the result.
- Return type:
A list of dictionaries with the following keys
Examples using GoogleSearchAPIWrapper