o
    ȳg	                     @   sL   d Z ddlmZmZmZ ddlmZ ddlmZm	Z	m
Z
 G dd deZdS )z+Util that calls OpenWeatherMap using PyOWM.    )AnyDictOptional)get_from_dict_or_env)	BaseModel
ConfigDictmodel_validatorc                   @   s   e Zd ZU dZdZeed< dZee	 ed< e
ddZedded	ed
efddZde	ded
e	fddZde	d
e	fddZdS )OpenWeatherMapAPIWrapperzWrapper for OpenWeatherMap API using PyOWM.

    Docs for using:

    1. Go to OpenWeatherMap and sign up for an API key
    2. Save your API KEY into OPENWEATHERMAP_API_KEY env variable
    3. pip install pyowm
    Nowmopenweathermap_api_keyforbid)extrabefore)modevaluesreturnc                 C   sF   t |dd}zddl}W n ty   tdw ||}||d< |S )z,Validate that api key exists in environment.r   OPENWEATHERMAP_API_KEYr   NzBpyowm is not installed. Please install it with `pip install pyowm`r
   )r   pyowmImportErrorOWM)clsr   r   r   r
    r   h/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/langchain_community/utilities/openweathermap.pyvalidate_environment   s   
z-OpenWeatherMapAPIWrapper.validate_environmentlocationwc           
      C   s   |j }| }|j}|d}|j}|j}|j}	d| d| d|d  d|d  d| d	|d
  d|d  d|d  d|d  d| d| d|	 dS )NcelsiuszIn z6, the current weather is as follows:
Detailed status: z
Wind speed: speedz m/s, direction: degu   °
Humidity: z%
Temperature: 
  - Current: tempu   °C
  - High: temp_maxu   °C
  - Low: temp_minu   °C
  - Feels like: 
feels_likeu
   °C
Rain: z
Heat index: z
Cloud cover: %)detailed_statuswindhumiditytemperaturerain
heat_indexclouds)
selfr   r   r$   r%   r&   r'   r(   r)   r*   r   r   r   _format_weather_info/   s>   
	
z-OpenWeatherMapAPIWrapper._format_weather_infoc                 C   s&   | j  }||}|j}| ||S )z=Get the current weather information for a specified location.)r
   weather_managerweather_at_placeweatherr,   )r+   r   mgrobservationr   r   r   r   runG   s   

zOpenWeatherMapAPIWrapper.run)__name__
__module____qualname____doc__r
   r   __annotations__r   r   strr   model_configr   classmethodr   r   r,   r2   r   r   r   r   r	   	   s   
 	r	   N)r6   typingr   r   r   langchain_core.utilsr   pydanticr   r   r   r	   r   r   r   r   <module>   s
    