1import { OpenAI } from "https://esm.town/v/std/openai";
2import { type Context, Hono } from "npm:hono";
3import { paymentMiddleware } from "npm:x402-hono";
4
5const openai = new OpenAI();
6
7const app = new Hono();
28
29app.get("/jokes", async (c: Context) => {
30 const completion = await openai.chat.completions.create({
31 messages: [
32 { role: "user", content: "Tell a punny programming joke" },
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" },
127 </div>
128 <div class="border rounded-lg p-4">
129 <h3 class="font-semibold text-orange-600 mb-2">🤖 OpenAI</h3>
130 <ul class="text-sm text-gray-600 space-y-1">
131 <li>• openai_chat</li>
132 </ul>
133 </div>
8- **SQLite Database**: Execute queries and manage database operations
9- **Email**: Send emails through Val Town's email service
10- **OpenAI Integration**: Access OpenAI API through Val Town's service
11- **File Operations**: Read and list project files
12- **Environment Variables**: Access environment configuration
40 - `email_send` - Send emails
41
424. **OpenAI**
43 - `openai_chat` - Generate text with OpenAI
44
455. **File Operations**
6import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
7import { email } from "https://esm.town/v/std/email";
8import { OpenAI } from "https://esm.town/v/std/openai";
9import { readFile, listFiles } from "https://esm.town/v/std/utils@85-main/index.ts";
10import { MCPTool, MCPToolResult } from "./types.ts";
85 },
86 {
87 name: "openai_chat",
88 description: "Generate text using OpenAI's chat completion API",
89 inputSchema: {
90 type: "object",
102 }
103 },
104 model: { type: "string", default: "gpt-4o-mini", description: "OpenAI model to use" },
105 max_tokens: { type: "number", description: "Maximum tokens to generate" },
106 temperature: { type: "number", description: "Sampling temperature" }
156 case "email_send":
157 return await handleEmailSend(args);
158 case "openai_chat":
159 return await handleOpenAIChat(args);
160 case "file_read":
161 return await handleFileRead(args);
285}
286
287async function handleOpenAIChat(args: any): Promise<MCPToolResult> {
288 validateRequired(args, ["messages"]);
289
290 const openai = new OpenAI();
291 const options: any = {
292 messages: args.messages,
297 if (args.temperature !== undefined) options.temperature = args.temperature;
298
299 const completion = await openai.chat.completions.create(options);
300
301 return {
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import {
4 saveItinerary,
12
13const app = new Hono();
14const openai = new OpenAI();
15
16function generateId(): string {
69 Provide realistic coordinates and addresses. Make descriptions engaging and informative.`;
70
71 const completion = await openai.chat.completions.create({
72 messages: [{ role: "user", content: prompt }],
73 model: "gpt-4o-mini",
47## Technology Stack
48
49- **Backend**: Hono + SQLite + OpenAI
50- **Frontend**: React + TypeScript + TailwindCSS
51- **Offline**: Service Workers + Cache API
1227 <a href="?q=function" className="example-link">function</a>
1228 <a href="?q=discord" className="example-link">discord</a>
1229 <a href="?q=openai" className="example-link">openai</a>
1230 <a href="?q=react" className="example-link">react</a>
1231 </div>
1381 <a href="?q=function" className="example-link">function</a>
1382 <a href="?q=discord" className="example-link">discord</a>
1383 <a href="?q=openai" className="example-link">openai</a>
1384 <a href="?q=react" className="example-link">react</a>
1385 </div>
119
1201. When a new message is posted in a configured Slack channel (ie. #bugs, or #support), Slack sends an event to this Val
1212. The val makes an OpenAI call to determine if the message is a bug
1223. If it is, then it searches GitHub for semantically related open issues with a separate OpenAI call
1234. It posts a comment in the Slack thread with links to related GitHub issues, with a "Relevance Score"
124