Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

The actual code for VALL-E: https://www.val.town/v/janpaul123/VALLE

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/** @jsxImportSource https://esm.sh/react */
import valleGetValsContextWindow from "https://esm.town/v/janpaul123/valleGetValsContextWindow";
import archiveVal from "https://esm.town/v/nbbaier/archiveVal?v=10";
import { updateValByName } from "https://esm.town/v/nbbaier/updateValByName?v=14";
import { createVal } from "https://esm.town/v/neverstew/createVal?v=6";
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo?v=29";
import { passwordAuth } from "https://esm.town/v/pomdtr/password_auth?v=84";
import { verifyToken } from "https://esm.town/v/pomdtr/verifyToken";
import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
import { sleep } from "https://esm.town/v/stevekrouse/sleep?v=1";
import { anthropic } from "npm:@ai-sdk/anthropic";
import { createOpenAI, openai } from "npm:@ai-sdk/openai";
import ValTown from "npm:@valtown/sdk";
import { StreamingTextResponse, streamText } from "npm:ai";
import { Hono } from "npm:hono@3";
import _ from "npm:lodash@4";
import { renderToString } from "npm:react-dom/server";
const valTownToken = Deno.env.get("valtown");
const vt = new ValTown({ bearerToken: valTownToken });
const app = new Hono();
const jsxResponse = (jsx) => {
return new Response(renderToString(jsx), { headers: { "Content-Type": "text/html" } });
};
const username = extractValInfo(import.meta.url).author;
const systemprompt = await fetchText(
"https://gist.githubusercontent.com/stevekrouse/21cba8759c09f906be424dc1bb949869/raw/townie.md",
);
// Your response should start with \`\`\`ts and end with \`\`\`.
// The val should create a "export default async function main() {" which
// is the main function that gets executed, without any arguments. Don't return a Response object,
// just return a plain Javascript object, array, or string.
const systemprompt2 = `Since your last response the user might have changed the code.
The current version of the code is below. Keep your response as close to their current
code as possible, only changing things that are strictly necessary to change.`.replace("\n", "");
const makeBubbleHeader = (emoji: string, id?: string, spin?: boolean) => {
const idStr = id ? ` id="${id}"` : "";
const spinStr = spin ? " animate-spin" : "";
return `
<div class="flex mb-4" ${idStr}>
<div class="${spinStr}" style="width:32px; height:32px; line-height:32px; font-size:28px; overflow:hidden; text-align: center; display:inline-block; background:#ddd; border-radius:100%; flex-shrink: 0">${emoji}</div>
<div class="flex-1 ml-4" style="margin-top: 3px; min-width: 0">
`;
};
const makeBubbleFooter = () => {
return `
</div>
</div>
`;
};
const makeAssistantMessageHeader = (maxHeight: number) => {
return `I wrote some new code for your Val: <div class="js-scroll-container-assistant font-mono whitespace-pre-wrap text-xs overflow-auto p-2 mt-2 rounded" style="max-height: ${maxHeight}px; background: rgb(249 250 251)">`;
};
app.post("/save", async (c) => {
const body = await c.req.parseBody();
// console.log(body);
const valName = body.valName as any;
const code = (body.code as any).replaceAll("\r\n", "\n");
await updateValByName({ token: valTownToken, code, name: valName });
return new Response();
});
const mainHandler = async (c) => {
const { readable, writable } = new TransformStream();
const writer = writable.getWriter();
const textEncoder = new TextEncoder();
function write(text) {
writer.write(textEncoder.encode(text));
}
new Promise(async () => {
const body = await c.req.parseBody();
const userprompt: any = body.userprompt;
let prevConversation = [];
if (body.prevConversation) prevConversation = JSON.parse(body.prevConversation as any) as any;
let currentCode = "";
if (body.code) currentCode = (body.code as any).replaceAll("\r\n", "\n");
let model = "gpt-4o-mini";
// let model = "claude-3-5-sonnet-20240620";
if (body.model) model = body.model as any;
let loadValName = "";
if (c.req.query("loadValName")) loadValName = c.req.query("loadValName") as any;
let fullscreen = "";
if (c.req.query("fullscreen")) fullscreen = c.req.query("fullscreen") as any;
let questionType = "regenerate";
if (body.questionType) questionType = body.questionType as any;
let contextWindowSize = 10;
if (body.contextWindowSize) contextWindowSize = parseInt(body.contextWindowSize) as any;
let formAction = "/";
stevekrouse-likelycyanpartridge.web.val.run
September 5, 2024