
    dh                     |    S r SSKrSSKJrJrJr  SSKJr  SSKJ	r	  SSK
JrJrJr  \" SSS	S
9 " S S\5      5       rg)z#Chain that calls Google Places API.    N)AnyDictOptional)
deprecated)get_from_dict_or_env)	BaseModel
ConfigDictmodel_validatorz0.0.33z1.0z1langchain_google_community.GooglePlacesAPIWrapper)sinceremovalalternative_importc                       \ rS rSr% SrSr\\   \S'   Sr	\
\S'   Sr\\   \S'   \" SSS	9r\" S
S9\S\S\
4S j5       5       rS\S\4S jrS\S\\   4S jrS\\\
4   S\\   4S jrSrg)GooglePlacesAPIWrapper   aP  Wrapper around Google Places API.

To use, you should have the ``googlemaps`` python package installed,
 **an API key for the google maps platform**,
 and the environment variable ''GPLACES_API_KEY''
 set with your API key , or pass 'gplaces_api_key'
 as a named parameter to the constructor.

By default, this will return the all the results on the input query.
 You can use the top_k_results argument to limit the number of results.

Example:
    .. code-block:: python


        from langchain_community.utilities import GooglePlacesAPIWrapper
        gplaceapi = GooglePlacesAPIWrapper()
Ngplaces_api_keygoogle_map_clienttop_k_resultsTforbid)arbitrary_types_allowedextrabefore)modevaluesreturnc                     [        USS5      nX!S'    SSKnUR                  U5      US'   U$ ! [         a    [        S5      ef = f)z6Validate that api key is in your environment variable.r   GPLACES_API_KEYr   Nr   z\Could not import googlemaps python package. Please install it with `pip install googlemaps`.)r   
googlemapsClientImportError)clsr   r   r   s       g/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/utilities/google_places_api.pyvalidate_environment+GooglePlacesAPIWrapper.validate_environment-   sk     /%'8
 %4 !	*4*;*;O*LF&'   	C 	s	   - Aqueryc           	         U R                   R                  U5      S   n[        U5      n/ nUS:X  a  gU R                  c  UO[	        X0R                  5      n[        U5       H1  nX%   nU R                  US   5      nUc  M   UR                  U5        M3     SR                  [        U5       VVs/ sH  u  pXUS-    SU 3PM     snn5      $ s  snnf )zDRun Places search and get k number of places that exists that match.resultsr   z@Google Places did not find any places that match the descriptionplace_id
   z. )
r   placeslenr   minrangefetch_place_detailsappendjoin	enumerate)	selfr$   search_resultsnum_to_returnr*   iresultdetailsitems	            r!   runGooglePlacesAPIWrapper.run@   s    //66u=iHN+AU !!) ]$6$67 	 }%A#&F..vj/ABG"g& & yyIf<MN<MQUG2dV,<MNOONs   0C
r'   c                      U R                   R                  U5      nXS'   U R                  U5      nU$ ! [         a#  n[        R
                  " SU 35         S nAg S nAff = f)Nr'   z0An Error occurred while fetching place details: )r   placeformat_place_details	Exceptionloggingerror)r2   r'   place_detailsformatted_detailses        r!   r.   *GooglePlacesAPIWrapper.fetch_place_detailsY   sc    	 2288BM(0*% $ 9 9- H$$ 	MMLQCPQ	s   14 
A!AA!rA   c           
          UR                  S0 5      R                  SS5      nUR                  S0 5      R                  SS5      nUR                  S0 5      R                  SS5      nUR                  S0 5      R                  SS5      nUR                  S0 5      R                  SS5      nU SU S	U S
U SU S3
nU$ ! [         a#  n[        R                  " SU 35         S nAg S nAff = f)Nr6   nameUnknownformatted_addressformatted_phone_numberwebsiter'   z

Address: z
Google place ID: z
Phone: z

Website: z

z2An error occurred while formatting place details: )getr>   r?   r@   )	r2   rA   rF   addressphone_numberrJ   r'   rB   rC   s	            r!   r=   +GooglePlacesAPIWrapper.format_place_detailsc   s   	 $$Xr266vyID#''"599#YG ),,Xr:>>()L $''"599)YOG$((26:::yQH &G9 -$$,: .&{7)4A 
 %$ 	MMNqcRS	s   B<B? ?
C,	C''C, )__name__
__module____qualname____firstlineno____doc__r   r   str__annotations__r   r   r   intr	   model_configr
   classmethodr   r"   r9   r.   r=   __static_attributes__rO       r!   r   r      s    & &*OXc])!s!#'M8C=' $L
 (#$ 3   $"P P P2C HSM $sCx. Xc] r[   r   )rT   r?   typingr   r   r   langchain_core._api.deprecationr   langchain_core.utilsr   pydanticr   r	   r
   r   rO   r[   r!   <module>r`      sI    )  & & 6 5 ; ; 
J
gY g
gr[   