Search

3,760 results found for openai (8564ms)

Code
3,657

<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 = `
the user in English and tell them that they're using the OpenAI Realtime API, powered by the {{
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
import { streamText } from "npm:hono@4.4.12/streaming";
import type { Context } from "npm:hono@4.4.12";
import { OpenAI } from "https://esm.town/v/std/openai";
import { nanoid } from "npm:nanoid";
// --- CORE AI & HELPER LOGIC ---
const openai = new OpenAI();
const services = {
async callAI(
if (isJson) requestPayload.response_format = { type: "json_object" };
const completion = await openai.chat.completions.create(requestPayload);
const content = completion.choices?.[0]?.message?.content ?? "";
onDelta: (delta: string) => Promise<void>,
) {
const completionStream = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: systemPrompt }, {
## Other todos
- [ ] Get OpenTownie or Gemini or Claude or OpenAI to synthesize the core of these patterns into
- [ ] Convert this or into the basic react router guest book (and preserve this forum app in ano
- [ ] To what extent can these patterns be packaged up into a Val Town Router project? Would be
bomb/bms/main.ts
3 matches
// @ts-ignore
import { 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: [
bomb/orch/main.ts
3 matches
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// @ts-ignore
import { blob } from "https://esm.town/v/std/blob?v=11";
// --- CORE AI & ORCHESTRATION LOGIC ---
const openai = new OpenAI();
const INDEX_KEY = "mas_orchestrator_index";
const MAX_ATTEMPTS_PER_STEP = 5;
): Promise<any> {
try {
const completion = await openai.chat.completions.create({
model: "gpt-4o", // Using a powerful model for orchestration
messages: [
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { 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" },
// Récupérer la clé API depuis les env variables
const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
if (!OPENAI_API_KEY) {
return new Response(
JSON.stringify({ error: "OPENAI_API_KEY not configured" }),
{
status: 500,
}
// Appeler l'API OpenAI Chat Completions avec vision
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${OPENAI_API_KEY}`,
},
body: JSON.stringify({
if (req.method === "POST" && url.pathname === "/moderate") {
try {
const { OpenAI } = await import("https://esm.town/v/std/openai");
const openai = new OpenAI();
const body = await req.json();
if (body.type === "text") {
const response = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
} else if (body.type === "image") {
const base64 = body.content.split(",")[1];
const response = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
if (req.method === "POST" && url.pathname === "/moderateDoc") {
try {
const { OpenAI } = await import("https://esm.town/v/std/openai");
const openai = new OpenAI();
const formData = await req.formData();
const file = formData.get("file") as File;
const text = await file.text(); // Extracts text for txt/doc/pdf (works if Val Town suppor
const response = await openai.chat.completions.create({
model: "gpt-4o",
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;