Search
Code3,901
# hello-realtime-videoHello Realtime is a complete OpenAI Realtime application that supports WebRTCusers. You can access the app via WebRTC athttps://hello-realtime-video.val.run.websocket interface.If you remix the app, you'll just need to pop in your own OPENAI_API_KEY (fromplatform.openai.com).observer.post("/:callId", async (c) => { const callId = c.req.param("callId"); const url = `wss://api.openai.com/v1/realtime?call_id=${callId}`; const ws = new WebSocket(url, { headers: makeHeaders() }); ws.on("open", () => { <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>OpenAI Realtime API Voice Agent</title> <style> :root {This script allows you to:- Send emails to OpenAI. The text will be treated as the prompt- Parse PDF attachments and include their contents in the AI's analysis.- Get response directly to your inbox.1. Copy this Val and save it as an Email Val (choose Val type in top-right corner of editor)2. Add your OpenAI API key to line 8 (or use an environment variable: https://docs.val.town/reference/environment-variables/)3. Copy the email address of the Val (click 3 dots in top-right > Copy > Copy email address)// main controller functionexport async function emailValHandler(receivedEmail) { const openaiUrl = "https://api.openai.com/v1/chat/completions"; const apiKey = Deno.env.get("OPENAI_KEY"); // replace this entire line with your OpenAI API key as a string, e.g., "sk-123..." or use environment variable: https://docs.val.town/reference/environment-variables/ const model = "gpt-4o-mini"; if (!apiKey) { throw new Error( "OPENAI_KEY environment variable is not set. Please set it or replace this line with your API key.", ); } const prompt = generatePrompt(receivedEmail, pdfTexts, emailText); // step 4: send prompt to openai const openaiResponse = await sendRequestToOpenAI(prompt, openaiUrl, apiKey, model); // log the openai response console.log("openai response:", openaiResponse); // step 5: send the response back via email await sendResponseByEmail(receivedEmail.from, openaiResponse); console.log("response email sent.");}// helper function to generate a prompt for openaifunction generatePrompt(email, pdfTexts, emailText) { // extract the first name from the 'from' field if it exists}// helper function to send a request to openaiasync function sendRequestToOpenAI(prompt, openaiUrl, apiKey, model) { try { // prepare the openai messages payload const messages = [ { }; // send the request to openai const response = await fetch(openaiUrl, { method: "POST", body: JSON.stringify(body), // parse the response const data = await response.json(); return data.choices[0]?.message?.content || "no response from openai."; } catch (err) { console.error("error in sendRequestToOpenAI:", err); return "error processing your request."; }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" }, const { query } = await request.json(); const { OpenAI } = await import("https://esm.town/v/std/openai"); const openai = new OpenAI(); const response = await openai.chat.completions.create({ messages: [ {const REALTIME_BASE_URL = "https://api.openai.com/v1/realtime";const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");if (!OPENAI_API_KEY) { throw new Error("π΄ OpenAI API key not configured");}export function makeHeaders(contentType?: string) { const obj: Record<string, string> = { Authorization: `Bearer ${OPENAI_API_KEY}`, }; if (contentType) obj["Content-Type"] = contentType;sip.post("/", async (c) => { // Verify the webhook. const OPENAI_SIGNING_SECRET = Deno.env.get("OPENAI_SIGNING_SECRET"); if (!OPENAI_SIGNING_SECRET) { console.error("π΄ webhook secret not configured"); return c.text("Internal error", 500); } const webhook = new Webhook(OPENAI_SIGNING_SECRET); const bodyStr = await c.req.text(); let callId: string | undefined;# hello-realtime**Hello Realtime** is a OpenAI Realtime app that supports both WebRTC and SIP(telephone) users. You can access the app via WebRTC at[hello-realtime.val.run](https://hello-realtime.val.run), or via SIP by callingserver-side websocket interface.If you remix the app, you'll just need to pop in your own `OPENAI_API_KEY` (from[platform.openai.com](https://platform.openai.com)), and if you want SIP, the`OPENAI_SIGNING_SECRET`.## Architecture - Browser connects to frontend - creates WebRTC offer - `/rtc` endpoint handles SDP negotiation with OpenAI - observer established to monitor session2. **SIP Flow**: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