11 console.log("Received:", message, "from", from);
12
13 // Get OpenAI API key
14 const openaiKey = Deno.env.get("OPENAI_API_KEY")!;
15
16 // 1. Ask OpenAI for a response
17 let aiResponse = "Sorry, something went wrong.";
18 try {
19 const openaiRes = await fetch("https://api.openai.com/v1/chat/completions", {
20 method: "POST",
21 headers: {
22 Authorization: `Bearer ${openaiKey}`,
23 "Content-Type": "application/json",
24 },
39 });
40
41 const data = await openaiRes.json();
42 aiResponse = data.choices?.[0]?.message?.content ?? aiResponse;
43 } catch (err) {
44 console.error("OpenAI error:", err);
45 }
46
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
844
845export default async function(req: Request) {
846 const { OpenAI } = await import("https://esm.town/v/std/openai");
847 const { PDFExtract } = await import("npm:pdf.js-extract");
848
858 const action = url.searchParams.get("action");
859 const sourceUrl = import.meta.url.replace("esm.town", "val.town");
860 const openai = new OpenAI();
861 const MAX_TEXT_SUGGEST = 20000;
862 const MAX_TEXT_ANALYZE = 30000;
868 agentName: string,
869 ): Promise<object> {
870 log.push({ agent: agentName, type: "step", message: `Calling OpenAI gpt-4o for ${agentName}...` });
871 try {
872 const response = await openai.chat.completions.create({
873 model: "gpt-4o",
874 messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
1import { type Context, Hono } from "https://esm.sh/hono@3.11.7";
2import { blob } from "https://esm.town/v/std/blob";
3import { OpenAI } from "https://esm.town/v/std/openai";
4import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
5import Groq from "npm:groq-sdk";
16
17const app = new Hono();
18const openai = new OpenAI();
19
20// Get all voice notes (for admin/dashboard)
153async function transcribeAudio(voiceNoteId: string, audioBuffer: ArrayBuffer) {
154 try {
155 // Convert ArrayBuffer to File for OpenAI
156 const audioFile = new File([audioBuffer], "audio.webm", { type: "audio/webm" });
157
6
7- 🎙️ Record voice notes directly in the browser
8- 🤖 AI-powered transcription using OpenAI Whisper
9- 🔗 Share voice notes via unique URLs
10- ⏰ Set expiration by max listens or date
53- **Database**: SQLite for voice note metadata
54- **Storage**: Val Town Blob storage for audio files
55- **AI**: OpenAI Whisper for transcription
56- **Frontend**: React with TypeScript
57- **Styling**: TailwindCSS
102```
103
104### OpenAI Integration
105```ts
106import { OpenAI } from "https://esm.town/v/std/openai";
107const openai = new OpenAI();
108const completion = await openai.chat.completions.create({
109 messages: [{ role: "user", content: "Describe this weather for photography" }],
110 model: "gpt-4o-mini",
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3export default async function(req: Request): Promise<Response> {
11 });
12 }
13 const openai = new OpenAI();
14
15 try {
28 }
29
30 const stream = await openai.chat.completions.create(body);
31
32 if (!body.stream) {
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
89
90### OpenAI
91
92```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96 messages: [
97 { role: "user", content: "Say hello in a creative way" },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },