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 'npm:openai'
2
3const openai = new OpenAI()
4
5openai.sd
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101
102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107 messages: [
108 { role: "user", content: "Say hello in a creative way" },
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { streamText } from "https://esm.sh/hono@3.11.7/streaming";
3import { OpenAI } from "https://esm.town/v/std/openai";
4import {
5 searchMedicalContent,
95 : "No specific textbook content found for this query.";
96
97 // Prepare messages for OpenAI
98 const openaiMessages = [
99 { role: "system", content: SYSTEM_PROMPT },
100 { role: "user", content: `Context from Nelson Textbook:\n${contextText}\n\nUser Question: ${message}` }
105 recentMessages.forEach(msg => {
106 if (msg.role !== 'system') {
107 openaiMessages.push({
108 role: msg.role,
109 content: msg.content
116 return streamText(c, async (stream) => {
117 try {
118 const openai = new OpenAI();
119 const completion = await openai.chat.completions.create({
120 model: "gpt-4o-mini",
121 messages: openaiMessages,
122 stream: true,
123 max_tokens: 1500,
199 } else {
200 // Non-streaming response
201 const openai = new OpenAI();
202 const completion = await openai.chat.completions.create({
203 model: "gpt-4o-mini",
204 messages: openaiMessages,
205 max_tokens: 1500,
206 temperature: 0.3,
37- **Hono** API framework
38- **Supabase** with PGVector for vector search
39- **OpenAI/Mistral** for AI responses
40- **Hugging Face** for embeddings
41
68### Prerequisites
69- Supabase project with PGVector extension
70- OpenAI or Mistral API key
71- Hugging Face API key (optional for server-side embeddings)
72
75SUPABASE_URL=your_supabase_url
76SUPABASE_ANON_KEY=your_supabase_anon_key
77OPENAI_API_KEY=your_openai_key
78HUGGING_FACE_API_KEY=your_hf_key (optional)
79```
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" },