Search

4,001 results found for openai (1893ms)

Code
3,897

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
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 { generateOpenGraphTags, OpenGraphData } from "https://esm.town/v/dthyresson/generateOpen
import { ValTownLink } from "https://esm.town/v/dthyresson/viewOnValTownComponent";
import { chat } from "https://esm.town/v/stevekrouse/openai";
import * as fal from "npm:@fal-ai/serverless-client";
const { message, topic, position, sessionContext } = await req.json();
const apiKey = __secrets['OPENAI_API_KEY'];
if (!apiKey) {
return Response.json({ error: 'OpenAI API key not configured' }, { status: 500 });
}
Be professional but challenging. Push them to think critically and defend their positions with s
// Call OpenAI API
const response = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
if (!response.ok) {
const error = await response.text();
console.error('OpenAI API error:', error);
return Response.json({ error: 'Failed to get AI response' }, { status: 500 });
}
// @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";
* long-running task processing and blob storage for persistent state management.
*
* The novel application of OpenAI is the agentic framework itself:
* 1. Strategist: Deconstructs the request into a Blueprint.
* 2. Researcher: Gathers Raw Materials based on the Blueprint.
*/
async function runAgent(
openai: OpenAI,
systemPrompt: string,
userMessage: string,
): Promise<string> {
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
// Agent 1: Strategist
async function runStrategist(openai: OpenAI, userRequest: string) {
const content = await runAgent(
openai,
SYSTEM_PROMPT_STRATEGIST,
userRequest,
// Agent 2: Researcher
async function runResearcher(openai: OpenAI, blueprint: any) {
const userMessage = JSON.stringify({ blueprint });
const content = await runAgent(
openai,
SYSTEM_PROMPT_RESEARCHER,
userMessage,
// Agent 3: Creator
async function runCreator(openai: OpenAI, blueprint: any, rawMaterials: any) {
const userMessage = JSON.stringify({
blueprint,
});
const content = await runAgent(
openai,
SYSTEM_PROMPT_CREATOR,
userMessage,
// Agent 4: Refiner
async function runRefiner(openai: OpenAI, blueprint: any, draft: string) {
const userMessage = JSON.stringify({
blueprint: blueprint,
});
const content = await runAgent(
openai,
SYSTEM_PROMPT_REFINER,
userMessage,
// Agent 5: Communicator
async function runCommunicator(
openai: OpenAI,
blueprint: any,
pristine_output: string,
});
const content = await runAgent(
openai,
SYSTEM_PROMPT_COMMUNICATOR,
userMessage,
}) {
const { taskId, userRequest } = job;
const openai = new OpenAI();
try {
status: "running",
});
const strategistResponse = await runStrategist(openai, userRequest);
const blueprint = strategistResponse.blueprint;
if (!blueprint || !strategistResponse.reasoning) {
blueprint: blueprint,
});
const researcherResponse = await runResearcher(openai, blueprint);
const rawMaterials = researcherResponse.raw_materials;
if (!rawMaterials || !researcherResponse.reasoning) {
rawMaterials: rawMaterials,
});
const creatorResponse = await runCreator(openai, blueprint, rawMaterials);
const draft = creatorResponse.draft;
if (!draft || !creatorResponse.reasoning) {
draft: draft,
});
const refinerResponse = await runRefiner(openai, blueprint, draft);
const pristine_output = refinerResponse.pristine_output;
if (pristine_output === undefined || !refinerResponse.red_team_analysis) {
});
const communicatorResponse = await runCommunicator(
openai,
blueprint,
pristine_output,
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" },
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" },