Search
Code3,285
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({messages: [{ role: "user", content: "Say hello in a creative way" },
<library>## OpenAIVal Town includes a free, proxied OpenAI:```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({messages: [{ role: "user", content: "Say hello in a creative way" },```OpenAI only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:`const { OpenAI } = await import "https://esm.town/v/std/openai");`</library>
```### OpenAI Integration```typescriptimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({messages: [{ role: "user", content: "Say hello" }],model: "gpt-4o-mini",
console.log("Received:", message, "from", from); // Get OpenAI API key const openaiKey = Deno.env.get("OPENAI_API_KEY")!; // 1. Ask OpenAI for a response let aiResponse = "Sorry, something went wrong."; try { const openaiRes = await fetch("https://api.openai.com/v1/chat/completions", { method: "POST", headers: { Authorization: `Bearer ${openaiKey}`, "Content-Type": "application/json", }, }); const data = await openaiRes.json(); aiResponse = data.choices?.[0]?.message?.content ?? aiResponse; } catch (err) { console.error("OpenAI error:", err); }
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: "Say hello in a creative way" },
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: "Say hello in a creative way" },
export default async function(req: Request) { const { OpenAI } = await import("https://esm.town/v/std/openai"); const { PDFExtract } = await import("npm:pdf.js-extract"); const action = url.searchParams.get("action"); const sourceUrl = import.meta.url.replace("esm.town", "val.town"); const openai = new OpenAI(); const MAX_TEXT_SUGGEST = 20000; const MAX_TEXT_ANALYZE = 30000; agentName: string, ): Promise<object> { log.push({ agent: agentName, type: "step", message: `Calling OpenAI gpt-4o for ${agentName}...` }); try { const response = await openai.chat.completions.create({ model: "gpt-4o", messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
import { type Context, Hono } from "https://esm.sh/hono@3.11.7";import { blob } from "https://esm.town/v/std/blob";import { OpenAI } from "https://esm.town/v/std/openai";import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";import Groq from "npm:groq-sdk";const app = new Hono();const openai = new OpenAI();// Get all voice notes (for admin/dashboard)async function transcribeAudio(voiceNoteId: string, audioBuffer: ArrayBuffer) { try { // Convert ArrayBuffer to File for OpenAI const audioFile = new File([audioBuffer], "audio.webm", { type: "audio/webm" });
- 🎙️ Record voice notes directly in the browser- 🤖 AI-powered transcription using OpenAI Whisper- 🔗 Share voice notes via unique URLs- ⏰ Set expiration by max listens or date- **Database**: SQLite for voice note metadata- **Storage**: Val Town Blob storage for audio files- **AI**: OpenAI Whisper for transcription- **Frontend**: React with TypeScript- **Styling**: TailwindCSS
```### OpenAI Integration```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({ messages: [{ role: "user", content: "Describe this weather for photography" }], model: "gpt-4o-mini",
reconsumeralization
import { OpenAI } from "https://esm.town/v/std/openai";
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
/**
* Practical Implementation of Collective Content Intelligence
* Bridging advanced AI with collaborative content creation
*/
exp
kwhinnery_openai
lost1991
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
No docs found