askSMHI
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v66View latest version
Using OpenAI chat completion with function calls to SMHI api
The API is instructed to use the current time in Europe/Stockholm timezone. If the message can not be handled with the weather API endpoint, the Open AI assistant will reply instead.
/ask?q=What is the weather like in Stockholm today
{
answer?: string // If the message could not be answered with the SMHI API
error?:string //
data?: unknown // the actual data returned from SMHI, if the API is called
summary?: string // a summary of the data, by GPT API
}
- How is the weather in the Capital of Sweden tomorrow.
- How is the weather at Liseberg on Friday.
- zod: for describing the SMHI API response and function API input
- zod-to-json-schema: Transform the zod schema to json schema (readable by the GPT API)
- gpt3-tokenizer: count the number of tokens
- formkit/temporal: To handle dates in a specific timezone (Europe/Stockholm)