1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { blob } from "https://esm.town/v/std/blob";
4import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
13});
14
15const openai = new OpenAI();
16
17// Serve static files
77 console.log("Added user message");
78
79 // Prepare messages for OpenAI (limit to last 10 messages to avoid token limits)
80 const recentMessages = conversation.messages.slice(-10);
81 const openaiMessages = recentMessages.map(msg => ({
82 role: msg.role as "user" | "assistant",
83 content: msg.content
84 }));
85
86 console.log("Calling OpenAI with", openaiMessages.length, "messages");
87
88 // Get AI response
89 const completion = await openai.chat.completions.create({
90 model: "gpt-4o-mini",
91 messages: openaiMessages,
92 max_tokens: 1000,
93 temperature: 0.7,
94 });
95
96 console.log("OpenAI response received");
97
98 const aiContent = completion.choices[0]?.message?.content;
99 if (!aiContent) {
100 throw new Error("No content in OpenAI response");
101 }
102
8- Typing indicators
9- Responsive design
10- OpenAI GPT integration
11
12## Project Structure
38## Setup
39
401. Set your OpenAI API key in environment variables as `OPENAI_API_KEY`
412. The app will be available at the HTTP endpoint
42
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" },
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" },
1// === Replace these with your real keys/numbers ===
2const openai = new OpenAI({ apiKey: "sk-..." });
3const clinicianPhone = "+1YOURCELLPHONE";
4const twilioNumber = "+1YOURTWILIONUMBER";
10 `A dental patient asked: "${question}". Write 3 short, professional draft responses a dentist could choose from. Keep each under 30 words.`;
11
12 const result = await openai.chat.completions.create({
13 model: "gpt-4",
14 messages: [{ role: "user", content: prompt }],
1// === Replace these with your real keys/numbers ===
2const openai = new OpenAI({ apiKey: "sk-..." });
3const clinicianPhone = "+1YOURCELLPHONE";
4const twilioNumber = "+1YOURTWILIONUMBER";
9const prompt = `A dental patient asked: "${question}". Write 3 short, professional draft responses a dentist could choose from. Keep each under 30 words.`;
10
11const result = await openai.chat.completions.create({
12model: "gpt-4",
13messages: [{ role: "user", content: prompt }],