Readme

Use GPT to generate vals on your account!

Describe the val that you need, call this function, and you'll get a new val on your workspace generated by OpenAI's API!

First, ensure you have a Val Town API Token, then call @andreterron.createGeneratedVal({...}) like this example:

@andreterron.createGeneratedVal({ valTownKey: @me.secrets.vt_token, description: "A val that given a text file position in `{line, col}` and the text contents, returns the index position", });

This will create a val in your workspace, and here's the one created by the example above: https://www.val.town/v/andreterron.getFileIndexPosition

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
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
import { runVal } from "https://esm.town/v/std/runVal";
export async function createGeneratedVal({ description, valTownKey }: {
description: string;
valTownKey: string;
}) {
const code = await runVal(
"andreterron.generateValCodeAPI",
description,
);
const val = await fetchJSON(
`https://api.val.town/v1/vals`,
{
method: "POST",
headers: {
Authorization: `Bearer ${valTownKey}`,
},
body: JSON.stringify({
code,
}),
},
);
return val;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
1
nbbaier avatar

Wow this is so cool

October 23, 2023