89If you encounter issues with the Deep Research Agent, try the following:
90
911. **Check OpenAI API Access**: Ensure your Val Town account has access to the OpenAI API.
92
932. **Verify Endpoints**: Make sure you're using the correct URLs for your Val Town username.
113## Requirements
114
115This agent uses the OpenAI API via Val Town's standard library. No additional setup is required.
116
117## Limitations
104
105 <footer class="mt-8 text-center text-gray-500 text-sm">
106 <p>Powered by Val Town and OpenAI</p>
107 <p class="mt-1">
108 <a href="${import.meta.url.replace("esm.sh", "val.town")}" target="_top" class="text-blue-500 hover:underline">View Source</a>
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" },
4import type { ApiResponse, RecommendationRequest, UserProfile } from "../shared/types";
5import { drills, initDatabase, initSampleDrills, playlists, sessions, users } from "./database";
6import { generateFootballDrills, generateMusicPlaylist, generateTrainingSession } from "./openai";
7
8// Initialize the Hono app
1import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { readFile } from "https://esm.town/v/std/utils@85-main/index.ts";
4
5// Initialize OpenAI client
6const openai = new OpenAI();
7
8// Database setup
50}
51
52// Fallback response generator when OpenAI is not available
53function generateFallbackResponse(query: string, memories: Array<{ content: string; tags?: string }> = []) {
54 if (memories.length === 0) {
71}
72
73// Generate a response using OpenAI, incorporating memories if available
74async function generateResponse(query: string, memories: Array<{ content: string; tags?: string }> = []) {
75 try {
84 : "I don't have any memories stored yet.\n\n";
85
86 console.log(`Sending to OpenAI with ${memories.length} memories in context`);
87
88 const response = await openai.chat.completions.create({
89 model: "gpt-4o-mini",
90 messages: [
102
103 if (!response.choices || response.choices.length === 0) {
104 console.error('OpenAI returned no choices:', response);
105 return generateFallbackResponse(query, memories);
106 }
108 return response.choices[0].message.content || generateFallbackResponse(query, memories);
109 } catch (error) {
110 console.error('Error generating response with OpenAI:', error);
111 return generateFallbackResponse(query, memories);
112 }
18brian@airbnb.com,Brian Chesky
19drew@dropbox.com,Drew Houston
20sam@openai.com,Sam Altman
21tim@apple.com,Tim Cook
22jeff@amazon.com,Jeff Bezos
18brian@airbnb.com,Brian Chesky
19drew@dropbox.com,Drew Houston
20sam@openai.com,Sam Altman
21tim@apple.com,Tim Cook
22jeff@amazon.com,Jeff Bezos
1# AI Agent with Memory
2
3This is an AI agent that can save information to its memory and retrieve it when answering questions. The agent uses SQLite for persistent storage and OpenAI's API for generating responses.
4
5## Features
141. **Database**: Uses SQLite to store memory snippets with content, tags, and timestamps
152. **Memory Search**: Performs simple text matching to find relevant memories
163. **Response Generation**: Uses OpenAI to generate responses that incorporate found memories
174. **Web Interface**: Provides a clean UI for asking questions and saving new memories
18
36- **Backend**: TypeScript with Deno runtime
37- **Database**: SQLite for persistent storage
38- **AI**: OpenAI API for generating responses
39- **Frontend**: HTML, JavaScript, and Twind (Tailwind CSS in JS)
40
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" },