mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-29 07:19:59 +00:00
This PR upgrades langchain-community to pydantic 2.
* Most of this PR was auto-generated using code mods with gritql
(https://github.com/eyurtsev/migrate-pydantic/tree/main)
* Subsequently, some code was fixed manually due to accommodate
differences between pydantic 1 and 2
Breaking Changes:
- Use TEXTEMBED_API_KEY and TEXTEMBEB_API_URL for env variables for text
embed integrations:
cbea780492
Other changes:
- Added pydantic_settings as a required dependency for community. This
may be removed if we have enough time to convert the dependency into an
optional one.
---------
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
Co-authored-by: Bagatur <baskaryan@gmail.com>
31 lines
976 B
Python
31 lines
976 B
Python
"""Tool for the OpenWeatherMap API."""
|
|
|
|
from typing import Optional
|
|
|
|
from langchain_core.callbacks import CallbackManagerForToolRun
|
|
from langchain_core.tools import BaseTool
|
|
from pydantic import Field
|
|
|
|
from langchain_community.utilities.openweathermap import OpenWeatherMapAPIWrapper
|
|
|
|
|
|
class OpenWeatherMapQueryRun(BaseTool):
|
|
"""Tool that queries the OpenWeatherMap API."""
|
|
|
|
api_wrapper: OpenWeatherMapAPIWrapper = Field(
|
|
default_factory=OpenWeatherMapAPIWrapper # type: ignore[arg-type]
|
|
)
|
|
|
|
name: str = "open_weather_map"
|
|
description: str = (
|
|
"A wrapper around OpenWeatherMap API. "
|
|
"Useful for fetching current weather information for a specified location. "
|
|
"Input should be a location string (e.g. London,GB)."
|
|
)
|
|
|
|
def _run(
|
|
self, location: str, run_manager: Optional[CallbackManagerForToolRun] = None
|
|
) -> str:
|
|
"""Use the OpenWeatherMap tool."""
|
|
return self.api_wrapper.run(location)
|