Search
Code3,267
# AI Agent with MemoryThis 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.## Features1. **Database**: Uses SQLite to store memory snippets with content, tags, and timestamps2. **Memory Search**: Performs simple text matching to find relevant memories3. **Response Generation**: Uses OpenAI to generate responses that incorporate found memories4. **Web Interface**: Provides a clean UI for asking questions and saving new memories- **Backend**: TypeScript with Deno runtime- **Database**: SQLite for persistent storage- **AI**: OpenAI API for generating responses- **Frontend**: HTML, JavaScript, and Twind (Tailwind CSS in JS)
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({messages: [{ role: "user", content: "Say hello in a creative way" },
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: "Say hello in a creative way" },
- **Backend**: TypeScript, Hono framework for API routing- **Database**: Val Town SQLite for data persistence- **AI**: OpenAI GPT models for personalized content generation## How It Works1. **User Onboarding**: Users create a profile with their football position, skill level, and music preferences2. **Personalization**: The app uses this information to generate tailored recommendations3. **AI Integration**: OpenAI models create custom playlists and training programs based on user context4. **Combined Experience**: Music and football training are seamlessly integrated for an enhanced experience├── backend/│ ├── index.ts # Main HTTP API entry point│ ├── openai.ts # OpenAI integration for recommendations│ └── database.ts # Database operations├── frontend/
export default async function(req: Request): Promise<Response> { // const OPENAI_API_KEY = "your_openai_api_key_here"; if (!req.url.includes("/v1/chat/completions")) { const body = await req.json(); // Prepare the request to OpenAI API with streaming enabled const openaiResponse = await fetch("https://api.openai.com/v1/chat/completions", { method: "POST", headers: { }); if (!openaiResponse.ok) { const errorText = await openaiResponse.text(); return new Response(errorText, { status: openaiResponse.status }); } // Stream the response back to the client return new Response(openaiResponse.body, { headers: { "Content-Type": "text/event-stream",
import { OpenAI } from "https://esm.town/v/std/openai";import type { UserProfile, } from "../shared/types";// Initialize OpenAI clientconst openai = new OpenAI();/**`; const completion = await openai.chat.completions.create({ messages: [ { role: "system", content: "You are a sports music curator who creates perfect playlists for athletes." }, }; } catch (error) { console.error("Failed to parse OpenAI response:", error); throw new Error("Failed to generate playlist"); }`; const completion = await openai.chat.completions.create({ messages: [ { role: "system", content: "You are an expert football coach who creates personalized training programs." }, return personalizedDrills; } catch (error) { console.error("Failed to parse OpenAI response:", error); throw new Error("Failed to generate drill recommendations"); }`; const completion = await openai.chat.completions.create({ messages: [ { role: "system", content: "You are a professional football trainer who creates engaging training programs." }, }; } catch (error) { console.error("Failed to parse OpenAI response:", error); throw new Error("Failed to generate session details"); }
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: "Say hello in a creative way" },
# BeeGPT - Bee-Themed AI AssistantA fun, bee-themed wrapper for OpenAI's GPT models that adds bee personality, puns, and facts to AI responses, plus a bee-themed image generator.## Features## How It WorksBeeGPT uses OpenAI's API to generate responses and images, but adds a bee-themed personality layer through prompt engineering. The system includes:1. A backend API that communicates with OpenAI2. A bee-themed prompt that instructs the AI to respond with bee-related content3. A bee-themed image generator that enhances prompts with bee elements- Built on Val Town- Uses OpenAI's GPT models (gpt-4o-mini for chat)- Uses OpenAI's DALL-E 3 for image generation- Frontend built with HTML, CSS, and vanilla JavaScript- Styled with Tailwind CSS via CDN## Environment VariablesThis project requires an OpenAI API key to be set in your Val Town environment variables.## License
<footer class="bg-yellow-500 text-black p-3 text-center text-sm"> <p> BeeGPT - Powered by OpenAI | <a href="https://val.town" target="_top"
import { OpenAI } from "https://esm.town/v/std/openai";import { readFile } from "https://esm.town/v/std/utils@85-main/index.ts";// Initialize OpenAI clientconst openai = new OpenAI();// Bee-themed personality prompt } // Call OpenAI with bee persona const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [ try { // Generate image using DALL-E const response = await openai.images.generate({ model: "dall-e-3", prompt: enhancedPrompt, }); console.log("OpenAI response:", JSON.stringify(response)); const imageUrl = response.data[0]?.url; if (!imageUrl) { throw new Error("No image URL returned from OpenAI"); } }, ); } catch (openaiError) { console.error("OpenAI API Error:", openaiError); // Check if it's a content policy violation if (openaiError.message && openaiError.message.includes("content policy")) { return new Response( JSON.stringify({ error: "Your image request was rejected due to content policy. Please try a different prompt.", details: openaiError.message, }), { // Check if it's a rate limit error if (openaiError.message && openaiError.message.includes("rate limit")) { return new Response( JSON.stringify({ error: "Rate limit exceeded. Please try again later.", details: openaiError.message, }), { } throw openaiError; // Re-throw for general error handling } } catch (error) {
reconsumeralization
import { OpenAI } from "https://esm.town/v/std/openai";
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
/**
* Practical Implementation of Collective Content Intelligence
* Bridging advanced AI with collaborative content creation
*/
exp
kwhinnery_openai
lost1991
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
No docs found