Search
Code3,282
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" },
import { OpenAI } from "https://esm.town/v/std/openai";import { sqlite } from "https://esm.town/v/std/sqlite";const CACHE_RAW = "polymarket_raw";const CACHE_SUMMARY = "polymarket_summary";const openai = new OpenAI();// Calculate date 3 months from now for start_date_min // 5) Call AI const aiRes = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [{ role: "user", content: prompt }],
import { OpenAI } from "https://esm.town/v/std/openai";import { sqlite } from "https://esm.town/v/std/sqlite";const RAW_URL = "https://api.manifold.markets/v0/markets?limit=100&sort=last-bet-time";const DETAIL_URL = (id) => `https://api.manifold.markets/v0/market/${id}`;const openai = new OpenAI();export async function cronValHandler(interval) { // 5) Call AI once const aiRes = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [{ role: "user", content: prompt }],
//export default async function(req: Request) { const { OpenAI } = await import("https://esm.town/v/std/openai"); const CORS_HEADERS = { const format = url.searchParams.get("format"); const sourceUrl = import.meta.url.replace("esm.town", "val.town"); const openai = new OpenAI(); const jsonResponse = (body: object, status: number) => ): Promise<object> { try { const response = await openai.chat.completions.create({ model: "gpt-4o", messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessagePayload }],
export default async function(req: Request) { const { OpenAI } = await import("https://esm.town/v/std/openai"); // The 'Buffer' class is specific to Node.js. In other environments like Deno or Cloudflare Workers, // this might not be available. The client-side logic correctly uses FileReader, which is standard. const action = url.searchParams.get("action"); const sourceUrl = import.meta.url.replace("esm.town", "val.town"); const openai = new OpenAI(); async function fileToDataURL(file: File): Promise<string> { agentName: string, ): Promise<object> { log.push({ agent: agentName, type: "step", message: `Calling OpenAI gpt-4o...` }); try { const response = await openai.chat.completions.create({ model: "gpt-4o", messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
- **Backend**: Hono API framework with TypeScript- **Database**: SQLite with normalized schema (recipes + ingredients tables)- **AI**: OpenAI GPT-4o-mini for intelligent recipe parsing- **File Processing**: - PDF parsing via `unpdf` library - Image OCR via OpenAI Vision API - URL content extraction### AI-Powered Parsing- Uses OpenAI GPT-4o-mini for intelligent content extraction- Handles fractional Unicode characters (¼, ½, ¾) and converts to decimals- Robust JSON extraction with fallback parsing### File Processing- **PDF**: Uses `unpdf` library for text extraction- **Images**: Leverages OpenAI Vision API for OCR- **URLs**: Fetches and parses HTML content- **Text**: Direct text processing- **Node.js APIs**: Not required (uses Deno-compatible libraries)- **Environment Variables**: - OpenAI API key (automatically provided by Val Town's OpenAI integration)### Project Configuration- **Image Upload Issues**: Verify image is properly base64 encoded- **Database Errors**: Check if migrations ran successfully on startup- **OpenAI Errors**: Verify API quota and model availability### Debug Endpoints
import { Hono } from "https://esm.sh/hono@3.11.7";import { extractText, getDocumentProxy } from "https://esm.sh/unpdf@1.0.6";import { OpenAI } from "https://esm.town/v/std/openai";import type { ParseRequest, ParseResponse, Recipe } from "../../shared/types.ts";const app = new Hono();const openai = new OpenAI();// PDF parsing is now handled by unpdf library const html = await response.text(); // Use OpenAI to parse the recipe from HTML const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [ try { // Try to extract JSON from the response (sometimes OpenAI adds extra text) let jsonText = recipeText.trim(); } catch (parseError) { console.error("JSON parsing error for URL:", parseError); console.error("Raw response from OpenAI:", recipeText); return c.json({ success: false, error: `Invalid recipe format returned. OpenAI response: ${recipeText.substring(0, 200)}...`, } as ParseResponse); } } // Use OpenAI Vision to parse recipe from image const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [ const recipeText = completion.choices[0]?.message?.content; console.log("OpenAI response:", recipeText); if (!recipeText) { return c.json({ success: false, error: "OpenAI returned empty response" } as ParseResponse); } try { // Try to extract JSON from the response (sometimes OpenAI adds extra text) let jsonText = recipeText.trim(); } catch (parseError) { console.error("JSON parsing error:", parseError); console.error("Raw response from OpenAI:", recipeText); return c.json({ success: false, error: `Invalid recipe format returned. OpenAI response: ${recipeText.substring(0, 200)}...`, } as ParseResponse); } console.log(`Processed PDF with ${totalPages} pages`); // Use OpenAI to parse the recipe const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [ const recipeText = completion.choices[0]?.message?.content; console.log("OpenAI response for PDF:", recipeText); if (!recipeText) { return c.json({ success: false, error: "OpenAI returned empty response" } as ParseResponse); } try { // Try to extract JSON from the response (sometimes OpenAI adds extra text) let jsonText = recipeText.trim(); } catch (parseError) { console.error("JSON parsing error for PDF:", parseError); console.error("Raw response from OpenAI:", recipeText); return c.json({ success: false, error: `Invalid recipe format returned. OpenAI response: ${recipeText.substring(0, 200)}...`, } as ParseResponse); } // Parse recipe from plain text const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [ const recipeText = completion.choices[0]?.message?.content; console.log("OpenAI response for text:", recipeText); if (!recipeText) { return c.json({ success: false, error: "OpenAI returned empty response" } as ParseResponse); } try { // Try to extract JSON from the response (sometimes OpenAI adds extra text) let jsonText = recipeText.trim(); } catch (parseError) { console.error("JSON parsing error for text:", parseError); console.error("Raw response from OpenAI:", recipeText); return c.json({ success: false, error: `Invalid recipe format returned. OpenAI response: ${recipeText.substring(0, 200)}...`, } as ParseResponse); }
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" },
</div> <div> <a href="/std/openai" class="example-link">🤖 OpenAI Integration</a> <span class="text-sm text-gray-500">- AI API wrapper</span> </div> <div> <a href="/examples/ai-explainer.ts" class="custom-function-link">🤖 AI Explainer</a> <span class="text-sm text-gray-600">- Uses OpenAI for detailed code explanations</span> </div> <div>
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