Search

3,760 results found for β€œopenai” (8711ms)

Code
3,657

}
const apiKey = __secrets['openai_api_key'];
if (!apiKey) {
return Response.json({ error: "OpenAI API key not configured" }, { status: 500 });
}
const imageContent = await platform.getContentFile(referenceImagePath);
// Convert to base64 for OpenAI Vision API
const base64Image = btoa(String.fromCharCode(...new Uint8Array(imageContent)));
const dataUrl = `data:image/png;base64,${base64Image}`;
console.log(`Analyzing reference image: ${referenceImagePath}`);
// Use OpenAI Vision API to analyze the image
const visionResponse = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
if (!visionResponse.ok) {
const error = await visionResponse.text();
console.error("OpenAI Vision API error:", error);
return Response.json({
success: false,
}
const apiKey = __secrets['openai_api_key'];
if (!apiKey) {
return Response.json({ error: "OpenAI API key not configured" }, { status: 500 });
}
console.log(`Generating image ${i + 1}/${promptData.image_count} for prompt ${promptId}`
// Call OpenAI API
const openaiResponse = await fetch("https://api.openai.com/v1/images/generations", {
method: "POST",
headers: {
});
if (!openaiResponse.ok) {
const error = await openaiResponse.text();
console.error("OpenAI API error:", error);
continue;
}
const data = await openaiResponse.json();
const imageUrl = data.data[0]?.url;
) {
try {
const { OpenAI } = await import("https://esm.town/v/std/openai");
const openai = new OpenAI();
const body = await request.json();
const imageBase64 = body.image.split(",")[1];
} else prompt = "Describe this media content.";
const response = await openai.chat.completions.create({
model: "gpt-4o",
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" },
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" },
// @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";
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: [
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" },
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;
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**:
…
6
…