Skip to content

Commit

Permalink
fix: tool icon, allow user-provided keys, conform to app key assignme…
Browse files Browse the repository at this point in the history
…nt pattern
  • Loading branch information
danny-avila committed Jan 10, 2025
1 parent ff8a6e3 commit 8731f43
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
14 changes: 9 additions & 5 deletions api/app/clients/tools/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
"pluginKey": "calculator",
"description": "Perform simple and complex mathematical calculations.",
"icon": "https://i.imgur.com/RHsSG5h.png",
"isAuthRequired": "false",
"authConfig": []
},
{
Expand Down Expand Up @@ -141,10 +140,15 @@
},
{
"name": "OpenWeather",
"pluginKey": "OpenWeather",
"pluginKey": "open_weather",
"description": "Get weather forecasts and historical data from the OpenWeather API",
"icon": "/assets/flux.png",
"isAuthRequired": "false",
"authConfig": []
"icon": "/assets/openweather.png",
"authConfig": [
{
"authField": "OPENWEATHER_API_KEY",
"label": "OpenWeather API Key",
"description": "Sign up at <a href=\"https://home.openweathermap.org/users/sign_up\" target=\"_blank\">OpenWeather</a>, then get your key at <a href=\"https://home.openweathermap.org/api_keys\" target=\"_blank\">API keys</a>."
}
]
}
]
29 changes: 13 additions & 16 deletions api/app/clients/tools/structured/OpenWeather.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ const { z } = require('zod');
const { getEnvironmentVariable } = require('@langchain/core/utils/env');
const fetch = require('node-fetch');

// Utility to retrieve API key
function getApiKey(envVar, override, providedKey) {
if (providedKey) {
return providedKey;
}
const key = getEnvironmentVariable(envVar);
if (!key && !override) {
throw new Error(`Missing ${envVar} environment variable.`);
}
return key;
}

/**
* Map user-friendly units to OpenWeather units.
* Defaults to Celsius if not specified.
Expand Down Expand Up @@ -70,7 +58,7 @@ function roundTemperatures(obj) {
}

class OpenWeather extends Tool {
name = 'OpenWeather';
name = 'open_weather';
description =
'Provides weather data from OpenWeather One Call API 3.0. ' +
'Actions: help, current_forecast, timestamp, daily_aggregation, overview. ' +
Expand All @@ -90,10 +78,19 @@ class OpenWeather extends Tool {
tz: z.string().optional(),
});

constructor(options = {}) {
constructor(fields = {}) {
super();
const { apiKey, override = false } = options;
this.apiKey = getApiKey('OPENWEATHER_API_KEY', override, apiKey);
this.envVar = 'OPENWEATHER_API_KEY';
this.override = fields.override ?? false;
this.apiKey = fields[this.envVar] ?? this.getApiKey();
}

getApiKey() {
const key = getEnvironmentVariable(this.envVar);
if (!key && !this.override) {
throw new Error(`Missing ${this.envVar} environment variable.`);
}
return key;
}

async geocodeCity(city) {
Expand Down
2 changes: 1 addition & 1 deletion api/app/clients/tools/util/handleTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const loadTools = async ({
'azure-ai-search': StructuredACS,
traversaal_search: TraversaalSearch,
tavily_search_results_json: TavilySearchResults,
OpenWeather: OpenWeather,
open_weather: OpenWeather,
};

const customConstructors = {
Expand Down

0 comments on commit 8731f43

Please sign in to comment.