Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌤️ feat: Add OpenWeather Tool for Weather Data Retrieval #5246

Merged
merged 6 commits into from
Jan 10, 2025

Conversation

danny-avila
Copy link
Owner

@danny-avila danny-avila commented Jan 10, 2025

Originally #5206

Summary

Added OpenWeather integration as a structured tool for LibreChat. This integration provides:

  • Current weather and forecasts
  • Historical weather data
  • Daily weather summaries
  • Human-readable weather overviews
  • Temperature unit conversion (Celsius, Fahrenheit, Kelvin)
  • Multi-language support for weather descriptions
  • Geocoding support (city names to coordinates)

The tool uses OpenWeather's One Call API 3.0, which offers a free tier with 1,500 API calls per month.

This PR demonstrates rapid plugin development using AI assistance - the entire implementation, including comprehensive tests and documentation, was completed in about 3 hours while multitasking.

Features

  • Current weather and forecasts
  • Historical weather data (back to 1979)
  • Daily weather aggregations
  • Natural language weather summaries
  • Support for multiple temperature units
  • Multi-language support
  • City name or coordinate-based queries
  • Comprehensive error handling
  • Full test coverage

Change Type

Please delete any irrelevant options.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Testing

npm test -- app/clients/tools/__tests__/openWeather.test.js

export OPENWEATHER_API_KEY=YourAPIKeyHere
npm test -- app/clients/tools/__tests__/openWeather.integration.test.js

In addition, it is easy enough to test from with LC. I can provide an API key for testing privately.

Documentation

PR submitted at LibreChat-AI/librechat.ai#196

@danny-avila
Copy link
Owner Author

danny-avila commented Jan 10, 2025

@jmaddington One thing I noticed is that this isn't setup for user-provided keys.

Part of the logic involves getEnvironmentVariable, which is why the test is failing:

   ● OpenWeather Tool (Integration Test) › timestamp action with real API key returns historical data

    Missing OPENWEATHER_API_KEY environment variable.

      11 |   const key = getEnvironmentVariable(envVar);
      12 |   if (!key && !override) {
    > 13 |     throw new Error(`Missing ${envVar} environment variable.`);
         |           ^
      14 |   }
      15 |   return key;
      16 | }

I'll add it when I get the chance

@jmaddington
Copy link
Contributor

@danny-avila I'd be glad to provide a key, or we can skip the integration tests if the key doesn't exist. While mock tests are great, I personally have a high preference for live integration tests when it is feasible.

@danny-avila
Copy link
Owner Author

All good, I meant that the current code was not allowing users to provide their own keys from the UI.

Coded tools need to follow a simple authentication pattern to allow for this, see my changes here:
8731f43

@danny-avila
Copy link
Owner Author

I can add my own key once it's activated for live testing

@danny-avila danny-avila merged commit 0855677 into main Jan 10, 2025
4 checks passed
@danny-avila danny-avila deleted the feat/openweather-tool branch January 10, 2025 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants