Public
Script
October 23, 2023
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
import { fetch } from "https://esm.town/v/std/fetch";
import process from "node:process";
export let newChatGPT35 = async ({ req, res }) => {
const postData = {
model: "gpt-3.5-turbo",
messages: [
{ role: "system", content: "You are a powerful chatGPT assistant." },
{
role: "user",
content: "请介绍一下你自己",
},
],
};
const getCompletion = async () => {
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.openaiKey}`,
},
body: JSON.stringify(postData),
});
const data = await response.json();
return data;
};
const data = await getCompletion();
res.json(JSON.stringify(data.choices[0].message.content));
};
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!
October 23, 2023