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/`)
2
3import { Hono } from "https://esm.sh/hono@3.11.7";
4import { OpenAI } from "https://esm.town/v/std/openai";
5import { blob } from "https://esm.town/v/std/blob";
6import * as db from "../database/queries.ts";
9
10const app = new Hono();
11const openai = new OpenAI();
12
13// Create new game
430 const prompt = createLLMPrompt(context);
431
432 // Call OpenAI Vision API
433 const completion = await openai.chat.completions.create({
434 model: "gpt-4o",
435 messages: [
17- **Hono API server** with WebSocket support
18- **SQLite database** for game state persistence
19- **OpenAI Vision API** integration for board analysis
20- **Parallel LLM processing** for simultaneous piece moves
21
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" },