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 || '';
119 try {
120 // For now, just check if environment variables are set
121 const openaiKey = Deno.env.get('OPENAI_API_KEY');
122 const xaiKey = Deno.env.get('XAI_API_KEY');
123
124 if (!openaiKey && !xaiKey) {
125 return {
126 status: 'unhealthy',
360### 8.2 External Dependencies
361- **Database**: External PostgreSQL or SQLite for data persistence
362- **LLM Services**: OpenAI, xAI, Claude APIs for AI functionality
363- **Platform APIs**: Direct integration with messaging platform APIs
364- **Monitoring**: External logging and metrics collection services
167- SendGrid API v3
168- WhatsApp Business API
169- OpenAI/xAI/Claude APIs for LLM integration
170
171### 5.4 Communication Interfaces
4 <meta charset="utf-8" />
5 <meta name="viewport" content="width=device-width, initial-scale=1" />
6 <title>OpenAI Realtime API Voice Agent</title>
7 <style>
8 :root {
4import * as db from "./database/queries.ts";
5import { generateGameId, generateMgmtId, isValidUsername, isValidGameId } from "../shared/utils.ts";
6import { generateAllPieceMoves, type LLMPieceContext } from "./llm/openai.ts";
7import type {
8 CreateGameRequest,
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { parseLLMResponse } from "../../shared/utils.ts";
3
17
18/**
19 * Generate a move for a single piece using OpenAI's multimodal capabilities
20 */
21export async function generatePieceMove(context: LLMPieceContext): Promise<LLMResponse> {
22 const openai = new OpenAI();
23
24 // Build the prompt
43
44 try {
45 const completion = await openai.chat.completions.create({
46 model: "gpt-4o-mini",
47 messages: [
70
71 } catch (error) {
72 console.error("OpenAI API error:", error);
73 throw new Error(`Failed to generate move: ${error.message}`);
74 }
11 - **queries.ts**: Database query functions
12- **llm/**: LLM integration
13 - **openai.ts**: OpenAI API calls for piece moves
14
15### Frontend (`/frontend/`)