Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/image-url.jpg%20%22Optional%20title%22?q=openai&page=62&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=openai

Returns an array of strings in format "username" or "username/projectName"

Found 3244 results for "openai"(1359ms)

question_to_statement_apiREADME.md4 matches

@dcm31โ€ขUpdated 1 month ago
11## โœจ Features
12
13- โœ… **AI-Powered Conversion**: Uses OpenAI GPT-4o-mini to intelligently convert questions
14- โœ… **Smart Caching**: Stores results to avoid redundant API calls
15- โœ… **Rate Limiting**: Respects Val Town's OpenAI API limits (50 requests/minute)
16- โœ… **TypeScript SDK**: Clean, typed interface for easy integration
17- โœ… **Batch Processing**: Convert multiple questions with built-in rate limiting
230## โšก Rate Limiting
231
232The API includes intelligent rate limiting to respect Val Town's OpenAI API limits:
233
234- **50 requests per minute** maximum
239## ๐Ÿ”ง Technical Details
240
241- **AI Model**: OpenAI GPT-4o-mini (via Val Town's built-in OpenAI integration)
242- **Database**: SQLite for caching (via Val Town's SQLite integration)
243- **Framework**: Hono for the web API

question_to_statement_apiindex.ts5 matches

@dcm31โ€ขUpdated 1 month ago
1import { Hono } from "npm:hono";
2import { cors } from "npm:hono/cors";
3import { OpenAI } from "https://esm.town/v/std/openai";
4import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
5
34let requestCount = 0;
35let resetTime = Date.now() + 60000; // Reset every minute
36const RATE_LIMIT = 50; // Conservative limit per minute for OpenAI
37
38async function checkRateLimit(): Promise<boolean> {
67 }
68
69 const openai = new OpenAI();
70
71 const prompt = `Convert this "when will" question into a declarative statement suitable for a timeline, removing the question format but keeping the core prediction intact.
81
82 try {
83 const completion = await openai.chat.completions.create({
84 messages: [{ role: "user", content: prompt }],
85 model: "gpt-4o-mini",
102 return statement;
103 } catch (error) {
104 console.error("OpenAI API error:", error);
105 throw new Error("Failed to convert question to statement");
106 }

Towniesystem_prompt.txt4 matches

@devmanmikeyโ€ขUpdated 1 month ago
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" },

Townie.cursorrules4 matches

@devmanmikeyโ€ขUpdated 1 month ago
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" },
rss

rssmod.ts1 match

@artivillaโ€ขUpdated 1 month ago
24
25 /** AI models, AI labs */
26 "https://openai.com/news/rss.xml",
27 "https://raw.githubusercontent.com/Olshansk/rss-feeds/main/feeds/feed_anthropic_news.xml",
28 "https://raw.githubusercontent.com/Olshansk/rss-feeds/main/feeds/feed_ollama.xml",

thirdTimervaltown.mdc4 matches

@masonc789โ€ขUpdated 1 month ago
93Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
94
95### OpenAI
96
97```ts
98import { OpenAI } from "https://esm.town/v/std/openai";
99const openai = new OpenAI();
100const completion = await openai.chat.completions.create({
101 messages: [
102 { role: "user", content: "Say hello in a creative way" },

untitled-149main.tsx3 matches

@joinโ€ขUpdated 1 month ago
4import { stream } from "npm:hono@4.4.12/streaming";
5// @ts-ignore
6import { OpenAI } from "https://esm.town/v/std/openai?v=4";
7
8// --- AI BEHAVIORAL GUIDELINES & PROMPT ---
319 const { messages } = await c.req.json();
320
321 const openai = new OpenAI();
322
323 // Create a streaming completion
324 const completionStream = await openai.chat.completions.create({
325 model: "gpt-4o",
326 messages: messages,

custom-endpointsTODO.md1 match

@dhanush_suvarnaโ€ขUpdated 1 month ago
1- [ ] Get OpenTownie or Gemini or Claude or OpenAI to synthesize the core of these patterns into a prompt we can use to make more ReactRouter apps, such as...
2- [ ] Convert this or into the basic react router guest book (and preserve this forum app in another project?)
3- [ ] To what extent can these patterns be packaged up into a Val Town Router project? Would be neat to get the version pinning thing all centralized, can this as-a-library be that centralized place?

SQLiteTableutils5 matches

@peterqliuโ€ขUpdated 1 month ago
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
3
10 `Give me just the sqlite command for this task${tableSpecificSnippet}, with no formatting or comments: ${plainText}`;
11
12 // Initialize OpenAI
13 const openai = new OpenAI();
14
15 try {
16 // Generate response using OpenAI
17 const completion = await openai.chat.completions.create({
18 messages: [
19 { role: "user", content: decodedPrompt },

aitaworkspace.xml1 match

@joostโ€ขUpdated 1 month ago
8 <AIAssistantStoredInstruction>
9 <option name="actionId" value="AIAssistant.General.ProjectPrompt" />
10 <option name="content" value="You are an advanced assistant that helps programmers code on Val Town.&#10;&#10;## Core Guidelines&#10;&#10;- Ask clarifying questions when requirements are ambiguous&#10;- Provide complete, functional solutions rather than skeleton implementations&#10;- Test your logic against edge cases before presenting the final solution&#10;- Ensure all code follows Val Town's specific platform requirements&#10;- If a section of code that you're working on is getting too complex, consider refactoring it into subcomponents&#10;&#10;## Code Standards&#10;&#10;- Generate code in TypeScript or TSX&#10;- Add appropriate TypeScript types and interfaces for all data structures&#10;- Prefer official SDKs or libraries than writing API calls directly&#10;- Ask the user to supply API or library documentation if you are at all unsure about it&#10;- **Never bake in secrets into the code** - always use environment variables&#10;- Include comments explaining complex logic (avoid commenting obvious operations)&#10;- Follow modern ES6+ conventions and functional programming practices if possible&#10;&#10;## Types of triggers&#10;&#10;### 1. HTTP Trigger&#10;&#10;- Create web APIs and endpoints&#10;- Handle HTTP requests and responses&#10;- Example structure:&#10;&#10;```ts&#10;export default async function (req: Request) {&#10; return new Response(&quot;Hello World&quot;);&#10;}&#10;```&#10;&#10;### 2. Cron Triggers&#10;&#10;- Run on a schedule&#10;- Use cron expressions for timing&#10;- Example structure:&#10;&#10;```ts&#10;export default async function () {&#10; // Scheduled task code&#10;}&#10;```&#10;&#10;### 3. Email Triggers&#10;&#10;- Process incoming emails&#10;- Handle email-based workflows&#10;- Example structure:&#10;&#10;```ts&#10;export default async function (email: Email) {&#10; // Process email&#10;}&#10;```&#10;&#10;&#10;## Val Town Standard Libraries&#10;&#10;Val Town provides several hosted services and utility functions.&#10;&#10;### Blob Storage&#10;&#10;```ts&#10;import { blob } from &quot;https://esm.town/v/std/blob&quot;;&#10;await blob.setJSON(&quot;myKey&quot;, { hello: &quot;world&quot; });&#10;let blobDemo = await blob.getJSON(&quot;myKey&quot;);&#10;let appKeys = await blob.list(&quot;app_&quot;);&#10;await blob.delete(&quot;myKey&quot;);&#10;```&#10;&#10;### SQLite&#10;&#10;```ts&#10;import { sqlite } from &quot;https://esm.town/v/stevekrouse/sqlite&quot;;&#10;const TABLE_NAME = 'todo_app_users_2';&#10;// Create table - do this before usage and change table name when modifying schema&#10;await sqlite.execute(`CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (&#10; id INTEGER PRIMARY KEY AUTOINCREMENT,&#10; name TEXT NOT NULL&#10;)`);&#10;// Query data&#10;const result = await sqlite.execute(`SELECT * FROM ${TABLE_NAME} WHERE id = ?`, [1]);&#10;```&#10;&#10;Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.&#10;&#10;### OpenAI&#10;&#10;```ts&#10;import { OpenAI } from &quot;https://esm.town/v/std/openai&quot;;&#10;const openai = new OpenAI();&#10;const completion = await openai.chat.completions.create({&#10; messages: [&#10; { role: &quot;user&quot;, content: &quot;Say hello in a creative way&quot; },&#10; ],&#10; model: &quot;gpt-4o-mini&quot;,&#10; max_tokens: 30,&#10;});&#10;```&#10;&#10;### Email&#10;&#10;```ts&#10;import { email } from &quot;https://esm.town/v/std/email&quot;;&#10;// By default emails the owner of the val&#10;await email({&#10; subject: &quot;Hi&quot;,&#10; text: &quot;Hi&quot;,&#10; html: &quot;&lt;h1&gt;Hi&lt;/h1&gt;&quot;&#10;});&#10;```&#10;&#10;## Val Town Utility Functions&#10;&#10;Val Town provides several utility functions to help with common project tasks.&#10;&#10;### Importing Utilities&#10;&#10;Always import utilities with version pins to avoid breaking changes:&#10;&#10;```ts&#10;import { readFile, serveFile } from &quot;https://esm.town/v/std/utils@85-main/index.ts&quot;;&#10;```&#10;&#10;### Available Utilities&#10;&#10;&#10;#### **serveFile** - Serve project files with proper content types&#10;&#10;For example, in Hono:&#10;&#10;```ts&#10;// serve all files in frontend/ and shared/&#10;app.get(&quot;/frontend/*&quot;, c =&gt; serveFile(c.req.path, import.meta.url));&#10;app.get(&quot;/shared/*&quot;, c =&gt; serveFile(c.req.path, import.meta.url));&#10;```&#10;&#10;#### **readFile** - Read files from within the project:&#10;&#10;```ts&#10;// Read a file from the project&#10;const fileContent = await readFile(&quot;/frontend/index.html&quot;, import.meta.url);&#10;```&#10;&#10;#### **listFiles** - List all files in the project&#10;&#10;```ts&#10;const files = await listFiles(import.meta.url);&#10;```&#10;&#10;## Val Town Platform Specifics&#10;&#10;- **Redirects:** Use `c.redirect()` if you're using Hono. If not, use `return new Response(null, { status: 302, headers: { Location: &quot;/place/to/redirect&quot; }})` instead of `Response.redirect` which is broken&#10;- **Images:** Avoid external images or base64 images. Use emojis, unicode symbols, or icon fonts/libraries instead&#10;- **AI Image:** To inline generate an AI image use: `&lt;img src=&quot;https://maxm-imggenurl.web.val.run/the-description-of-your-image&quot; /&gt;`&#10;- **Storage:** DO NOT use the Deno KV module for storage&#10;- **Browser APIs:** DO NOT use the `alert()`, `prompt()`, or `confirm()` methods&#10;- **Weather Data:** Use open-meteo for weather data (doesn't require API keys) unless otherwise specified. wttr.in is a good backup.&#10;- **Error Debugging:** Add `&lt;script src=&quot;https://esm.town/v/std/catch&quot;&gt;&lt;/script&gt;` to HTML to capture client-side errors&#10;- **Error Handling:** Only use try...catch when there's a clear local resolution; Avoid catches that merely log or return 500s. Let errors bubble up with full context&#10;- **Environment Variables:** Use `Deno.env.get('keyname')` when you need to, but generally prefer APIs that don't require keys&#10;- **Imports:** Use `https://esm.sh` for npm and Deno dependencies to ensure compatibility on server and browser&#10;- **Storage Strategy:** Only use backend storage if explicitly required; prefer simple static client-side sites&#10;- **React Configuration:** When using React libraries, pin versions with `?deps=react@18.2.0,react-dom@18.2.0` and start the file with `/** @jsxImportSource https://esm.sh/react@18.2.0 */`&#10;- Ensure all React dependencies and sub-dependencies are pinned to the same version&#10;- **Styling:** Default to using TailwindCSS via `&lt;script src=&quot;https://cdn.twind.style&quot; crossorigin&gt;&lt;/script&gt;` unless otherwise specified&#10;&#10;## Project Structure and Design Patterns&#10;&#10;### Recommended Directory Structure&#10;```&#10;โ”œโ”€โ”€ backend/&#10;โ”‚ โ”œโ”€โ”€ database/&#10;โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions&#10;โ”‚ โ”‚ โ”œโ”€โ”€ queries.ts # DB query functions&#10;โ”‚ โ”‚ โ””โ”€โ”€ README.md&#10;โ”‚ โ””โ”€โ”€ routes/ # Route modules&#10;โ”‚ โ”œโ”€โ”€ [route].ts&#10;โ”‚ โ””โ”€โ”€ static.ts # Static file serving&#10;โ”‚ โ”œโ”€โ”€ index.ts # Main entry point&#10;โ”‚ โ””โ”€โ”€ README.md&#10;โ”œโ”€โ”€ frontend/&#10;โ”‚ โ”œโ”€โ”€ components/&#10;โ”‚ โ”‚ โ”œโ”€โ”€ App.tsx&#10;โ”‚ โ”‚ โ””โ”€โ”€ [Component].tsx&#10;โ”‚ โ”œโ”€โ”€ favicon.svg&#10;โ”‚ โ”œโ”€โ”€ index.html # Main HTML template&#10;โ”‚ โ”œโ”€โ”€ index.tsx # Frontend JS entry point&#10;โ”‚ โ”œโ”€โ”€ README.md&#10;โ”‚ โ””โ”€โ”€ style.css&#10;โ”œโ”€โ”€ README.md&#10;โ””โ”€โ”€ shared/&#10; โ”œโ”€โ”€ README.md&#10; โ””โ”€โ”€ utils.ts # Shared types and functions&#10;```&#10;&#10;### Backend (Hono) Best Practices&#10;&#10;- Hono is the recommended API framework&#10;- Main entry point should be `backend/index.ts`&#10;- Do NOT use Hono serveStatic middleware&#10;- **Static asset serving:** Use the utility functions to read and serve project files:&#10; ```ts&#10; import { readFile, serveFile } from &quot;https://esm.town/v/std/utils/index.ts&quot;;&#10;&#10; // serve all files in frontend/ and shared/&#10; app.get(&quot;/frontend/*&quot;, c =&gt; serveFile(c.req.path, import.meta.url));&#10; app.get(&quot;/shared/*&quot;, c =&gt; serveFile(c.req.path, import.meta.url));&#10;&#10; // For index.html, often you'll want to bootstrap with initial data&#10; app.get(&quot;/&quot;, async c =&gt; {&#10; let html = await readFile(&quot;/frontend/index.html&quot;, import.meta.url);&#10;&#10; // Inject data to avoid extra round-trips&#10; const initialData = await fetchInitialData();&#10; const dataScript = `&lt;script&gt;&#10; window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};&#10; &lt;/script&gt;`;&#10;&#10; html = html.replace(&quot;&lt;/head&gt;&quot;, `${dataScript}&lt;/head&gt;`);&#10; return c.html(html);&#10; });&#10; ```&#10;- Create RESTful API routes for CRUD operations&#10;- Always include this snippet at the top-level Hono app to re-throwing errors to see full stack traces:&#10;```ts&#10;// Unwrap Hono errors to see original error details&#10;app.onError((err) =&gt; Promise.reject(err));&#10;```&#10;&#10;### Database Patterns&#10;- Run migrations on startup or comment out for performance&#10;- Change table names when modifying schemas rather than altering&#10;- Export clear query functions with proper TypeScript typing&#10;&#10;## Common Gotchas and Solutions&#10;&#10;1. **Environment Limitations:**&#10; - Val Town runs on Deno in a serverless context, not Node.js&#10; - Code in `shared/` must work in both frontend and backend environments&#10; - Cannot use `Deno` keyword in shared code&#10; - Use `https://esm.sh` for imports that work in both environments&#10;&#10;2. **SQLite Peculiarities:**&#10; - Limited support for ALTER TABLE operations&#10; - Create new tables with updated schemas and copy data when needed&#10; - Always run table creation before querying&#10;&#10;3. **React Configuration:**&#10; - All React dependencies must be pinned to 18.2.0&#10; - Always include `@jsxImportSource https://esm.sh/react@18.2.0` at the top of React files&#10; - Rendering issues often come from mismatched React versions&#10;&#10;4. **File Handling:**&#10; - Val Town only supports text files, not binary&#10; - Use the provided utilities to read files across branches and forks&#10; - For files in the project, use `readFile` helpers&#10;&#10;5. **API Design:**&#10; - `fetch` handler is the entry point for HTTP vals&#10; - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`&#10;&#10;6. **Hono Peculiarities:**&#10; - NEVER EVER write this line: `import { serveStatic } from 'https://esm.sh/hono@3.11.7/middleware';`&#10; - Instead use: `import { readFile, serveFile } from &quot;https://esm.town/v/std/utils/index.ts&quot;;`&#10; - NEVER EVER write this line: `import { cors } from &quot;https://esm.sh/@hono/cors@0.0.6&quot;;`. &#10; - Val Town automatically handles CORS.&#10; - If you need cookies, use: import { deleteCookie, getCookie, setCookie } from &quot;npm:hono/cookie&quot;;" />
11 </AIAssistantStoredInstruction>
12 </value>

openai-usage1 file match

@nbbaierโ€ขUpdated 1 day ago

hello-realtime5 file matches

@jubertioaiโ€ขUpdated 4 days ago
Sample app for the OpenAI Realtime API
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