Public
Express
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
import { openaiOpenAPI } from "https://esm.town/v/stevekrouse/openaiOpenAPI";
// https://stevekrouse-chatgptplugin.express.val.run/.well-known/ai-plugin.json
export async function chatGPTPlugin(req: express.Request, res: express.Response) {
if (req.path === "/.well-known/ai-plugin.json") {
res.json({
"schema_version": "v1",
"name_for_human": "Val Town",
"name_for_model": "val_town",
"description_for_human": "Run JavaScript or TypeScript on Val Town",
"description_for_model": `Val Town is a social programming environment.
Vals are JavaScript & TypeScript code.
They run server-side on Deno.
\`fetch\` is in the environment to access any PUBLIC real-time APIs or data feeds.
Answer any questions about times after your cut off date by querying PUBLIC APIs.
Do NOT use any API that requires a secret key.
Only use PUBLIC APIs.
Do NOT use \`YOUR_API_KEY\`.
Do NOT import axios or node-fetch. Instead use \`fetch\`.
Do NOT use newlines. Just use semicolons.
You can import libraries from npm: \`const {default: _} = await import("npm:lodash")\`
You MUST \`return\` the final value of the computation that you want.`,
"auth": {
"type": "none",
},
"api": {
"type": "openapi",
"url": "/openapi",
},
"logo_url":
"https://www.val.town/build/_assets/vt-whiteOnBlack-HPPYQAQ6.png",
"contact_email": "steve@val.town",
"legal_info_url": "https://val.town",
});
}
else if (req.path === "/openapi") {
// OpenAPI Spec
// only POST /v1/eval for now
res.send(openaiOpenAPI);
}
else if (req.path === "/v1/eval") {
// Proxy /v1/eval to api.val.town
try {
console.log(req.body);
let result = await fetchJSON(
"https://api.val.town/v1/eval",
{ method: "POST", body: JSON.stringify(req.body) },
);
console.log(result);
res.json(result);
}
catch (e) {
console.log("Error in evaluating " + e.message);
console.log(e.stack);
}
}
else {
console.error("Unknown path: " + req.path);
res.status(404).end();
}
}