Search

3,267 results found for โ€œopenaiโ€ (1749ms)

Code
3,172

capabilities: {
tools: {
listChanged: true // Critical: tells OpenAI to fetch tools
}
},
<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" },
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;
// Accept the call.
const url = `https://api.openai.com/v1/realtime/calls/${callId}/accept`;
const headers = makeHeaders("application/json");
const body = JSON.stringify(makeSession());
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", () => {
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" },
import { OpenAI } from "https://esm.town/v/std/openai";
export async function wisdom() {
const openai = new OpenAI();
try {
const completion = await openai.chat.completions.create({
messages: [
{
// ---------- env ----------
const OPENAI_API_KEY =
"sk-proj-xN07oO7FGJVJ5QeA-X4MDv8SHnxvnsVbVK0h7YVLeFU2czOncZnoE4m7vUEtEiBDNyFv9-tQ-4T3BlbkFJYww
const NOTION_API_KEY = "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";
const HOUSE_TZ = Deno.env.get("HOUSE_TZ") || "America/Los_Angeles";
if (!OPENAI_API_KEY) throw new Error("Missing OPENAI_API_KEY");
if (!NOTION_API_KEY) throw new Error("Missing NOTION_API_KEY");
if (!NOTION_DB_ID) throw new Error("Missing NOTION_DB_ID");
return { start: null, end: null };
}
async function openaiStructured<T>(userQ: string): Promise<T> {
const body = {
model: "gpt-4o-mini",
};
const r = await fetch("https://api.openai.com/v1/responses", {
method: "POST",
headers: {
authorization: `Bearer ${OPENAI_API_KEY}`,
"content-type": "application/json",
},
if (!r.ok) {
throw new Error(
`OpenAI structured parse failed: ${r.status} ${await r.text()}`,
);
}
return JSON.parse(raw) as T;
}
async function openaiAnswer(userQ: string, rows: any[]) {
const body = {
model: "gpt-4o-mini",
};
const r = await fetch("https://api.openai.com/v1/responses", {
method: "POST",
headers: {
authorization: `Bearer ${OPENAI_API_KEY}`,
"content-type": "application/json",
},
});
if (!r.ok) {
throw new Error(`OpenAI answer failed: ${r.status} ${await r.text()}`);
}
const data = await r.json();
ok: true,
env: {
OPENAI: Boolean(OPENAI_API_KEY),
NOTION: Boolean(NOTION_API_KEY),
DB: Boolean(NOTION_DB_ID),
if (!q) return asJSON({ error: "Missing ?q=<question>" }, 400);
const params = await openaiStructured<{
dateISO: string | null;
room: string | null;
if (mode === "dryrun") return asJSON({ params, rows });
const answer = await openaiAnswer(q, rows);
return new Response(answer, { headers: { "content-type": "text/plain" } });
} catch (e: any) {
โ€ฆ
29
โ€ฆ
Next