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" },
import { fetch } from "https://esm.town/v/std/fetch";import { OpenAI } from "https://esm.town/v/std/openai";import { z } from "npm:zod";}async function callOpenAI(sysP: string, userP: string, mid: string, tid: string, log: LogFn): Promise<string | null> { log("DB", "OpenAI", `Call tid=${tid}`, { sL: sysP.length, uL: userP.length }, mid, tid); try { // @ts-ignore const oai = new OpenAI(); const comp = await oai.chat.completions.create({ model: "gpt-4o-mini", const usg = comp.usage; if (!resT) { log("WN", "OpenAI", `No text tid=${tid}.`, { usg, fin: comp.choices[0]?.finish_reason }, mid, tid); return null; } log("IN", "OpenAI", `OK tid=${tid}`, { rL: resT.length, usg, fin: comp.choices[0]?.finish_reason }, mid, tid); return resT.trim(); } catch (err: any) { st: err.status, }; log("ER", "OpenAI", `Fail tid=${tid}:${err.message}`, { e: eD }, mid, tid); throw new Error( `OpenAI API Call Failed: ${err.message}` + (err.code ? ` (Code:${err.code}, Status:${err.status})` : (err.status ? ` (Status:${err.status})` : "")), ); } const filledUserPrompt = Utils.fillPromptTemplate(userPrompt, params); const rawOpenAIResponse = await callOpenAI(systemPrompt, filledUserPrompt, mid, tid, logFn); if (!rawOpenAIResponse) { logFn("WN", agentConfig.name, `OpenAI call returned no content, tid=${tid}.`, {}, mid, tid); return { mid, cid: tid, p: {} as TOD, e: `${agentConfig.name} Error: AI returned no content.` }; } let outputData: TOD; try { outputData = agentConfig.outputParser(rawOpenAIResponse); } catch (parseError: any) { agentConfig.name, `Output parsing failed, tid=${tid}. M: ${parseError.message}`, { rawResponsePreview: rawOpenAIResponse.slice(0, 500) }, mid, tid,
## Environment Variables- `OPENAI_API_KEY` - Required for AI chatbot functionality (automatically configured in Val Town)- No other API keys required - uses open health data sources and local storage
import { Hono } from "https://esm.sh/hono@3.11.7";import { OpenAI } from "https://esm.town/v/std/openai";import { email } from "https://esm.town/v/std/email";import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";const chatbot = new Hono();// Initialize OpenAIconst openai = new OpenAI();// System prompt for the health assistant // Get AI response const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [
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" },
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