Search

4,002 results found for openai (6073ms)

Code
3,898

.trim();
const res = await fetch("https://text.pollinations.ai/openai", {
method: "POST",
headers: {
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 { Hono } from "npm:hono@4.4.12";
import { OpenAI } from "https://esm.town/v/std/openai";
import type { Context } from "npm:hono@4.4.12";
import { streamText } from "npm:hono@4.4.12/streaming";
// --- BACKEND SERVICES ---
const services = {
  async callOpenAI(
    systemPrompt: string,
    userContent: string | object,
      c = null,
    } = options;
    const openai = new OpenAI();
    const messages: any[] = [{ role: "system", content: systemPrompt }, {
      role: "user",
    if (isJson) requestPayload.response_format = { type: "json_object" };
    try {
      const completion = await openai.chat.completions.create(requestPayload);
      if (stream && c) {
        return streamText(c, async (s) => {
      return completion;
    } catch (e) {
      console.error(`Error calling OpenAI: ${e.message}`);
      throw new Error("AI service failed.");
    }
  }
  const userContent = `Company Context: ${JSON.stringify(company_context)}`;
  return services.callOpenAI(config.prompts.INDUSTRY_GENERATOR, userContent, {
    c,
    isJson: true,
    );
  try {
    const completion = await services.callOpenAI(
      "You are a helpful assistant following strict output rules.",
      prompt,
    ...(type === "occupations" && { industry: body.industry }),
SESSION };
  return services.callOpenAI(config.prompts.DYNAMIC_LIST_GENERATOR, payload, {
    c,
    isJson: true,
    .replace("{{company_context}}", JSON.stringify(company_context));
  return services.callOpenAI(
    "You are a helpful assistant following strict output rules.",
    userContent,
  const userPrompt = "Proceed with the task defined in your system instructions.";
  return services.callOpenAI(systemPrompt, userPrompt, { c, stream: true });
});
// --- END MODIFIED ENDPOINT ---
      briefing,
    );
    const criteriaCompletion = await services.callOpenAI(
      "You are a helpful assistant following strict output rules.",
      criteriaPrompt,
      raw_output: first_draft,
    };
    return services.callOpenAI(config.prompts.EVALUATOR_AGENT, userContent, {
      c,
      isJson: true,
## QA Critique
${critique}`;
  return services.callOpenAI(config.prompts.REFINER_AGENT, userContent, {
    c,
    stream: true,
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" },
realtime/Big/main.ts
11 matches
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// ============================================================================
async function generateAnalysis(
openai: OpenAI,
goal: string,
): Promise<string> {
try {
const completion = await executeWithTimeout(
openai.chat.completions.create({
model: CONFIG.AI_MODEL,
messages: [
async function generatePlanTree(
openai: OpenAI,
goal: string,
analysis: string,
try {
const completion = await executeWithTimeout(
openai.chat.completions.create({
model: CONFIG.AI_MODEL,
messages: [
const goal = validateGoal(body.goal);
// Initialize OpenAI
let openai: OpenAI;
try {
openai = new OpenAI();
} catch (error) {
throw new PlannerError(
"OpenAI API key not configured",
"MISSING_API_KEY",
500,
// Execute two-phase planning
const analysis = await generateAnalysis(openai, goal);
const plan = await generatePlanTree(openai, goal, analysis);
// Extract metrics
// @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";
let currentState: JobState;
try {
const openai = new OpenAI();
currentState = await blob.getJSON(jobId);
await blob.setJSON(jobId, currentState);
const plannerCompletion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
const explorerPromises = generatedPaths.map((path) => {
return openai.chat.completions.create({
model: "gpt-4o",
messages: [
await blob.setJSON(jobId, currentState);
const validatorCompletion = 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;
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**: