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);
1/**
2 * This app generates cute daily notes for a daughter using OpenAI's GPT model.
3 * It stores the generated notes in SQLite for persistence and displays them on a simple web interface.
4 * The app uses React for the frontend and Deno's runtime environment in Val Town for the backend.
56
57async function server(request: Request): Promise<Response> {
58 const { OpenAI } = await import("https://esm.town/v/std/openai");
59 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
60 const KEY = "DailyDaughterNotes";
85 }
86 } else if (path === "/generate-note" && request.method === "POST") {
87 const openai = new OpenAI();
88 const completion = await openai.chat.completions.create({
89 messages: [
90 {
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.
1import { sha256 } from "https://denopkg.com/chiefbiiko/sha256@v1.0.0/mod.ts";
2import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
3import { OpenAI } from "https://esm.town/v/std/openai?v=4";
4import { ResultSet, sqlite } from "https://esm.town/v/std/sqlite?v=6";
5import { Hono } from "npm:hono@3";
392const app = new Hono();
393app.post("/remix/:id", async (c) => {
394 const openai = new OpenAI();
395 const { prompt } = await c.req.json();
396 let svg = await getSVG(c.req.param("id") as string);
397 if (svg === undefined) return c.text("Not found", 404);
398 const stream = await openai.chat.completions.create({
399 messages: [
400 { role: "user", content: "make me an svg image" },
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3const OPENAI_API_KEY = "your_openai_api_key"; // Replace with your actual OpenAI API key
4
5export default async function main(req: Request): Promise<Response> {
57 const user2Summary = summarizeActivity(user2Data);
58
59 const openai = new OpenAI(OPENAI_API_KEY);
60 const completion = await openai.chat.completions.create({
61 model: "gpt-3.5-turbo",
62 messages: [
1// This approach fetches GitHub activity for two users specified in the URL,
2// sends it to OpenAI for analysis, and returns collaboration suggestions.
3// It uses the GitHub API (which doesn't require authentication for public data)
4// and the OpenAI API (which does require an API key).
5// Tradeoff: We're using an inline API key for simplicity, which isn't ideal for security.
6// Note: This might hit rate limits for the GitHub API due to fetching a year of data.
7
8import { OpenAI } from "https://esm.town/v/std/openai";
9
10const OPENAI_API_KEY = "your_openai_api_key"; // Replace with your actual OpenAI API key
11
12export default async function main(req: Request): Promise<Response> {
54 const user2Summary = summarizeActivity(user2Data);
55
56 const openai = new OpenAI(OPENAI_API_KEY);
57 const completion = await openai.chat.completions.create({
58 model: "gpt-3.5-turbo",
59 messages: [
1# GitHub Activity Summarizer
2
3This val.town script fetches a user's recent GitHub activity and generates a summarized narrative overview using OpenAI's GPT model.
4
5## Features
6
7- Retrieves GitHub activity for a specified user from the past week
8- Summarizes activity using OpenAI's GPT-3.5-turbo model
9- Returns a concise, narrative summary of the user's GitHub contributions
10
22## Note
23
24Ensure you have necessary permissions and comply with GitHub's and OpenAI's terms of service when using this script.
1// This val receives text input, sends it to OpenAI to generate relationships,
2// and returns a newline-delimited list of relationships.
3// It uses the OpenAI API to generate the relationships.
4// Tradeoff: This approach relies on an external API, which may have rate limits or costs.
5
7// curl -X POST -H "Content-Type: text/plain" -d "Your text here" https://your-val-url.web.val.run
8
9import { OpenAI } from "https://esm.town/v/std/openai";
10
11const openai = new OpenAI();
12
13export default async function main(req: Request): Promise<Response> {
18 const text = await req.text();
19
20 const completion = await openai.chat.completions.create({
21 model: "gpt-3.5-turbo",
22 messages: [
1import Mux from "npm:@mux/mux-node";
2import { AssemblyAI } from "npm:assemblyai";
3import OpenAI from "npm:openai";
4
5import { zodResponseFormat } from "npm:openai/helpers/zod";
6import z from "npm:zod";
7
15 apiKey: Deno.env.get("ASSEMBLY_AI_KEY"),
16});
17const openai = new OpenAI({
18 apiKey: Deno.env.get("OPEN_API_KEY"),
19});
133 const responseFormat = z.object({ cues: cueFormat });
134
135 const completion = await openai.chat.completions.create({
136 messages: [
137 {
14- Mux Access token details (`MUX_TOKEN_ID`, `MUX_TOKEN_SECRET`) This endpoint requires an existing Mux asset that's ready with an audio-only static rendition associated with it. You can run [this val](https://www.val.town/v/mux/createDubbingTestAsset) to create a new one for testing.
15- AssemblyAI API key (`ASSEMBLYAI_API_KEY`). Get it [from their dashboard here](https://www.assemblyai.com/app/account)
16- OpenAI API key (`OPENAI_API_KEY`). Get it [from their dashboard here](https://platform.openai.com/api-keys)
17
18Make a POST request to the Val's endpoint with the following body, replacing the values with your own asset ID and the list of speakers. Speakers are listed in order of appearance.