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

Generate a story and summarize it using Substrate.

🪩 To fork, sign up for Substrate to get your own API key and $50 free credits.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { ComputeText, sb, Substrate } from "npm:substrate";
const substrate = new Substrate({ apiKey: Deno.env.get("SUBSTRATE_API_KEY") });
const story = new ComputeText({
prompt: "tell me a story, be concise",
max_tokens: 500,
});
const summary = new ComputeText({
prompt: sb.interpolate`summarize this story in one sentence. do not preface the summary: ${story.future.text}`,
max_tokens: 500,
});
const stream = await substrate.stream(summary);
export default async function render(req: Request): Promise<Response> {
if (new URL(req.url).pathname === "/robots.txt") {
return new Response("User-agent: *\nDisallow: /");
}
const renderNodeResults = (await import("https://esm.town/v/substrate/renderNodeResults")).default;
return renderNodeResults(stream);
}
substrate-intro.web.val.run
August 2, 2024