Public
Back
Version 40
1/24/2024
import { chat } from "https://esm.town/v/cosmo/chat_openai";
import { getCurrentWeather } from "https://esm.town/v/cosmo/get_current_weather";
const currentWeather = await getCurrentWeather("48.4117", "-114.34"),
weather = Object.fromEntries(
[isDaytime, temperature, temperatureUnit, windSpeed, windDirection, shortForecast]
.filter(key => key in obj)
.map(key => [key, currentWeather[key]]),
),
messages = [
{
role: "system",
content:
"Concisely relay the provided weather data in natural language. Don't preface or embellish it, just only relay the weather.",
},
{ role: "user", content: JSON.stringify(weather) },
],
chatResponse = await chat(Deno.env.get("OPENAI_API_KEY"), messages);
export default chatResponse.choices[0].message.content;
Updated: February 1, 2024