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/$%7BsvgDataUrl%7D?q=openai&page=1&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 2230 results for "openai"(1488ms)

cardamonparse.ts20 matches

@connnolly•Updated 1 hour ago
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import type { ParseRequest, ParseResponse, Recipe } from "../../shared/types.ts";
4
5const app = new Hono();
6const openai = new OpenAI();
7
8// Function to validate and clean recipe data
171 const html = await response.text();
172
173 // Use OpenAI to parse the recipe from HTML
174 const completion = await openai.chat.completions.create({
175 model: "gpt-4o-mini",
176 messages: [
191
192 try {
193 // Try to extract JSON from the response (sometimes OpenAI adds extra text)
194 let jsonText = recipeText.trim();
195
219 } catch (parseError) {
220 console.error('JSON parsing error for URL:', parseError);
221 console.error('Raw response from OpenAI:', recipeText);
222 return c.json({
223 success: false,
224 error: `Invalid recipe format returned. OpenAI response: ${recipeText.substring(0, 200)}...`
225 } as ParseResponse);
226 }
243 }
244
245 // Use OpenAI Vision to parse recipe from image
246 const completion = await openai.chat.completions.create({
247 model: "gpt-4o-mini",
248 messages: [
269
270 const recipeText = completion.choices[0]?.message?.content;
271 console.log('OpenAI response:', recipeText);
272
273 if (!recipeText) {
274 return c.json({ success: false, error: 'OpenAI returned empty response' } as ParseResponse);
275 }
276
277 try {
278 // Try to extract JSON from the response (sometimes OpenAI adds extra text)
279 let jsonText = recipeText.trim();
280
305 } catch (parseError) {
306 console.error('JSON parsing error:', parseError);
307 console.error('Raw response from OpenAI:', recipeText);
308 return c.json({
309 success: false,
310 error: `Invalid recipe format returned. OpenAI response: ${recipeText.substring(0, 200)}...`
311 } as ParseResponse);
312 }
352
353 // Parse recipe from plain text
354 const completion = await openai.chat.completions.create({
355 model: "gpt-4o-mini",
356 messages: [
366
367 const recipeText = completion.choices[0]?.message?.content;
368 console.log('OpenAI response for text:', recipeText);
369
370 if (!recipeText) {
371 return c.json({ success: false, error: 'OpenAI returned empty response' } as ParseResponse);
372 }
373
374 try {
375 // Try to extract JSON from the response (sometimes OpenAI adds extra text)
376 let jsonText = recipeText.trim();
377
402 } catch (parseError) {
403 console.error('JSON parsing error for text:', parseError);
404 console.error('Raw response from OpenAI:', recipeText);
405 return c.json({
406 success: false,
407 error: `Invalid recipe format returned. OpenAI response: ${recipeText.substring(0, 200)}...`
408 } as ParseResponse);
409 }

cardamonREADME.md1 match

@connnolly•Updated 1 hour ago
22- **Backend**: Hono API framework
23- **Database**: SQLite for recipe storage
24- **AI**: OpenAI GPT-4 for intelligent recipe parsing
25- **File Processing**: PDF parsing and image OCR capabilities
26

NewPerspctovologyAppmain.tsx1 match

@hxseidman•Updated 3 hours ago
1// val.js
2
3const OPENAI_API_KEY = process.env.OPENAI_API_KEY; // set this later
4
5export default async (req, res) => {
Plantfo

PlantfoREADME.md9 matches

@Llad•Updated 5 hours ago
1# Plant Information API
2
3A REST API that provides detailed plant information using OpenAI's GPT model with intelligent caching for improved performance and reduced API costs.
4
5## Project Structure
19- Get comprehensive plant information by name
20- Structured JSON response with 8 key plant characteristics
21- Powered by OpenAI GPT-4o-mini for accurate plant data
22- **Intelligent caching system** - stores successful responses and serves cached data for repeated requests
23- Cache management endpoints for monitoring and administration
46
47### GET /plant/:name
48Returns detailed information about a specific plant. If the plant information is already cached, returns the cached response immediately. Otherwise, fetches new information from OpenAI and caches it for future requests.
49
50**Parameters:**
68
69**Cache Indicators:**
70- `_cached`: Boolean indicating if the response came from cache (true) or OpenAI (false)
71- `_cacheTimestamp`: ISO timestamp of when the response was generated
72
174- `200`: Success
175- `400`: Bad request (missing plant name)
176- `500`: Server error (OpenAI API issues, parsing errors)
177
178Error responses include descriptive error messages and may include additional debugging information.
216- **Plant name normalization**: Plant names are normalized (lowercased, special characters removed, spaces converted to underscores) for consistent caching
217- **Cache hits**: Subsequent requests for the same plant (even with different capitalization or spacing) will return cached responses instantly
218- **Cache misses**: New plants trigger OpenAI API calls and the responses are automatically cached
219- **Performance**: Cached responses are served in milliseconds vs. seconds for OpenAI API calls
220- **Cost efficiency**: Reduces OpenAI API usage and associated costs
221
222## Technical Details
224- **Main entry point**: `index.ts` at project root with HTTP trigger
225- Built with Hono framework
226- Uses OpenAI GPT-4o-mini model
227- SQLite database for caching with automatic table creation
228- Includes input validation and error handling
Plantfo

Plantfoindex.ts8 matches

@Llad•Updated 5 hours ago
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { readFile } from "https://esm.town/v/std/utils/index.ts";
4import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
20});
21
22// Initialize OpenAI
23const openai = new OpenAI();
24
25// Initialize cache on startup with error handling
88 }
89
90 console.log(`Fetching fresh data from OpenAI for: "${plantName}"`);
91 // If not cached, fetch from OpenAI
92 const prompt = `Please provide detailed information about the plant "${plantName}" in the following JSON format. Be specific and accurate:
93
105Only return the JSON object, no additional text.`;
106
107 const completion = await openai.chat.completions.create({
108 messages: [
109 { role: "user", content: prompt }
117
118 if (!responseText) {
119 return c.json({ error: "No response from OpenAI" }, 500);
120 }
121
129 }
130
131 // Parse the JSON response from OpenAI
132 const plantInfo: PlantInfo = JSON.parse(cleanedResponse);
133

Todomain.tsx4 matches

@svc•Updated 6 hours ago
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3// --- TYPE DEFINITIONS ---
296 */
297export default async function(req: Request): Promise<Response> {
298 const openai = new OpenAI();
299 const url = new URL(req.url);
300
320 throw new Error("Goal is required for synthesis.");
321 }
322 const completion = await openai.chat.completions.create({
323 model: "gpt-4o",
324 messages: [
338 throw new Error("An array of tasks is required for reschedule.");
339 }
340 const completion = await openai.chat.completions.create({
341 model: "gpt-4o",
342 messages: [
143Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
144
145### OpenAI
146```ts
147import { OpenAI } from "npm:openai";
148const openai = new OpenAI();
149const completion = await openai.chat.completions.create({
150 messages: [
151 { role: "user", content: "Say hello in a creative way" },

val-town-http-mcp-servervalley.txt4 matches

@prashamtrivedi•Updated 7 hours ago
86Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
87
88### OpenAI
89
90```ts
91import { OpenAI } from "https://esm.town/v/std/openai";
92const openai = new OpenAI();
93const completion = await openai.chat.completions.create({
94 messages: [
95 { role: "user", content: "Say hello in a creative way" },

val-town-http-mcp-servertownie.txt7 matches

@prashamtrivedi•Updated 7 hours ago
83
84 <library>
85 ## OpenAI
86
87 Val Town includes a free, proxied OpenAI:
88
89 ```ts
90 import { OpenAI } from "https://esm.town/v/std/openai";
91 const openai = new OpenAI();
92 const completion = await openai.chat.completions.create({
93 messages: [
94 { role: "user", content: "Say hello in a creative way" },
99 ```
100
101 OpenAI only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
102 `const { OpenAI } = await import "https://esm.town/v/std/openai");`
103 </library>
104
71```
72
73### OpenAI Integration
74```typescript
75import { OpenAI } from "https://esm.town/v/std/openai";
76const openai = new OpenAI();
77const completion = await openai.chat.completions.create({
78 messages: [{ role: "user", content: "Say hello" }],
79 model: "gpt-4o-mini",

openai-client1 file match

@cricks_unmixed4u•Updated 1 week ago

openai_enrichment6 file matches

@stevekrouse•Updated 1 week ago
kwhinnery_openai
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