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

Vercel AI SDK with Val Town!

Use the Vercel AI SDK in your Vals.

Note: you must add your OpenAI key to your Val Town Env variables under OPENAI_API_KEY. If you would like to specify a different name for your API Key, you can create a custom OpenAI provider with the createOpenAI function.

Prefer another AI provider? Use any supported provider by changing just two lines of code!

1
2
3
4
5
6
7
8
9
10
import { openai } from "npm:@ai-sdk/openai";
import { StreamingTextResponse, streamText } from "npm:ai";
export default async function(req: Request): Promise<Response> {
const result = await streamText({
model: openai("gpt-4o"),
prompt: "Generate a fast recipe for Lasagna.",
});
return result.toTextStreamResponse({ headers: { "Content-Type": "text/event-stream" } });
}
tahsin-tomatominnow.web.val.run
June 14, 2024