Ë
    µŒjb  ã                   ó~   — d Z ddlmZmZmZmZ ddlmZ ddlm	Z	 ddl
mZmZmZ  eddd¬	«       G d
„ de«      «       Zy)zUtil that calls Google Search.é    )ÚAnyÚDictÚListÚOptional)Ú
deprecated)Úget_from_dict_or_env)Ú	BaseModelÚ
ConfigDictÚmodel_validatorz0.0.33z1.0z1langchain_google_community.GoogleSearchAPIWrapper)ÚsinceÚremovalÚalternative_importc            
       ó  — e Zd ZU dZdZeed<   dZee	   ed<   dZ
ee	   ed<   dZeed<   dZeed	<    ed
¬«      Zde	dedee   fd„Z ed¬«      ededefd„«       «       Zde	de	fd„Z	 dde	dedeee	e	f      dee   fd„Zy)ÚGoogleSearchAPIWrapperuY  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.

    NÚsearch_engineÚgoogle_api_keyÚgoogle_cse_idé
   ÚkFÚsiterestrictÚforbid)ÚextraÚsearch_termÚkwargsÚreturnc                 óì   — | j                   j                  «       }| j                  r|j                  «       } |j                  d|| j                  dœ|¤Žj                  «       }|j                  dg «      S )N)ÚqÚcxÚitems© )r   Úcser   Úlistr   ÚexecuteÚget)Úselfr   r   r!   Úress        úu/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/utilities/google_search.pyÚ_google_search_resultsz-GoogleSearchAPIWrapper._google_search_results@   sg   € Ø× Ñ ×$Ñ$Ó&ˆØ×ÒØ×"Ñ"Ó$ˆCØˆc�h‰hÐF˜¨×);Ñ);ÑF¸vÑF×NÑNÓPˆØ�w‰w�w Ó#Ð#ó    Úbefore)ÚmodeÚvaluesc                 ó¬   — t        |dd«      }||d<   t        |dd«      }||d<   	 ddlm}  |dd	|¬
«      }||d<   |S # t        $ r t        d«      ‚w xY w)z?Validate that api key and python package exists in environment.r   ÚGOOGLE_API_KEYr   ÚGOOGLE_CSE_IDr   )Úbuildzqgoogle-api-python-client is not installed. Please install it with `pip install google-api-python-client>=2.100.0`ÚcustomsearchÚv1)ÚdeveloperKeyr   )r   Úgoogleapiclient.discoveryr0   ÚImportError)Úclsr,   r   r   r0   Úservices         r'   Úvalidate_environmentz+GoogleSearchAPIWrapper.validate_environmentG   s†   € ô .ØÐ$Ð&6ó
ˆð $2ˆÐÑ ä,¨V°_ÀoÓVˆØ"/ˆˆÑð	Ý7ñ ˜¨¸>ÔJˆØ")ˆˆÑàˆøô ò 	Üðóð ð	ús	   ¦> ¾AÚqueryc                 óÀ   — g }| j                  || j                  ¬«      }t        |«      dk(  ry|D ]  }d|v sŒ|j                  |d   «       Œ dj	                  |«      S )z0Run query through GoogleSearch and parse result.)Únumr   ú&No good Google Search Result was foundÚsnippetÚ )r(   r   ÚlenÚappendÚjoin)r%   r9   ÚsnippetsÚresultsÚresults        r'   ÚrunzGoogleSearchAPIWrapper.runb   sc   € àˆØ×-Ñ-¨e¸¿¹Ð-Ó@ˆÜˆw‹<˜1ÒØ;ÛˆFØ˜FÒ"Ø—‘  yÑ 1Õ2ð ð �x‰x˜Ó!Ð!r)   Únum_resultsÚsearch_paramsc                 óÀ   — g } | j                   |fd|i|xs i ¤Ž}t        |«      dk(  rddigS |D ]*  }|d   |d   dœ}d|v r|d   |d<   |j                  |«       Œ, |S )	aÕ  Run query through GoogleSearch and return metadata.

        Args:
            query: The query to search for.
            num_results: The number of results to return.
            search_params: Parameters to be passed on search

        Returns:
            A list of dictionaries with the following keys:
                snippet - The description of the result.
                title - The title of the result.
                link - The link to the result.
        r;   r   ÚResultr<   ÚtitleÚlink)rJ   rK   r=   )r(   r?   r@   )r%   r9   rF   rG   Úmetadata_resultsrC   rD   Úmetadata_results           r'   rC   zGoogleSearchAPIWrapper.resultsn   sŸ   € ð& ÐØ-�$×-Ñ-Øñ
Ø"ð
Ø'4Ò':¸ñ
ˆô ˆw‹<˜1ÒØÐGÐHÐIÐIÛˆFà ™Ø˜v™ñˆOð ˜FÑ"Ø-3°IÑ->� 	Ñ*Ø×#Ñ# OÕ4ð ð  Ðr)   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__annotations__r   r   Ústrr   r   Úintr   Úboolr
   Úmodel_configr   Údictr(   r   Úclassmethodr   r8   rE   rC   r    r)   r'   r   r   
   sñ   … ñ$ðL €M�3ÓØ$(€N�H˜S‘MÓ(Ø#'€M�8˜C‘=Ó'Ø€A€sƒKØ€L�$ÓáØô€Lð$°#ð $Àð $ÈÈdÉó $ñ ˜(Ô#Øð¨$ð °3ò ó ó $ðð2
"˜ð 
" ó 
"ð  37ñ	" àð" ð ð" ð    S¨# X¡Ñ/ð	" ð
 
ˆd‰ô" r)   r   N)rQ   Útypingr   r   r   r   Úlangchain_core._api.deprecationr   Úlangchain_core.utilsr   Úpydanticr	   r
   r   r   r    r)   r'   Ú<module>r]      sF   ðÙ $ç ,Ó ,å 6Ý 5ß ;Ñ ;ñ Ø
ØØJôô
A ˜Yó A óñ
A r)   