Public
Readme
- Fork this val to your own profile.
- Create a Val Town API token, open the browser preview of this val, and use the API token as the password to log in.
Code
HTTP
import valleGetValsContextWindow from "https://esm.town/v/janpaul123/valleGetValsContextWindow?v=7";
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?v=1";
import { openai } from "npm:@ai-sdk/openai";
import ValTown from "npm:@valtown/sdk";
import { streamText } from "npm:ai";
import _ from "npm:lodash@4";
async function main(req: Request): Promise<Response> {
const { readable, writable } = new TransformStream();
const writer = writable.getWriter();
const write = (text) => writer.write(new TextEncoder().encode(text));
(async () => {
write(`<!DOCTYPE html>
<html>
<head><link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet" /></head>
<body style="padding: 8px; padding-top: 12px; height: 100%; overflow: auto">
<script>
// Scroll to the bottom of the page when the page changes.
(new MutationObserver(function (mutationsList, observer) {
window.scrollTo({ left: 0, top: document.body.scrollHeight, behavior: "instant" });
})).observe(document, { childList: true, characterData: true, subtree: true });
</script>
<div class="mb-4">Hi, I'm <strong>VALL-E</strong>. What would you like to make?</div>`);
const userprompt = req.method === "POST" ? (await req.formData()).get("userprompt") as string : "";
write(`<form method="POST" action="/">
<textarea "autofocus" name="userprompt" class="bg-gray-100 w-full p-2 rounded">${userprompt}</textarea>
<button type="submit" class="bg-gray-100 hover:bg-gray-200 px-2 block rounded">Go</button>
</form>`);
if (userprompt) {
write(`<div class="my-4">I wrote some new code for your Val:
<div class="font-mono whitespace-pre-wrap text-xs p-2 mt-2 rounded bg-gray-100">`);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
janpaul123-valleblogv0.web.val.run
Updated: August 8, 2024