Search
Code3,246
import { Hono } from "https://esm.sh/hono";import { OpenAI } from "https://esm.town/v/std/openai";import { serveFile } from "https://esm.town/v/std/utils/index.ts";import type { ChatRequest, ChatResponse } from "../shared/types.ts"; } // Build conversation context for OpenAI const messages = [ { ]; // Call OpenAI API const openai = new OpenAI(); const completion = await openai.chat.completions.create({ model: "gpt-3.5-turbo", messages, if (!assistantMessage) { throw new Error("No response from OpenAI"); }
A ChatGPT-like chat application built for Val Town using React and Hono withOpenAI integration.## Features- 💬 Real-time chat interface with ChatGPT-like styling- 🤖 OpenAI GPT-3.5-turbo integration via Val Town's standard library- 📱 Responsive design with Tailwind CSS- ⚡ Fast TypeScript development with Deno- `GET /` - Serves the React frontend- `POST /api/chat` - Chat with OpenAI (requires message and optional conversation history)- `GET /api/health` - Health check endpoint- **Frontend**: React with TypeScript- **Styling**: Tailwind CSS (via CDN)- **AI**: OpenAI GPT-3.5-turbo via Val Town's standard library- **Runtime**: Deno- **Platform**: Val Town
// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";// --- AI BEHAVIORAL GUIDELINES --- (async () => { try { const openai = new OpenAI(); const body = await req.json(); const text = body.text; ]; const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: messages,
import { cors } from "npm:hono@4.4.12/cors";// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";// @ts-ignoreimport { sqlite } from "https://esm.town/v/std/sqlite?v=4"; } const openai = new OpenAI({ apiKey: Deno.env.get("OPENAI_API_KEY"), });`; const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [
// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";// --- AI BEHAVIORAL GUIDELINES --- const url = new URL(req.url); const action = url.searchParams.get("action"); const openai = new OpenAI(); if (req.method === "POST") { switch (action) { case "newGame": { const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [{ role: "system", content: NEW_GAME_PROMPT }], throw new Error("Guess and secretWord are required."); } const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [
- **Backend:** Hono.js API framework- **Database:** SQLite for data persistence- **AI:** OpenAI GPT-4 for blend generation and sensory prediction- **Frontend:** React with TailwindCSS- **Storage:** Val Town Blob storage for file uploads## Technology Stack- **Backend:** Hono.js, SQLite, OpenAI GPT-4- **Frontend:** React, TailwindCSS- **Platform:** Val Town serverless environment- **Database:** SQLite with comprehensive wine data schema- **AI Integration:** OpenAI API for blend generation and sensory prediction
import { Hono } from "https://esm.sh/hono@3.11.7";import { OpenAI } from "https://esm.town/v/std/openai";import type { BlendGenerationRequest, const app = new Hono();const openai = new OpenAI();// Generate a new wine blend using AI const prompt = createBlendGenerationPrompt(request, availableBlocks); const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [
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" },
{ getRandomRegexExplanation, saveRegexExplanation, getRegexExplanationById }, ReactMarkdown, { OpenAI }, { renderToString }, { jsx, jsxs, Fragment }, import("https://esm.town/v/stainless_em/brainrotdb"), import("npm:react-markdown@7"), import("https://esm.town/v/std/openai"), import("npm:react-dom@19/server.browser"), import("npm:react@19/jsx-runtime"), } const openai = new OpenAI(); const abortController = new AbortController(); const completion = await openai.chat.completions.create({ messages: [ {
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" },
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