Class: Langchain::Tool::Weather
- Inherits:
-
Object
- Object
- Langchain::Tool::Weather
- Extended by:
- Langchain::ToolDefinition
- Defined in:
- lib/langchain/tool/weather.rb
Overview
A weather tool that gets current weather data
Current weather data is free for 1000 calls per day (home.openweathermap.org/api_keys) Forecast and historical data require registration with credit card, so not supported yet.
Usage:
weather = Langchain::Tool::Weather.new(api_key: ENV["OPEN_WEATHER_API_KEY"])
assistant = Langchain::Assistant.new(
llm: llm,
tools: [weather]
)
Instance Method Summary collapse
- #get_current_weather(city:, state_code:, country_code: nil, units: "imperial") ⇒ Object
-
#initialize(api_key:) ⇒ Weather
constructor
A new instance of Weather.
Methods included from Langchain::ToolDefinition
define_function, function_schemas, tool_name
Constructor Details
#initialize(api_key:) ⇒ Weather
Returns a new instance of Weather.
40 41 42 |
# File 'lib/langchain/tool/weather.rb', line 40 def initialize(api_key:) @api_key = api_key end |
Instance Method Details
#get_current_weather(city:, state_code:, country_code: nil, units: "imperial") ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/langchain/tool/weather.rb', line 44 def get_current_weather(city:, state_code:, country_code: nil, units: "imperial") validate_input(city: city, state_code: state_code, country_code: country_code, units: units) Langchain.logger.debug("#{self.class} - get_current_weather #{{city:, state_code:, country_code:, units:}}") fetch_current_weather(city: city, state_code: state_code, country_code: country_code, units: units) end |