Readme

If you fork this, you'll need to set OPENAI_API_KEY in your Val Town Secrets.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { email } from "https://esm.town/v/std/email?v=11";
import { fetch } from "https://esm.town/v/std/fetch";
import { OpenAI } from "npm:openai";
let location = "shenzhen";
let lang = "zh";
const weather = await fetch(
`https://wttr.in/${location}?lang=${lang}&format=j1`,
).then(r => r.json());
const openai = new OpenAI();
let chatCompletion = await openai.chat.completions.create({
messages: [{
role: "user",
content: `基于下面的天气预报信息,播报当天深圳的天气情况,给我相关的建议告诉我如何穿衣,如果下雨我是否需要携带雨伞。
给出合理的理由同时带上温度和天气播报。
尽可能的准确,假设我一天都不会更换衣服的。
使用2-3个句子概述一下。`.replaceAll("\n", ""),
}, {
role: "user",
content: JSON.stringify(weather),
}],
model: "gpt-3.5-turbo",
max_tokens: 150,
});
const text = chatCompletion.choices[0].message.content;
console.log(text);
export async function weatherGPT() {
const result = await fetch(`https://hello.liaolile.com/test/weather`, {
method: "POST",
body: JSON.stringify({
"info": text,
}),
}).then(r => r.json());
console.log(result);
await email({ subject: "Weather Today", text });
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
March 8, 2024