94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
1import { fetch } from "https://esm.town/v/std/fetch";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { z } from "npm:zod";
4
273}
274
275// --- OpenAI Call Wrapper ---
276async function callOpenAI(
277 sysP: string,
278 userP: string,
283 log("DB", "oai", `Call tid=${tid}`, { spL: sysP.length, upL: userP.length }, mid, tid);
284 try {
285 const oai = new OpenAI(); // Assumes OPENAI_API_KEY is set in environment
286 const comp = await oai.chat.completions.create({
287 model: "gpt-4o-mini",
819 try {
820 const { sys, user } = cfg.p(p);
821 const rawC = await callOpenAI(sys, user, mid, tid, log);
822 if (!rawC) {
823 log("WN", cfg.n, `No LLM content tid=${tid}.`, {}, mid, tid);
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
89
90### OpenAI
91
92```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96 messages: [
97 { role: "user", content: "Say hello in a creative way" },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { readFile } from "https://esm.town/v/std/utils@85-main/index.ts";
3import { parseProject } from "https://esm.town/v/std/utils@85-main/index.ts";
4
5// Initialize OpenAI client
6const openai = new OpenAI();
7
8// Define response types
67 }
68
69 // Call OpenAI Vision API to analyze the image
70 const response = await openai.chat.completions.create({
71 model: "gpt-4o",
72 messages: [
93 console.error("Error analyzing image:", error);
94
95 // Determine if it's an OpenAI API error
96 const errorMessage = error instanceof Error
97 ? error.message
1# AI Image Recognition App
2
3This Val Town app uses OpenAI's Vision API to analyze images and provide descriptions of their content.
4
5## Features
23## Technologies Used
24
25- OpenAI Vision API
26- TailwindCSS for styling
27- Val Town's blob storage for caching (optional future enhancement)
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
89
90### OpenAI
91
92```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96 messages: [
97 { role: "user", content: "Say hello in a creative way" },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
89
90### OpenAI
91
92```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96 messages: [
97 { role: "user", content: "Say hello in a creative way" },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },