Search

4,004 results found for openai (5740ms)

Code
3,900

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";
/**
* 2. 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;
}
// --- Streaming Call ---
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": "generate_summary",
"description": "Summarize package (Streaming)",
"endpoint": "/api/tools/openai_call",
"run_if": "{{extract_info.details.name}}", // Only run if name exists
"inputs": {
"id": "generate_keyword_analysis",
"description": "Analyze keywords IF they exist",
"endpoint": "/api/tools/openai_call",
"run_if": "{{extract_info.details.hasKeywords}}",
"inputs": {
};
const isStreaming = step.endpoint === "/api/tools/openai_call" && resolvedInputs.stream
const response = await fetch(step.endpoint, {
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) => {
import { OpenAI } from "https://esm.sh/openai@4.28.0";
import type { NovitaAnalysisRequest, NovitaAnalysisResponse, XSSVulnerability } from "../../shar
export class NovitaService {
private client: OpenAI;
constructor() {
}
this.client = new OpenAI({
apiKey,
baseURL: "https://api.novita.ai/openai"
});
}
try {
const response = await this.client.chat.completions.create({
model: "openai/gpt-oss-20b",
messages: [
{ role: "system", content: systemPrompt },
try {
const response = await this.client.chat.completions.create({
model: "openai/gpt-oss-20b",
messages: [
{ role: "system", content: systemPrompt },
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" },
_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" },
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// --- DOMAIN-SPECIFIC LANGUAGE (DSL) & TYPES ---
/**
* The strict JSON response format expected from the OpenAI API.
* This includes the scene definition and the mandatory justification.
*/
if (req.method === "POST") {
try {
const openai = new OpenAI();
const body = await req.json();
const userPrompt = body.prompt;
}
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
_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,