Search

3,377 results found for openai (3827ms)

Code
3,282

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" },
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" },
join/mech/main.tsx
13 matches
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): Pr
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 }, m
return null;
}
log("IN", "OpenAI", `OK tid=${tid}`, { rL: resT.length, usg, fin: comp.choices[0]?.finish_re
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:${er
);
}
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 conten
}
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 OpenAI
const 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 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" },