Search
Code3,282
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { 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 create a fresh table.### OpenAI```tsimport { 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 create a fresh table.### OpenAI```tsimport { 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 create a fresh table.### OpenAI```tsimport { 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 create a fresh table.### OpenAI```tsimport { 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 create a fresh table.### OpenAI```tsimport { 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" },
// === Replace these with your real keys/numbers ===const openai = new OpenAI({ apiKey: "sk-..." });const clinicianPhone = "+1YOURCELLPHONE";const twilioNumber = "+1YOURTWILIONUMBER"; `A dental patient asked: "${question}". Write 3 short, professional draft responses a dentist could choose from. Keep each under 30 words.`; const result = await openai.chat.completions.create({ model: "gpt-4", messages: [{ role: "user", content: prompt }],
// === Replace these with your real keys/numbers ===const openai = new OpenAI({ apiKey: "sk-..." });const clinicianPhone = "+1YOURCELLPHONE";const twilioNumber = "+1YOURTWILIONUMBER";const prompt = `A dental patient asked: "${question}". Write 3 short, professional draft responses a dentist could choose from. Keep each under 30 words.`;const result = await openai.chat.completions.create({model: "gpt-4",messages: [{ role: "user", content: prompt }],
// src/openai_service.tsimport { LogFunction } from "https://esm.town/v/join/crit/types";import { OpenAI } from "https://esm.town/v/std/openai"; // Val Town specific import/** * Invokes the OpenAI Chat Completion API with specified prompts and parameters. * @param systemPrompt The system message to guide the AI's behavior. * @param userPrompt The user's message or query. * @throws Error if the API call fails critically. */export async function invokeOpenAIChatCompletion( systemPrompt: string, userPrompt: string, logger( "AUDIT", "OpenAIService", `Initiating LLM call for task ${taskId}`, { systemPromptLength: systemPrompt.length, userPromptLength: userPrompt.length }, try { const openAIClient = new OpenAI(); // API key should be configured via environment variables const completion = await openAIClient.chat.completions.create({ model: "gpt-4o-mini", // Consider making this configurable messages: [ logger( "WARN", "OpenAIService", `LLM call for task ${taskId} yielded no content.`, { usageData, finishReason }, logger( "INFO", "OpenAIService", `LLM call for task ${taskId} successful.`, { responseLength: responseText.length, usageData, finishReason }, logger( "CRITICAL", "OpenAIService", `LLM call for task ${taskId} failed: ${error.message}`, { error: errorDetails }, ); throw new Error( `OpenAI Service Failure: ${error.message}` + (error.code ? ` (Code: ${error.code}, Status: ${error.status})` : ` (Status: ${error.status})`), );
// src/ai_agent_runner.tsimport { invokeOpenAIChatCompletion } from "https://esm.town/v/join/crit/openai_service";import { BaseIncidentContext, } const rawOpenAIResult = await invokeOpenAIChatCompletion( systemPrompt, userPrompt, logger, ); if (!rawOpenAIResult) { const msg = `LLM returned no content for task ${taskId}.`; logger("WARN", agentName, msg, {}, masterIncidentId, taskId); let parsedOutput: T_Output; try { parsedOutput = outputSchemaParser(rawOpenAIResult); } catch (parseError: any) { const msg = `Failed to parse LLM output for task ${taskId}. Error: ${parseError.message}`; agentName, msg, { rawResponsePreview: rawOpenAIResult.substring(0, 500) }, masterIncidentId, taskId,
reconsumeralization
import { OpenAI } from "https://esm.town/v/std/openai";
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
/**
* Practical Implementation of Collective Content Intelligence
* Bridging advanced AI with collaborative content creation
*/
exp
kwhinnery_openai
lost1991
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
No docs found