Search
Code3,901
<meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>OpenAI Realtime API Voice Agent</title> <style> :root {const NR_TYPE = "near_field";const INSTRUCTIONS = ` Greet the user in English and tell them that they're using the OpenAI Realtime API, powered by the {{model}} model. Give them a very brief summary of the benefits of the Realtime API based on the headline below, and then ask if they have any questions. - higher audio quality - improved handling of alphanumerics (eg, properly understanding credit card and phone numbers) - support for the OpenAI Prompts API - support for MCP-based tools - auto-truncation to reduce context size// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";// --- TYPE DEFINITIONS --- <div id="start-overlay" class="fixed inset-0 bg-gray-900/80 backdrop-blur-sm z-20 flex flex-col justify-center items-center text-center p-8"> <h1 class="text-4xl font-bold mb-4">✨ AI & Gesture Controlled Robotic Arm ✨</h1> <p class="text-lg text-gray-300 max-w-2xl mb-8">This demo uses your webcam for real-time hand tracking and OpenAI for autonomous control. Please grant camera permissions to begin.</p> <button id="start-camera-btn" class="px-8 py-4 bg-pink-600 text-white font-bold rounded-lg hover:bg-pink-700 transition-transform transform hover:scale-105 shadow-lg">Start Camera & Control</button> <p class="text-sm text-gray-500 mt-6">Powered by Val Town, Three.js & MediaPipe</p> if (req.method === "POST" && action === "choreograph") { try { const openai = new OpenAI(); const body = await req.json(); const goal = body.goal; ]; const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: messages,// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";// @ts-ignoreimport { blob } from "https://esm.town/v/std/blob?v=11";const MAX_DEPTH = 4;const CROSS_EXAMINE_DEPTH_INTERVAL = 2;const openai = new OpenAI();const INDEX_KEY = "totem_index"; } const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [<script>console.log(window.openai);debugger;const bEl = document.getElementById("bEl");window.addEventListener("openai:set_globals", (event) => { const value = event.detail.globals['toolOutput']; console.log('set_globals', event.detail.globals); } const { a, b, answer} = window.openai.toolOutput; const answerEl = document.getElementById("answerEl"); aEl.value = a;button.onclick = async () => { // don't add them in JS, call the tool. const response = await window.openai.callTool('add', {a: Number(aEl.value), b: Number(bEl.value)}); console.log(response); const { a, b, answer} = response.structuredContent; "Adds two numbers together (a and b) and stores them in the 'answer' field.", _meta: { "openai/outputTemplate": "ui://widget/add.html", "openai/toolInvocation/invoking": "Displaying the adder", "openai/toolInvocation/invoked": "Displayed the adder", "openai/widgetAccessible": true, }, inputSchema: { a: z.number(), b: z.number() }, apiKeyInput: '', // Model selection selectedModel: 'openai/gpt-oss-120b', // Browser search tool toggle useBrowserSearch: true, model: this.selectedModel, reasoning_effort: this.reasoningEffort, tools: (() => { const list = []; const isOss = !!(this.selectedModel && this.selectedModel.startsWith('openai/gpt-oss')); if (isOss) { if (this.useBrowserSearch) list.push({ type: 'browser_search' }); if (this.useCodeInterpreter) list.push({ type: 'code_interpreter' }); } return list; })(), temperature: this.temperature, ...(this.maxTokens ? { max_tokens: this.maxTokens } : {}), model: this.selectedModel, reasoning_effort: this.reasoningEffort, tools: (() => { const list = []; const isOss = !!(this.selectedModel && this.selectedModel.startsWith('openai/gpt-oss')); if (isOss) { if (this.useBrowserSearch) list.push({ type: 'browser_search' }); if (this.useCodeInterpreter) list.push({ type: 'code_interpreter' }); } return list; })(), temperature: this.temperature, ...(this.maxTokens ? { max_tokens: this.maxTokens } : {}), <div class="relative"> <select id="preset-model-new" x-model="newPresetSettings.selectedModel" class="px-2 py-1 pr-8 border border-gray-200 bg-white rounded-md focus:ring-2 focus:ring-blue-500 appearance-none text-xs w-full"> <option value="openai/gpt-oss-120b">openai/gpt-oss-120b</option> <option value="openai/gpt-oss-20b">openai/gpt-oss-20b</option> <option value="llama-3.1-8b-instant">llama-3.1-8b-instant</option> <option value="llama-3.3-70b-versatile">llama-3.3-70b-versatile</option> <div class="relative"> <select id="preset-model-select" x-model="editingPresetSettings.selectedModel" class="px-2 py-1 pr-8 border border-gray-200 bg-white rounded-md focus:ring-2 focus:ring-blue-500 appearance-none text-xs w-full"> <option value="openai/gpt-oss-120b">openai/gpt-oss-120b</option> <option value="openai/gpt-oss-20b">openai/gpt-oss-20b</option> <option value="llama-3.1-8b-instant">llama-3.1-8b-instant</option> <option value="llama-3.3-70b-versatile">llama-3.3-70b-versatile</option> <div class="relative"> <select x-model="selectedModel" @change="onModelChange()" class="px-2 py-1 pr-8 border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 rounded-md focus:ring-2 focus:ring-blue-500 appearance-none text-xs w-full dark:text-gray-200"> <option value="openai/gpt-oss-120b">openai/gpt-oss-120b</option> <option value="openai/gpt-oss-20b">openai/gpt-oss-20b</option> <option value="llama-3.1-8b-instant">llama-3.1-8b-instant</option> <option value="llama-3.3-70b-versatile">llama-3.3-70b-versatile</option> <span>JSON mode</span> </label> <label class="inline-flex items-center gap-2 text-xs text-gray-600 dark:text-gray-300" x-show="selectedModel && selectedModel.startsWith('openai/gpt-oss')"> <input type="checkbox" x-model="useBrowserSearch" @change="onUseBrowserSearchChange()" class="rounded border-gray-300 dark:border-gray-600"> <span>browser search</span> </label> <label class="inline-flex items-center gap-2 text-xs text-gray-600 dark:text-gray-300" x-show="selectedModel && selectedModel.startsWith('openai/gpt-oss')"> <input type="checkbox" x-model="useCodeInterpreter" @change="onUseCodeInterpreterChange()" class="rounded border-gray-300 dark:border-gray-600"> <span>code interpreter</span> <div class="relative"> <select x-model="selectedModel" @change="onModelChange()" class="px-2 py-1 pr-8 border border-gray-200 bg-white rounded-md focus:ring-2 focus:ring-blue-500 appearance-none text-xs w-full"> <option value="openai/gpt-oss-120b">openai/gpt-oss-120b</option> <option value="openai/gpt-oss-20b">openai/gpt-oss-20b</option> <option value="llama-3.1-8b-instant">llama-3.1-8b-instant</option> <option value="llama-3.3-70b-versatile">llama-3.3-70b-versatile</option> <span>JSON mode</span> </label> <label class="inline-flex items-center gap-2 text-xs" x-show="selectedModel && selectedModel.startsWith('openai/gpt-oss')"> <input type="checkbox" x-model="useBrowserSearch" @change="onUseBrowserSearchChange()" class="rounded border-gray-300"> <span>browser search</span> </label> <label class="inline-flex items-center gap-2 text-xs" x-show="selectedModel && selectedModel.startsWith('openai/gpt-oss')"> <input type="checkbox" x-model="useCodeInterpreter" @change="onUseCodeInterpreterChange()" class="rounded border-gray-300"> <span>code interpreter</span>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" },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