9import { sleep } from "https://esm.town/v/stevekrouse/sleep?v=1";
10import { anthropic } from "npm:@ai-sdk/anthropic";
11import { openai } from "npm:@ai-sdk/openai";
12import ValTown from "npm:@valtown/sdk";
13import { StreamingTextResponse, streamText } from "npm:ai";
1104 let vercelModel;
1105 if (model.includes("gpt")) {
1106 vercelModel = openai(model);
1107 } else {
1108 vercelModel = anthropic(model);
3- [[https://www.val.town/v/stevekrouse/valwriter]]
4
5- _Note_: It looks like openai enhancement was dropped at some point when adding all the gizmos;
6
1/**
2 * This val creates a website that generates optimized prompts for Val Town based on user input.
3 * It uses the OpenAI API to generate prompts and incorporates a loading animation.
4 * The generated prompt is tailored to Val Town's specific features and best practices.
5 */
14 "Blob storage",
15 "Email sending",
16 "OpenAI integration",
17 "React support",
18 "TypeScript support",
93
94 if (url.pathname === "/generate" && request.method === "POST") {
95 const { OpenAI } = await import("https://esm.town/v/std/openai");
96 const openai = new OpenAI();
97
98 try {
99 const { idea } = await request.json();
100 const completion = await openai.chat.completions.create({
101 messages: [
102 {
3import { passwordAuth } from "https://esm.town/v/pomdtr/password_auth?v=84";
4import { verifyToken } from "https://esm.town/v/pomdtr/verifyToken?v=1";
5import { openai } from "npm:@ai-sdk/openai";
6import ValTown from "npm:@valtown/sdk";
7import { streamText } from "npm:ai";
36
37 const stream = await streamText({
38 model: openai("gpt-4o", {
39 baseURL: "https://std-openaiproxy.web.val.run/v1",
40 apiKey: Deno.env.get("valtown"),
41 } as any),
441 prompt = prompt || "Summarize this article in 30 words, focusing on the primary author. Do not respond with JSON or XML or stage instructions. Only reply in text. Text:"
442 let result = await ai({
443 provider: provider || "openai",
444 model: model || "gpt-3.5-turbo",
445 prompt: prompt + content
455 console.log("prompt", prompt)
456 let result = await ai({
457 provider: provider || "openai",
458 model: model || "gpt-3.5-turbo",
459 prompt: prompt + content
464export const getEmbeddingsFn = async (content) => {
465 let result = await ai({
466 provider: "openai",
467 embed: true,
468 value: content
6* Fork this val to your own profile.
7* Make a folder for the temporary vals that get generated, take the ID from the URL, and put it in `tempValsParentFolderId`.
8* If you want to use OpenAI models you need to set the `OPENAI_API_KEY` [env var](https://www.val.town/settings/environment-variables).
9* If you want to use Anthropic models you need to set the `ANTHROPIC_API_KEY` [env var](https://www.val.town/settings/environment-variables).
10* Create a [Val Town API token](https://www.val.town/settings/api), open the browser preview of this val, and use the API token as the password to log in.
3import { passwordAuth } from "https://esm.town/v/pomdtr/password_auth?v=84";
4import { verifyToken } from "https://esm.town/v/pomdtr/verifyToken?v=1";
5import { openai } from "npm:@ai-sdk/openai";
6import ValTown from "npm:@valtown/sdk";
7import { streamText } from "npm:ai";
36
37 const stream = await streamText({
38 model: openai("gpt-4o", {
39 baseURL: "https://std-openaiproxy.web.val.run/v1",
40 apiKey: Deno.env.get("valtown"),
41 } as any),
3- [[https://www.val.town/v/stevekrouse/valwriter]]
4
5- _Note_: It looks like openai enhancement was dropped at some point when adding all the gizmos;
6
164
165 <div class="example">
166 <h3>Example with OpenAI Embeddings:</h3>
167 <p>This example shows how to use the UMAP service with OpenAI embeddings:</p>
168 <pre>
169// First, generate embeddings using OpenAI API
170import { OpenAI } from "https://esm.town/v/std/openai";
171const openai = new OpenAI();
172
173async function getEmbeddings(texts) {
174 const response = await openai.embeddings.create({
175 model: "text-embedding-ada-002",
176 input: texts,
180
181// Then, use these embeddings with the UMAP service
182const texts = ["Hello world", "OpenAI is amazing", "UMAP reduces dimensions"];
183const embeddings = await getEmbeddings(texts);
184
1import { email } from "https://esm.town/v/std/email?v=11";
2import { OpenAI } from "npm:openai";
3
4let location = "brooklyn ny";
8).then(r => r.json());
9
10const openai = new OpenAI();
11let chatCompletion = await openai.chat.completions.create({
12 messages: [{
13 role: "user",