
    Ng                         d Z ddlZddl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 )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                      e Zd ZU dZdZee         ed<   dZe	ed<   dZ
ee         ed<    edd          Z ed	
          edede	fd                        ZdedefdZdedee         fdZdeee	f         dee         fdZdS )GooglePlacesAPIWrappera  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                     t          |dd          }||d<   	 ddl}|                    |          |d<   n# t          $ r t          d          w xY w|S )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       k/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/utilities/google_places_api.pyvalidate_environmentz+GooglePlacesAPIWrapper.validate_environment-   s     /%'8
 
 %4 !	*4*;*;O*L*LF&'' 	 	 	C  	
 s	   5 Aqueryc                    | j                             |          d         }t          |          }g }|dk    rdS | j        |nt	          || j                  }t          |          D ]<}||         }|                     |d                   }||                    |           =d                    d t          |          D                       S )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 descriptionNplace_id
c                 (    g | ]\  }}|d z    d| S )   z.  ).0iitems      r    
<listcomp>z.GooglePlacesAPIWrapper.run.<locals>.<listcomp>W   s.    LLLwq$QqS**D**LLL    )
r   placeslenr   minrangefetch_place_detailsappendjoin	enumerate)selfr"   search_resultsnum_to_returnr/   r+   resultdetailss           r    runzGooglePlacesAPIWrapper.run@   s    /66u==iHN++AUU !) M]D$677 	 }%% 	' 	'A#A&F..vj/ABBG"g&&&yyLL)F:K:KLLLMMMr.   r%   c                     	 | j                             |          }||d<   |                     |          }|S # t          $ r"}t	          j        d|            Y d }~d S d }~ww xY w)Nr%   z0An Error occurred while fetching place details: )r   placeformat_place_details	Exceptionloggingerror)r7   r%   place_detailsformatted_detailses        r    r3   z*GooglePlacesAPIWrapper.fetch_place_detailsY   s    	 288BBM(0M*% $ 9 9- H H$$ 	 	 	MPQPPQQQ44444	s   58 
A$AA$rC   c           
      ,   	 |                     di                                dd          }|                     di                                dd          }|                     di                                dd          }|                     di                                dd          }|                     di                                dd          }| d| d	| d
| d| d
}|S # t          $ r"}t          j        d|            Y d }~d S d }~ww xY w)Nr:   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@   rA   rB   )	r7   rC   rG   addressphone_numberrK   r%   rD   rE   s	            r    r?   z+GooglePlacesAPIWrapper.format_place_detailsc   sr   	 $$Xr2266vyIID#''"5599#Y G ),,Xr::>>() L $''"5599)YOOG$((266:::yQQH  A AG A A$,A A&A A3:A A A 
 %$ 	 	 	MRqRRSSS44444	s   C$C' '
D1DD)__name__
__module____qualname____doc__r   r   str__annotations__r   r   r   intr	   model_configr
   classmethodr   r!   r<   r3   r?   r)   r.   r    r   r      s9         & &*OXc])))!s!!!#'M8C=''': $  L
 _(###$ 3    [ $#"N N N N N N2C HSM    $sCx. Xc]      r.   r   )rR   rA   typingr   r   r   langchain_core._api.deprecationr   langchain_core.utilsr   pydanticr   r	   r
   r   r)   r.   r    <module>r\      s    ) )  & & & & & & & & & & 6 6 6 6 6 6 5 5 5 5 5 5 ; ; ; ; ; ; ; ; ; ; 
J  
g g g g gY g g 
g g gr.   