144 // Check required environment variables
145 const requiredVars = [
146 'OPENAI_API_KEY',
147 'SLACK_BOT_TOKEN',
148 'TELNYX_API_KEY',
326 key: 'ai.default_provider',
327 value: JSON.stringify({
328 name: 'openai',
329 model: 'gpt-4o-mini',
330 maxTokens: 150,
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://deno.land/x/openai@v4.57.0/mod.ts";
2import { logFood } from "./notion.ts";
3import { searchFood, getNutrition, type SearchResult, type NutritionResult } from "./usda.ts";
13}
14
15const openaiApiKey = Deno.env.get("OPENAI_API_KEY") || env.OPENAI_API_KEY;
16const browserUseApiKey = Deno.env.get('BROWSER_USE_API_KEY') || env.BROWSER_USE_API_KEY;
17
18console.log("OpenAI API key present:", !!openaiApiKey);
19console.log("Browser Use API key present:", !!browserUseApiKey);
20
21const openai = new OpenAI({
22 apiKey: openaiApiKey,
23});
24const browserUse = new BrowserUseClient({
206 ];
207
208 let completion = await openai.chat.completions.create({
209 model: "gpt-4o",
210 messages,
281
282 // Get next response
283 completion = await openai.chat.completions.create({
284 model: "gpt-4o",
285 messages,
6const NR_TYPE = "near_field";
7const INSTRUCTIONS = `
8 Greet the user in English, and thank them for trying the new OpenAI Realtime API.
9 Give them a brief summary based on the list below, and then ask if they have any questions.
10 Answer questions using the information below. For questions outside this scope,
23 - higher audio quality
24 - improved handling of alphanumerics (eg, properly understanding credit card and phone numbers)
25 - support for the OpenAI Prompts API
26 - support for MCP-based tools
27 - auto-truncation to reduce context size
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" },
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" },
6
7- 🍎 Web interface for entering food descriptions
8- 🤖 AI-powered calorie estimation using OpenAI GPT-4o
9- 📊 Automatic logging to Notion database
10- 🎨 Clean, responsive UI with TailwindCSS
17
18- `NOTION_OAUTH_TOKEN` - Your Notion OAuth token
19- `OPENAI_API_KEY` - Your OpenAI API key (handled by Val Town's OpenAI integration)
20
21### Notion Database
39- `main.http.ts` - HTTP trigger with web interface and AI integration
40- `notion.ts` - Notion API integration for logging food entries
41- Uses Val Town's OpenAI integration for GPT-4o access
42- Responsive web UI built with TailwindCSS
43
46This version has been migrated from a Bun CLI script to a Val Town HTTP trigger:
47
48- ✅ Uses Val Town's OpenAI integration instead of direct OpenAI SDK
49- ✅ Environment variables use `Deno.env.get()` instead of `process.env`
50- ✅ ESM imports from `https://esm.sh` for compatibility
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" },
4 */
5
6import { OpenAI } from "https://esm.town/v/std/openai";
7import type {
8 ConversationContext,
26 */
27 private initializeProviders(): void {
28 // OpenAI provider
29 const openaiKey = Deno.env.get('OPENAI_API_KEY');
30 if (openaiKey) {
31 this.providers.set('openai', {
32 name: 'openai',
33 model: 'gpt-4o-mini',
34 apiKey: openaiKey,
35 maxTokens: 150,
36 temperature: 0.8
271 let tokensUsed = 0;
272
273 if (provider.name === 'openai') {
274 response = await this.callOpenAI(provider, prompt);
275 tokensUsed = response.usage?.total_tokens || 0;
276 } else if (provider.name === 'xai') {
309
310 /**
311 * Call OpenAI API
312 */
313 private async callOpenAI(provider: AIProvider, prompt: string): Promise<any> {
314 const openai = new OpenAI({ apiKey: provider.apiKey });
315
316 const completion = await openai.chat.completions.create({
317 model: provider.model,
318 messages: [
328
329 /**
330 * Call xAI API (similar to OpenAI format)
331 */
332 private async callXAI(provider: AIProvider, prompt: string): Promise<any> {
388 private extractContent(response: any, providerName: string): string {
389 switch (providerName) {
390 case 'openai':
391 case 'xai':
392 return response.choices?.[0]?.message?.content || '';