Search

4,002 results found for openai (3655ms)

Code
3,898

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 calling
server-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 session
2. **SIP Flow**:
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>OpenAI Realtime API Voice Agent</title>
<style>
:root {
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" },
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" },
function widgetMeta(invoking?: string, invoked?: string) {
return {
"openai/outputTemplate": WIDGET_URI,
"openai/widgetResourceUri": WIDGET_URI,
"openai/toolInvocation/invoking": invoking,
"openai/toolInvocation/invoked": invoked,
"openai/widgetAccessible": true,
"openai/resultCanProduceWidget": true,
} as const;
}
_meta: {
...widgetMeta(),
"openai/widgetCSP": {
connect_domains: [
baseUrl,
// @ts-nocheck
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
import { Hono } from "npm:hono@4.4.12";
import { z } from "npm:zod@3.23.8";
`;
/** Calls OpenAI to generate a world specification from a user description. */
async function generateWorldFromAI(
description: string,
openai: OpenAI,
): Promise<WorldSpec> {
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
}
const openai = new OpenAI();
const worldData = await generateWorldFromAI(description, openai);
const world: WorldSpecWithMacros = { ...worldData, macros: macroRegistry };
type UnknownObject = Record<string, unknown>;
export interface OpenAiGlobals<
ToolInput extends UnknownObject = UnknownObject,
ToolOutput extends UnknownObject = UnknownObject,
}
export interface OpenAIWidgetAPI<
ToolInput extends UnknownObject = UnknownObject,
ToolOutput extends UnknownObject = UnknownObject,
ToolResponseMetadata extends UnknownObject = UnknownObject,
WidgetState extends UnknownObject = UnknownObject,
> extends OpenAiGlobals<
ToolInput,
ToolOutput,
}
export const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
export interface SetGlobalsEvent
extends CustomEvent<{ globals: Partial<OpenAiGlobals> }> {
type: typeof SET_GLOBALS_EVENT_TYPE;
}
declare global {
interface GlobalThis {
openai?: OpenAIWidgetAPI;
}
}
export function getOpenAI(): OpenAIWidgetAPI | undefined {
const api = globalThis as typeof globalThis & {
openai?: OpenAIWidgetAPI;
};
return api.openai;
}
},
},
openai: {
models: [],
},
function widgetMeta(invoking?: string, invoked?: string) {
return {
"openai/outputTemplate": WIDGET_URI,
"openai/toolInvocation/invoking": invoking,
"openai/toolInvocation/invoked": invoked,
"openai/widgetAccessible": true,
"openai/resultCanProduceWidget": true,
} as const;
}
_meta: {
...widgetMeta(),
"openai/widgetCSP": {
connect_domains: [baseUrl, "https://esm.sh", "https://cdn.jsdelivr.net"],
resource_domains: [baseUrl, "https://esm.sh", "https://cdn.jsdelivr.net"],