You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As you see, the api.openmeteo... is prepended. Any ideas on what this is? Did I miss an option? Thank you?
import { OpenAI } from "@langchain/openai";
import { APIChain } from "langchain/chains";
import { StreamingTextResponse, LangChainStream } from "ai"
import { NextRequest } from "next/server";
const OPEN_METEO_DOCS = `BASE URL: https://api.open-meteo.com/
API Documentation
The API endpoint /v1/forecast accepts a geographical coordinate, a list of weather variables and responds with a JSON hourly weather forecast for 7 days. Time always starts at 0:00 today and contains 168 hours. All URL parameters are listed below:
Parameter Format Required Default Description
latitude, longitude Floating point Yes Geographical WGS84 coordinate of the location
hourly String array No A list of weather variables which should be returned. Values can be comma separated, or multiple &hourly= parameter in the URL can be used.
daily String array No A list of daily weather variable aggregations which should be returned. Values can be comma separated, or multiple &daily= parameter in the URL can be used. If daily weather variables are specified, parameter timezone is required.
current_weather Bool No false Include current weather conditions in the JSON output.
temperature_unit String No celsius If fahrenheit is set, all temperature values are converted to Fahrenheit.
windspeed_unit String No kmh Other wind speed speed units: ms, mph and kn
precipitation_unit String No mm Other precipitation amount units: inch
timeformat String No iso8601 If format unixtime is selected, all time values are returned in UNIX epoch time in seconds. Please note that all timestamp are in GMT+0! For daily values with unix timestamps, please apply utc_offset_seconds again to get the correct date.
timezone String No GMT If timezone is set, all timestamps are returned as local-time and data is returned starting at 00:00 local-time. Any time zone name from the time zone database is supported. If auto is set as a time zone, the coordinates will be automatically resolved to the local time zone.
past_days Integer (0-2) No 0 If past_days is set, yesterday or the day before yesterday data are also returned.
start_date
end_date String (yyyy-mm-dd) No The time interval to get weather data. A day must be specified as an ISO8601 date (e.g. 2022-06-30).
models String array No auto Manually select one or more weather models. Per default, the best suitable weather models will be combined.
Variable Valid time Unit Description
temperature_2m Instant °C (°F) Air temperature at 2 meters above ground
snowfall Preceding hour sum cm (inch) Snowfall amount of the preceding hour in centimeters. For the water equivalent in millimeter, divide by 7. E.g. 7 cm snow = 10 mm precipitation water equivalent
rain Preceding hour sum mm (inch) Rain from large scale weather systems of the preceding hour in millimeter
showers Preceding hour sum mm (inch) Showers from convective precipitation in millimeters from the preceding hour
weathercode Instant WMO code Weather condition as a numeric code. Follow WMO weather interpretation codes. See table below for details.
snow_depth Instant meters Snow depth on the ground
freezinglevel_height Instant meters Altitude above sea level of the 0°C level
visibility Instant meters Viewing distance in meters. Influenced by low clouds, humidity and aerosols. Maximum visibility is approximately 24 km.`;
export async function apichain(req: NextRequest) {
try {
const { stream, handlers } = LangChainStream()
const { api, messages } = await req.json()
const currentMessageContent = messages[messages.length - 1].content
const model = new OpenAI({
modelName: "gpt-3.5-turbo-16k",
streaming: true,
temperature: 0.1,
})
const apichain = APIChain.fromLLMAndAPIDocs(model, OPEN_METEO_DOCS, {
headers: {
"x-rapidapi-key": `${process.env.RAPIDAPI_KEY}`,
}
})
await apichain.stream({ question: currentMessageContent, messages: messages }, { callbacks: [handlers] })
return new StreamingTextResponse(stream)
} catch (e) {
return new StreamingTextResponse("Sorry. Try again.")
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi Langchain Community! I was running this APIChain example, and tried to convert it into a stream, but it keeps prepending the api URL it called.
Example: What is the weather in munich?
Answer: https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&hourly=temperature_2m,rain¤t_weather=trueThe API call to retrieve the temperature at 2 meters above ground and the amount of rain for the specified latitude and longitude, with the inclusion of current weather conditions, returned an error. The error message indicates that the data is corrupted and cannot be initialized due to an invalid string value for the latitude parameter.
As you see, the api.openmeteo... is prepended. Any ideas on what this is? Did I miss an option? Thank you?
Beta Was this translation helpful? Give feedback.
All reactions