§
    šŠtj|  ã                   ó’   — 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dS )zEDO NOT USE. Kept for backward compatibility for web search retriever.é    )Ú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            
       óB  — 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dS )ÚGoogleSearchAPIWrapperu[  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        r|                     ¦   «         } |j        d|| j        dœ|¤Ž                     ¦   «         }|                     dg ¦  «        S )N)ÚqÚcxÚitems© )r   Úcser   Úlistr   ÚexecuteÚget)Úselfr   r   r!   Úress        úi/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/utilities/google_search.pyÚ_google_search_resultsz-GoogleSearchAPIWrapper._google_search_resultsD   ss   € ØÔ ×$Ò$Ñ&Ô&ˆØÔð 	%Ø×"Ò"Ñ$Ô$ˆCØˆcŒhÐF˜¨Ô);ÐFÐF¸vÐFÐF×NÒNÑPÔPˆØ�wŠw�w Ñ#Ô#Ð#ó    Úbefore)ÚmodeÚvaluesc                 óÎ   — t          |dd¦  «        }||d<   t          |dd¦  «        }||d<   	 ddlm} n# t          $ r t          d¦  «        ‚w xY w |dd	|¬
¦  «        }||d<   |S )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_environmentK   s·   € õ .ØÐ$Ð&6ñ
ô 
ˆð $2ˆÐÑ å,¨V°_ÀoÑVÔVˆØ"/ˆˆÑð	Ø7Ð7Ð7Ð7Ð7Ð7Ð7øåð 	ð 	ð 	Ýðñô ð ð	øøøð �%˜¨¸>ÐJÑJÔJˆØ")ˆˆÑàˆs	   ®5 µAÚqueryc                 óÚ   — g }|                       || j        ¬¦  «        }t          |¦  «        dk    rdS |D ]!}d|v r|                     |d         ¦  «         Œ"d                     |¦  «        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.runf   s|   € àˆØ×-Ò-¨e¸¼Ð-Ñ@Ô@ˆÝˆw‰<Œ<˜1ÒÐØ;Ð;Øð 	3ð 	3ˆFØ˜FÐ"Ð"Ø—’  yÔ 1Ñ2Ô2Ð2øà�xŠx˜Ñ!Ô!Ð!r)   Únum_resultsÚsearch_paramsc                 óÒ   — g } | j         |fd|i|pi ¤Ž}t          |¦  «        dk    rddigS |D ]7}|d         |d         dœ}d|v r|d         |d<   |                     |¦  «         Œ8|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.resultsr   s¿   € ð& ÐØ-�$Ô-Øð
ð 
Ø"ð
Ø'4Ð':¸ð
ð 
ˆõ ˆw‰<Œ<˜1ÒÐØÐGÐHÐIÐIØð 	5ð 	5ˆFà œØ˜vœðð ˆOð ˜FÐ"Ð"Ø-3°IÔ->� 	Ñ*Ø×#Ò# OÑ4Ô4Ð4Ð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€K�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]      sØ   ðØ KÐ Kà ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,à 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;ð €Ø
ØØJðñ ô ð
E ð E ð E ð E ð E ˜Yñ E ô E ñô ð
E ð E ð E r)   