Search
valle_tmp_3173618096166977554668362851031
@janpaul123
@jsxImportSource https://esm.sh/react
HTTP (deprecated)
import _ from "npm:lodash@4";
import OpenAI from "npm:openai";
import { renderToString } from "npm:react-dom/server";
const contextWindow = await valleGetValsContextWindow.call(null, model);
const openai = new OpenAI();
const stream = await openai.chat.completions.create({
model,
valleBlogV0
@heaversm
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.
HTTP (deprecated)
import { verifyToken } from "https://esm.town/v/pomdtr/verifyToken?v=1";
import { openai } from "npm:@ai-sdk/openai";
import ValTown from "npm:@valtown/sdk";
const stream = await streamText({
model: openai("gpt-4o", {
baseURL: "https://std-openaiproxy.web.val.run/v1",
apiKey: Deno.env.get("valtown"),
valle_tmp_02267091431922629935130311039563566
@janpaul123
@jsxImportSource https://esm.sh/react
HTTP (deprecated)
import _ from "npm:lodash@4";
import OpenAI from "npm:openai";
import { renderToString } from "npm:react-dom/server";
const contextWindow = await valleGetValsContextWindow(model);
const openai = new OpenAI();
const stream = await openai.chat.completions.create({
model,
calories
@chriswmartin
Calorie Count via Photo Uploads your photo to ChatGPT's new vision model to automatically categorize the food and estimate the calories.
HTTP (deprecated)
import { fileToDataURL } from "https://esm.town/v/stevekrouse/fileToDataURL";
import { modifyImage } from "https://esm.town/v/stevekrouse/modifyImage";
import { chat } from "https://esm.town/v/stevekrouse/openai";
import { Hono } from "npm:hono@3";
function esmTown(url) {
webscrapeWikipediaIntro
@richardkaplan
An interactive, runnable TypeScript val by richardkaplan
Script
const cheerio = await import("npm:cheerio");
const html = await fetchText(
"https://en.wikipedia.org/wiki/OpenAI",
const $ = cheerio.load(html);
// Cheerio accepts a CSS selector, here we pick the second <p>
egoBooster
@stevekrouse
* This ego booster app takes a selfie, sends it to GPT-4o-mini for analysis,
* and streams funny, specific compliments about the user's appearance.
* We use the WebRTC API for camera access, the OpenAI API for image analysis,
* and server-sent events for real-time streaming of compliments.
HTTP (deprecated)
* and streams funny, specific compliments about the user's appearance.
* We use the WebRTC API for camera access, the OpenAI API for image analysis,
* and server-sent events for real-time streaming of compliments.
console.log("Image received, size:", image.size);
const { OpenAI } = await import("https://esm.town/v/std/openai");
const openai = new OpenAI();
const stream = new ReadableStream({
const base64Image = btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
console.log("Sending request to OpenAI");
const completion = await openai.chat.completions.create({
model: "gpt-4o-mini",
stream: true,
console.log("Streaming response from OpenAI");
for await (const chunk of completion) {
} catch (error) {
console.error('Error in OpenAI processing:', error);
controller.enqueue(new TextEncoder().encode("Oops! Our AI had a little hiccup. Maybe your beauty short-circuited it! 🤖💥"));
createGeneratedVal
@yawnxyz
Use GPT to generate vals on your account! Describe the val that you need, call this function, and you'll get a new val on your workspace generated by OpenAI's API! First, ensure you have a Val Town API Token , then call @andreterron.createGeneratedVal({...}) like this example : @andreterron.createGeneratedVal({
valTownKey: @me.secrets.vt_token,
description:
"A val that given a text file position in `{line, col}` and the text contents, returns the index position",
}); This will create a val in your workspace, and here's the one created by the example above: https://www.val.town/v/andreterron.getFileIndexPosition
Script
# Use GPT to generate vals on your account!
Describe the val that you need, call this function, and you'll get a new val on your workspace generated by OpenAI's API!
First, ensure you have a [Val Town API Token](https://www.val.town/settings/api), then call `@andreterron.createGeneratedVal({...})` like this [example](https://www.val.town/v/andreterron.untitled_tomatoKiwi):
import { runVal } from "https://esm.town/v/std/runVal";
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
export const generateValCode = async (
const lodash = await import('npm:lodash');
const response = await openai.chat.completions.create({
model: "gpt-4o",
valle_tmp_50677281064121176482256801591227
@janpaul123
// Improvements Made:
HTTP (deprecated)
import _ from "npm:lodash";
import OpenAI from "npm:openai";
import { renderToString } from "npm:react-dom/server";
const contextWindow = await valleGetValsContextWindow(model);
const openai = new OpenAI();
const stream = await openai.chat.completions.create({
model,
valTownChatGPT2
@janpaul123
https://x.com/JanPaul123/status/1811801305066651997 Fork it and authenticate with your Val Town API token as the password.
HTTP (deprecated)
import { Hono } from "npm:hono@3";
import OpenAI from "npm:openai";
import { renderToString } from "npm:react-dom/server";
</div>,
const openai = new OpenAI();
const stream = await openai.chat.completions.create({
model,
valle_tmp_563310902711919480463986409263
@janpaul123
@jsxImportSource https://esm.sh/react
HTTP (deprecated)
import _ from "npm:lodash@4";
import OpenAI from "npm:openai";
import { renderToString } from "npm:react-dom/server";
const contextWindow: any = await valleGetValsContextWindow(model);
const openai = new OpenAI();
const stream = await openai.chat.completions.create({
model,
telegrambot
@begoon
This val is a demo skeleton of a telegram chat bot. It requires the BOT_TOKEN environment varialbe, which the telegram bot token. Another required variable is ME. The variable is an HTTP header to call a few extra endpoints (see the code). One of those endpoints is /webhook/set , which installs the webhook to activate the bot. The code is mostly educational. The bot echos back incoming messages. There is one command, /ai , which sends the incoming messages to Open AI and forwards the reply back to the chat.
HTTP
const { endpoint } = VAL;
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
async function POST(cmd: string, data: { [key: string]: string }) {
console.log("q", q);
const completion = await openai.chat.completions.create({
messages: [
welcomeEmail
@rodrigotello
An interactive, runnable TypeScript val by rodrigotello
Script
<li style="margin-bottom:6px">Reference your vals: <div style="${CSScodeStyling};">@me.fizz.split('buzz').length</div></li>
<li style="margin-bottom:6px">Reference others' vals: <div style="${CSScodeStyling};">@stevekrouse.moreBuzz()</div></li>
<li style="margin-bottom:6px">Reference personal secrets: <div style="${CSScodeStyling};">@me.secrets.openai</div></li>
<li style="margin-bottom:6px">Import from npm: <div style="${CSScodeStyling};">const _ = await import("npm:lodash-es")</div></li>
<li>Run keyboard shortcut: <div style="${CSScodeStyling};">cmd+enter</div></li>
ReadmeWriter
@willthereader
Val Town AI Readme Writer This val provides a class ReadmeWriter for generating readmes for vals with OpenAI. It can both draft readmes and update them directly PRs welcome! See Todos below for some ideas I have. Usage To draft a readme for a given code, use the draftReadme method: import { ReadmeWriter } from "https://esm.town/v/nbbaier/readmeGPT";
const readmeWriter = new ReadmeWriter({});
const val = "https://www.val.town/v/:username/:valname";
const generatedReadme = await readmeWriter.draftReadme(val); To write and update a readme for a given code, use the writeReadme method: import { ReadmeWriter } from "https://esm.town/v/nbbaier/readmeGPT";
const readmeWriter = new ReadmeWriter({});
const val = "https://www.val.town/v/:username/:valname";
const successMessage = await readmeWriter.writeReadme(val); API Reference Class: ReadmeWriter The ReadmeWriter class represents a utility for generating and updating README files. Constructor Creates an instance of the ReadmeWriter class. Parameters: model (optional): The model to be used for generating the readme. Defaults to "gpt-3.5-turbo". apiKey (optional): An OpenAI API key. Defaults to Deno.env.get("OPENAI_API_KEY") . Methods draftReadme(val: string): Promise<string> : Generates a readme for the given val. Parameters: val : URL of the code repository. Returns: A promise that resolves to the generated readme. writeReadme(val: string): Promise<string> : Generates and updates a readme for the given val. Parameters: val : URL of the code repository. Returns: A promise that resolves to a success message if the update is successful. Todos [ ] Additional options to pass to the OpenAI model [ ] Ability to pass more instructions to the prompt to modify how the readme is constructed
Script
This val provides a class `ReadmeWriter` for generating readmes for vals with OpenAI. It can both draft readmes and update them directly
- `apiKey` (optional): An OpenAI API key. Defaults to `Deno.env.get("OPENAI_API_KEY")`.
- [ ] Additional options to pass to the OpenAI model
import OpenAI, { type ClientOptions } from "npm:openai";
openai: OpenAI;
const { model, ...openaiOptions } = options;
this.openai = new OpenAI(openaiOptions);
private async performOpenAICall(prompt: string) {
const response = await this.openai.chat.completions.create({
throw new Error("No response from OpenAI");
throw new Error("No readme returned by OpenAI. Try again.");
const readme = await this.performOpenAICall(prompt);
MuxAITranscript
@decepulis
Generate CuePoints and transcripts for your Mux video Adapted from the blog post, Build an AI-powered interactive video transcript with Mux Player CuePoints This Val exposes an HTTP endpoint that takes a Mux Asset ID and a list of speakers and Uses Mux's auto-generated captions to generate a CuePoints object for Mux Player Uses AssemblyAI for speaker labeling (diarization) Uses GPT-4o to format text Fork it and use it as a foundation for your own interactive video transcript project. Usage: Required environment variables: 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 to create a new one for testing. AssemblyAI API key ( ASSEMBLYAI_API_KEY ). Get it from their dashboard here OpenAI API key ( OPENAI_API_KEY ). Get it from their dashboard here Make 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. {
"asset_id": "00OZ8VnQ01wDNQDdI8Qw3kf01FkGTtkMq2CW901ltq64Jyc",
"speakers": ["Matt", "Nick"]
} Limitations This is just a demo, so it's obviously not battle hardened. The biggest issue is that it does this whole process synchronously, so if the any step takes longer than the Val's timeout, you're hosed.
HTTP (deprecated)
- AssemblyAI API key (`ASSEMBLYAI_API_KEY`). Get it [from their dashboard here](https://www.assemblyai.com/app/account)
- OpenAI API key (`OPENAI_API_KEY`). Get it [from their dashboard here](https://platform.openai.com/api-keys)
Make 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.
import { AssemblyAI } from "npm:assemblyai";
import OpenAI from "npm:openai";
import { zodResponseFormat } from "npm:openai/helpers/zod";
import z from "npm:zod";
apiKey: Deno.env.get("ASSEMBLY_AI_KEY"),
const openai = new OpenAI({
apiKey: Deno.env.get("OPEN_API_KEY"),
const responseFormat = z.object({ cues: cueFormat });
const completion = await openai.chat.completions.create({
messages: [
valleGetValsContextWindow
@janpaul123
An interactive, runnable TypeScript val by janpaul123
Script
el.attributes.filter(a => a.name === "href").map(a => a.value)
prompt: "Write a val that uses OpenAI",
code: `import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
"messages": [