Search

3,812 results found for openai (2517ms)

Code
3,709

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";
/**
* 3. OpenAI Call Tool (Streaming and Non-Streaming)
* This single function handles both modes.
*/
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 });
try {
const openai = new OpenAI();
// Non-streaming call (default)
if (!stream) {
const completion = await openai.chat.completions.create({
model,
messages,
...rest,
});
log("SUCCESS", "OpenAI non-streaming call successful.");
return completion;
}
// here for completeness, but the router will call streamText directly.
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;
}
"http_fetch": handleHttpFetch,
"run_script": handleRunScript,
"openai_call": handleOpenAICall,
};
"id": "generate_summary",
"description": "Summarize package (Streaming)",
"endpoint": "/api/tools/openai_call",
"inputs": {
"messages": [
"id": "generate_questions",
"description": "Generate follow-up questions (JSON)",
"endpoint": "/api/tools/openai_call",
"inputs": {
"messages": [
};
const isStreaming = step.endpoint === "/api/tools/openai_call" && resolvedInputs.stream
const response = await fetch(step.endpoint, {
}
// Mock an OpenAI payload structure so the output mapping works
rawResultPayload = {
choices: [{ message: { content: fullStreamedResponse } }]
try {
// *** SPECIAL CASE: STREAMING OPENAI CALL ***
if (toolName === "openai_call" && payload.stream === true) {
const stream = await handleOpenAICall(payload, log);
// Return the stream directly to the client
return streamText(c, async (s) => {
_2 or _3) to create a fresh table.
### 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" },
bomb/next/main.ts
20 matches
// - Serves the client-side orchestrator HTML/JS (from "first" file)
// - Exposes all tools and custom functions (from "first" file) via a Hono route
// - Adds streaming capability to the 'openai_call' endpoint (from "second" file)
import { Hono } from "npm:hono@4.4.12";
import type { Context } from "npm:hono@4.4.12";
import { fetch } from "https://esm.town/v/std/fetch";
import { OpenAI } from "https://esm.town/v/std/openai";
// --- COMMON TYPES (from "first" file) ---
timestamp: string;
level: LogLevel;
component: string; // e.g., "Tool:OpenAI", "CustomFunc:ValidateData"
message: string;
details?: string; // Stringified JSON for complex objects
}
// 2. OpenAI Call Tool Endpoint (NON-STREAMING version)
// This is the original function from "first", renamed.
// It's called by the router when payload.stream is NOT true.
async function handleOpenAICall_nonStreaming(
reqPayload: {
messages: Array<{ role: "system" | "user" | "assistant"; content: string }>;
max_tokens,
} = reqPayload;
logger.log("INFO", `Making NON-STREAMING OpenAI call to ${model}`, {
messageCount: messages.length,
});
try {
const openai = new OpenAI(); // Assumes OPENAI_API_KEY is in environment
const completion = await openai.chat.completions.create({
model,
messages,
stream: false, // Explicitly false
});
logger.log("SUCCESS", "OpenAI call successful.", {
modelUsed: completion.model,
});
return completion;
} catch (e: any) {
logger.log("ERROR", "OpenAI API call failed.", e);
throw e;
}
{
"id": "clean_petal_width_llm",
"endpoint": "/api/tools/openai_call",
"description": "LLM cleaning for 'petal.width'",
"inputs": {
{
"id": "insights_llm",
"endpoint": "/api/tools/openai_call",
"description": "Get LLM insights on summary",
"inputs": {
* Main API Router
* Replicates the single router function from "first" file, but using Hono.
* Adds streaming logic for 'openai_call'.
----------------------------------------- */
app.post("/api/:endpointType/:endpointName", async (c: Context) => {
try {
// *** SPECIAL CASE: STREAMING OPENAI CALL ***
// This logic is from the "second" file, integrated here.
if (
endpointType === "tools" &&
endpointName === "openai_call" &&
payload.stream === true
) {
logger.log("INFO", "Handling as STREAMING OpenAI call.", payload);
const { messages, model, ...rest } = payload;
const openai = new OpenAI();
const completionStream = await openai.chat.completions.create({
model: model || "gpt-4o-mini",
messages,
responsePayload = await handleHttpFetch(payload, logger);
break;
case "openai_call":
// Calls the non-streaming version
responsePayload = await handleOpenAICall_nonStreaming(
payload,
logger,
"https://kill-the-newsletter.com/feeds/sqpw3htkhocwl299i9t8.xml"
],
["openaiNews", ["AI"], "https://openai.com/news/rss.xml"],
[
"anthropicNews",
} // 🤖 Détection IA (ChatGPT, Perplexity, Copilot, Gemini, etc.)
else if (
/(chat\.openai\.com|perplexity\.ai|claude\.ai|bard\.google\.com|gemini\.google\.com|yo
.test(ref)
) {
_2 or _3) to create a fresh table.
### 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" },
_2 or _3) to create a fresh table.
### 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;

Vals

88
View more
toowired
openaiproxy
 
Public
marcaureledubois
editImageWithOpenAI
 
Public
toowired
ttsGeneration
Text-to-speech generation using OpenAI TTS API
Public
jubertioai
hello-realtime
Sample app for the OpenAI Realtime API
Public
biowaffeln
openai-demo
 
Public

Docs

12
View more
OpenAI. Copy page Copy page. Copy this page as Markdown for LLMs. View as Markdown View this page as plain text. Open in ChatGPT Ask questions about this page. Use
OpenAI Codex. Copy page Copy page. Copy this page as Markdown for LLMs. View as Markdown View this page as plain text. Open in ChatGPT Ask questions about this page.
= $("p:nth-of-type(2)").first().text(); console.log(intro); Logs OpenAI is an American artificial intelligence (AI) research organization consisting of the non-profit OpenAI, Inc.[5] registered in Delaware and its for-profit subsidiary OpenAI Global, LLC.[6] One
await browser.close(); console.log(intro); Logs "OpenAI is an American artificial intelligence (AI) research laboratory consisting of the non-profit OpenAI Incorporated and its for-profit subsidiary corporation OpenAI Limited Partnership. OpenAI conducts AI
AI. SQLite Store and retrieve structured data Blob Storage Store and retrieve any data OpenAI Use the OpenAI API Email Send emails API and SDK. Section titled “API and SDK”
Val Town + Claude Web/Desktop ChatGPT Web/Desktop Val Town + ChatGPT Codex Val Town + OpenAI Codex Cursor Val Town + Cursor GitHub Copilot Val Town + GitHub Copilot Warp
else—just send it to a val. Val. Section titled “Val” AI enrichment, browser automation: std/openai Prompt an OpenAI model Clay Enrich user data with Clay Browserbase Search the web with
“Popular tools” Claude Code Val Town CLI + Claude Code Codex Val Town CLI + OpenAI Codex Cursor Val Town CLI + Cursor GitHub Copilot Val Town CLI + GitHub
code. Receiving an attachment and then sending it along. Receiving an attachment, sending it to OpenAI, and then emailing it. Headers. Section titled “Headers” You can set custom headers in
} from "https://esm.town/v/patrickjm/gpt3?v=4"; export let librarySecret = gpt3({ prompt: "what is the meaning of life?", openAiKey: Deno.env.get("openai"), }); Import security. If you’re importing someone else’s code, read the code first