Search

4,004 results found for β€œopenai” (5726ms)

Code
3,900

} else if (step.endpoint) {
this.log("INFO", stepComponent, \`Calling endpoint: \${step.endpoint}\`)
const isStreaming = (step.endpoint === "/api/tools/openai_call" || step.endpoint === "/ap
&& resolvedInputs.stream === true;
// --- CRITICAL: You MUST include EITHER 'action' OR 'endpoint' ---
"action": "client:action_name", // Use for client tools (human_input, transform)
"endpoint": "/api/tools/tool_name", // Use for backend tools (openai_call, http_fetch)
// --- A step CANNOT have both or neither. ---
Every single step in the \`steps\` array **MUST** have exactly one of the following properties:
* \`"action"\`: Use this **only** for client-side tools listed in the manifest (e.g., \`"client:
backend tools listed in the manifest (e.g., \`"/api/tools/openai_call"\`, \`"/api/tools/http_fet
**A step will fail if it has NEITHER or BOTH.** The error you just saw (\`Step must have 'action
"id": "process_data",
"run_if": "this.check_for_error.apiFailed !== true",
"endpoint": "/api/tools/openai_call",
"inputs": { "messages": [...] },
"outputs": { "summary": "payload.choices[0].message.content" }
This is how you create a draft, evaluate it, and then refine it.
1. **'write_draft'**: (openai_call) -> outputs 'draft_text'
2. **'evaluate_draft'**: (qa_evaluation)
- inputs: { "briefing": "...", "first_draft": "{{write_draft.draft_text}}" }
},
{
tool: "openai_call",
endpoint: "/api/tools/openai_call",
description:
"Calls an OpenAI model for analysis, generation, or extraction.",
inputs: {
messages: "array (e.g., [{role: 'user', content: '...'}])",
response_format: "object (optional, e.g., {type: 'json_object'})",
},
outputs: "payload (OpenAI completion object)",
},
{
stream: "boolean (optional, default false)",
},
outputs: "payload (OpenAI completion object or stream)",
},
// --- *** NEW YAHOO FINANCE TOOL DEFINITION *** ---
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";
};
const openai = new OpenAI(); // Initialize once
// --- NEW YAHOO FINANCE CLIENT ---
const yahooFinance = new YahooFinance();
}
async function handleOpenAICall(
payload: {
messages: any[];
): Promise<any> {
const { messages, model = "gpt-4o-mini", stream, ...rest } = payload;
log("INFO", `Calling OpenAI model: ${model}`, { stream: !!stream, ...rest });
try {
return await openai.chat.completions.create({
model,
messages,
});
} catch (e) {
log("ERROR", `OpenAI call failed: ${e.message}`, e.stack);
throw e;
}
briefing,
);
const criteriaCompletion = await handleOpenAICall({
model: config.models.minor,
response_format: { type: "json_object" },
raw_output: first_draft,
};
const evalCompletion = await handleOpenAICall({
model: config.models.minor,
response_format: { type: "json_object" },
try {
const result = await handleOpenAICall({
model: config.models.major, // Use best model for refinement
messages: [{ role: "system", content: config.prompts.REFINER_AGENT }, {
const toolRegistry = {
"http_fetch": handleHttpFetch,
"openai_call": handleOpenAICall,
"text_manipulation": handleTextManipulation,
"qa_evaluation": handleQaEvaluation, // NEW
try {
const response = await handleOpenAICall({
model: config.models.major, // Use your best model
response_format: { type: "json_object" },
// Handle streaming for any tool that supports it
const isStreaming =
(toolName === "openai_call" || toolName === "refinement") &&
payload.stream === true;
bomb/test4/main.ts
9 matches
// @ts-nocheck
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";
}
async function handleOpenAICall(
payload: {
messages: any[];
const { messages, model = "gpt-4o-mini", stream, ...rest } = payload;
try {
const openai = new OpenAI();
if (!stream) {
return await openai.chat.completions.create({
model,
messages,
});
}
return await openai.chat.completions.create({
model,
messages,
const toolRegistry = {
"http_fetch": handleHttpFetch,
"openai_call": handleOpenAICall,
"text_manipulation": handleTextManipulation,
};
function generateClientHtml() {
description":"AI triage of issues","endpoint":"/api/tools/openai_call","run_if":"Array.isArray(t
}
};
try {
if (toolName === "openai_call" && payload.stream === true) {
log("INFO", "Starting streaming response");
const stream = await handleOpenAICall(payload, log);
return streamText(c, async (s) => {
try {
bomb/test3/main.ts
19 matches
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";
/**
* OpenAI Call Tool (Streaming and Non-Streaming)
*/
async function handleOpenAICall(
payload: {
messages: any[];
): Promise<any> {
const { messages, model = "gpt-4o-mini", stream, ...rest } = payload;
log("INFO", `Making OpenAI call to ${model}`, { stream, messages, ...rest });
try {
const openai = new OpenAI();
if (!stream) {
const completion = await openai.chat.completions.create({
model,
messages,
...rest,
});
log("SUCCESS", "OpenAI non-streaming call successful.");
return completion;
}
log("INFO", "Preparing for streaming call...");
return await openai.chat.completions.create({
model,
messages,
});
} catch (e) {
log("ERROR", "OpenAI API call failed.", e.message);
throw e;
}
const toolRegistry = {
"http_fetch": handleHttpFetch,
"openai_call": handleOpenAICall,
"text_manipulation": handleTextManipulation,
};
"id": "triage_issues",
"description": "AI triage of issues",
"endpoint": "/api/tools/openai_call",
"run_if": "typeof this.format_issues.formattedIssues === 'object'",
"inputs": {
"id": "brainstorm_outline",
"description": "Brainstorm outline (JSON Mode)",
"endpoint": "/api/tools/openai_call",
"inputs": {
"messages": [
"id": "write_post",
"description": "Write blog post (Streaming)",
"endpoint": "/api/tools/openai_call",
"inputs": {
"messages": [
"id": "analyze_weather",
"description": "Get AI analysis of the weather",
"endpoint": "/api/tools/openai_call",
"inputs": {
"messages": [
"id": "analyze_quote_streaming",
"description": "Analyze the quote with streaming",
"endpoint": "/api/tools/openai_call",
"inputs": {
"messages": [
};
const isStreaming = step.endpoint === "/api/tools/openai_call" &&
resolvedInputs.stream === true;
try {
// SPECIAL CASE: STREAMING OPENAI CALL
if (toolName === "openai_call" && payload.stream === true) {
log("INFO", "Starting streaming response");
const stream = await handleOpenAICall(payload, log);
return streamText(c, async (s) => {
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 default async function(req: Request) {
try {
const openai = new OpenAI();
const formData = await req.formData();
const file = formData.get("file") as File;
const blob = new Blob([arrayBuffer], { type });
const audioFile = new File([blob], file.name);
const transcription = await openai.audio.transcriptions.create({
file: audioFile,
model: "whisper-1",
}
// πŸ”Ή Add your OpenAI moderation logic here (this is the code you asked about)
const response = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
// πŸ”Ή Error handling for empty responses
if (!response?.choices?.[0]?.message?.content) {
throw new Error("Empty response from OpenAI");
}
import React, { useEffect, useState } from "https://esm.sh/react@18.2.0";
import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
import { OpenAI } from "https://esm.town/v/std/openai";
// ======== BACKEND HANDLER ========
if (req.method === "POST") {
try {
const openai = new OpenAI();
const formData = await req.formData();
const file = formData.get("file");
const blob = new Blob([arrayBuffer], { type: type });
const audioFile = new File([blob], file.name);
const transcription = await openai.audio.transcriptions.create({
file: audioFile,
model: "whisper-1",
// πŸ”Ή AI Moderation Check
const response = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
trob/Todo/index.ts
3 matches
import { blob } from "https://esm.town/v/std/blob";
import { readFile } from "https://esm.town/v/std/utils@85-main/index.ts";
import { OpenAI } from "https://esm.town/v/std/openai";
import { Todo } from "../shared/types.ts";
const TODOS_BLOB_KEY = "todo_app_items_v1";
const openai = new OpenAI();
const app = new Hono();
: "none yet";
const completion = await openai.chat.completions.create({
model: "gpt-4o-mini",
temperature: 0.7,
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" },