
    7|h	                     R    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e      Zy)z+Util that calls OpenWeatherMap using PyOWM.    )AnyDictOptional)get_from_dict_or_env)	BaseModel
ConfigDictmodel_validatorc                       e Zd ZU dZdZeed<   dZee	   ed<    e
d      Z ed      ed	ed
efd              Zde	ded
e	fdZde	d
e	fdZy)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                     t        |dd      }	 ddl}|j                  |      }||d<   |S # t        $ r t        d      w xY w)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   s        k/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/utilities/openweathermap.pyvalidate_environmentz-OpenWeatherMapAPIWrapper.validate_environment   s`     "6,.F"
	 ii./u  	T 	s	   + A locationwc                 .   |j                   }|j                         }|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-   s
             r   _format_weather_infoz-OpenWeatherMapAPIWrapper._format_weather_info/   s    ++vvx::mmI.vv\\
 (   /0 1=/):4;- H!
 #'/0 1$Z01 2#J/0 1*<89 :F %, '"81&	
    c                     | j                   j                         }|j                  |      }|j                  }| j	                  ||      S )z=Get the current weather information for a specified location.)r   weather_managerweather_at_placeweatherr/   )r.   r   mgrobservationr   s        r   runzOpenWeatherMapAPIWrapper.runG   sB    hh&&(**84((155r0   )__name__
__module____qualname____doc__r   r   __annotations__r   r   strr   model_configr	   classmethodr   r   r/   r7    r0   r   r   r   	   s     CO,0HSM0L (#$ 3   $&
S 
S 
S 
06C 6C 6r0   r   N)r;   typingr   r   r   langchain_core.utilsr   pydanticr   r   r	   r   r@   r0   r   <module>rD      s%    1 & & 5 ; ;D6y D6r0   