UNPKG

@jackhua/mini-langchain

Version:

A lightweight TypeScript implementation of LangChain with cost optimization features

63 lines 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WeatherTool = void 0; const base_1 = require("./base"); /** * Mock weather tool for demonstration */ class WeatherTool extends base_1.BaseTool { constructor() { super(...arguments); this.name = 'weather'; this.description = 'Get weather information for a location. Input should be a city name.'; // Mock weather data this.mockWeatherData = { 'london': { temperature: '15°C', condition: 'Partly cloudy', humidity: '65%', wind: '10 km/h' }, 'new york': { temperature: '22°C', condition: 'Sunny', humidity: '45%', wind: '15 km/h' }, 'tokyo': { temperature: '18°C', condition: 'Rainy', humidity: '80%', wind: '5 km/h' }, 'paris': { temperature: '20°C', condition: 'Clear', humidity: '55%', wind: '12 km/h' }, 'sydney': { temperature: '25°C', condition: 'Sunny', humidity: '60%', wind: '20 km/h' } }; } async execute(input) { const city = input.toLowerCase().trim(); const weather = this.mockWeatherData[city]; if (weather) { return `Weather in ${input}: ${weather.condition}, Temperature: ${weather.temperature}, Humidity: ${weather.humidity}, Wind: ${weather.wind}`; } // Check partial matches for (const [key, data] of Object.entries(this.mockWeatherData)) { if (city.includes(key) || key.includes(city)) { return `Weather in ${key}: ${data.condition}, Temperature: ${data.temperature}, Humidity: ${data.humidity}, Wind: ${data.wind}`; } } return `Weather data not available for "${input}". This is a mock weather tool. Try cities like London, New York, Tokyo, Paris, or Sydney.`; } } exports.WeatherTool = WeatherTool; //# sourceMappingURL=weather.js.map