Readme

ChatGPT Plugin for Val Town

Run code on Val Town from ChatGPT.

Usage

I haven't been able to get it to do very useful things yet. It certainly can evaluate simple JS code:

It would be awesome if it knew how to use other APIs and make fetch calls to them, but it has been failing at that.

Limitations

This plugin currently only has unauthenticated access to POST /v1/eval, which basically means that all it can do is evaluate JavaScript or TypeScript.

In theory it could refer to any existing vals in Val Town, but it wouldn't know about those unless you told it.

Future directions

Once we have more robust APIs to search for existing vals, this plugin could be WAY more valuable! In theory GPT4 could first search for vals to do a certain task and then if it finds one it could then write code based on that val. In practice however, that might require too many steps for poor GPT. We might need to use some sort of agent or langchain thing if we wanted that sort of behavior.

Adding authentication could also enable it to make requests using your secrets and private vals and create new vals for you. However I am dubious that this would actually be practically useful.

Installation

  1. Select GPT-4 (requires ChatGPT Plus)
  2. Click No plugins enabled

  1. Click "Install an unverified plugin" or "Develop your own plugin" (I'm not sure the difference)

  1. Paste in this val's express endpoint

https://stevekrouse-chatGPTPlugin.express.val.run
  1. Click through the prompts until it's installed
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();
}
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.