Search
Code3,898
<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 sizeNote: 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 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";// --- AI BEHAVIORAL GUIDELINES ---async function handleApiDispatch(req: Request): Promise<Response> { try { const openai = new OpenAI(); const body = await req.json(); }`; const completion = await openai.chat.completions.create({ model: "gpt-4o", // Using a powerful model for complex logic messages: [// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";// --- AI BEHAVIORAL GUIDELINES --- if (req.method === "POST" && action === "getDispatchPlan") { try { const openai = new OpenAI(); const ctx = await req.json(); const userMessage = "Generate dispatch plan for: " + JSON.stringify(ctx); const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [import { OpenAI } from "https://esm.town/v/std/openai";import { StoryOptions, generateCuteAnimalName } from "../../shared/types.ts";const openai = new OpenAI();export async function generateStory(options: StoryOptions): Promise<{ title: string; content: string; animalName: string }> { `; // Generate the story using OpenAI const completion = await openai.chat.completions.create({ messages: [ { role: "system", content: "You are a creative children's storyteller who creates engaging, age-appropriate bedtime stories." },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" },// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";import { Hono } from "npm:hono@4.4.12"; </button> </form> <p class="text-sm text-gray-500 mt-6">Powered by Val Town & OpenAI</p> </div> <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 opacity-0 pointer-events-none transition-opacity duration-500"> } const openai = new OpenAI(); const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [ } } catch (error) { console.error("OpenAI API Error:", error); return c.json({ error: "An error occurred while communicating with the AI designer.", } const response = await fetch("https://api.openai.com/v1/chat/completions", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${process.env.OPENAI_API_KEY}`, }, body: JSON.stringify({ if (!response.ok) { throw new Error(`OpenAI API error: ${response.status}`); }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