Public
Script
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
import { parentReference } from "https://esm.town/v/stevekrouse/parentReference?v=3";
import { runVal } from "https://esm.town/v/std/runVal";
/**
* OpenAI text completion. https://platform.openai.com/docs/api-reference/completions
*
* val.town and rlimit.com has generously provided a free daily quota. Until the quota is met, no need to provide an API key.
*
*/
export const gpt4 = async (prompt: string, maxTokens?: number = 1000) => {
const parent = parentReference();
return await runVal("rlimit.gpt4Api", {
prompt,
valUser: parent.userHandle,
maxTokens: Math.min(500, maxTokens)
});
};
October 23, 2023