Search
Code25
/** * OpenAI connection status */export interface OpenAIConnection { envVar: string; status: ConnectionStatus; notion: NotionConnection; database: DatabaseConnection; openai: OpenAIConnection;}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" }], model: "gpt-4o-mini", })); // 6. Check OpenAI connection (validate API key with actual API call) const openaiApiKey = Deno.env.get('OPENAI_API_KEY'); let openaiStatus: 'connected' | 'not_configured' | 'error' = 'not_configured'; let openaiError: string | null = null; if (openaiApiKey) { const openaiResult = await aiService.validateOpenAIConnection(); if (openaiResult.success) { openaiStatus = 'connected'; } else { openaiStatus = 'error'; openaiError = openaiResult.error || 'Failed to connect to OpenAI'; } } ...(databaseError ? { error: databaseError } : {}) }, openai: { envVar: 'OPENAI_API_KEY', status: openaiStatus, error: openaiError } },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" },// Val: nanoBananaImageOpenAI// Adaptado pra ser OpenAI-compatible pro Open WebUI remoto, mantendo o handler original como fallback.// 1. LISTAS DE OPÇÕES VÁLIDAS if (pathname === "/v1/images/generations") { // Handler pra OpenAI-compatible (pro Open WebUI) if (req.method !== "POST") { return Response.json({ error: "Use POST" }, { status: 405 }); const { prompt, size = "1024x1024", // Default OpenAI style n = 1, // Número de imagens, mas por agora suportamos só 1 response_format = "b64_json", } = body; // Mapear size OpenAI pra aspectRatio e imageSize let aspectRatio = "1:1"; let imageSize = "2K"; if (imageData && imageData.data && imageData.mimeType) { // Retorna no formato OpenAI: array de data com b64_json ou url const images = []; for (let i = 0; i < n; i++) { // Suporte básico a n>1, mas gera a mesma imagem// 3. DESCRIÇÃO DA FERRAMENTAexport const description = { name: "nanoBananaImageOpenAI", description: "Gera imagens via Google Nano Banana, agora com endpoint OpenAI-compatible em /v1/images/generations pra integração remota com Open WebUI. Use pra fotos, desenhos ou artes, controlando formato (1:1, 16:9) e qualidade (4K, 2K).", inputSchema: { type: "object", type: "string", description: "Tamanho no formato OpenAI como '1024x1024', mapeado pra aspectRatio e imageSize.", }, n: { type: "integer", description: "Número de imagens (default 1)." },- **Frontend**: React 18 + Twind (TailwindCSS)- **Database**: Val Town SQLite- **AI**: OpenAI for recipe extraction**Goal:** Build a lightweight recipe management app on Val Town that lets users save recipes from URLs via AI extraction, view their collection, and generate shopping lists.**Architecture:** Single Val Town project with Hono backend serving a React frontend. SQLite for persistence. OpenAI for recipe extraction from scraped web pages. Simple REST API with three core endpoints: recipes CRUD, URL ingestion, and shopping list generation.**Tech Stack:** Val Town, TypeScript, Hono, React 18.2.0, SQLite, OpenAI GPT-4o-mini, TailwindCSS (via Twind)---// backend/routes/ingest.tsimport { Hono } from "https://esm.sh/hono@4.4.2";import { OpenAI } from "https://esm.town/v/std/openai";import { createRecipe } from "../database/queries.ts";import type { IngestRequest } from "../../shared/types.ts";const ingest = new Hono();const openai = new OpenAI();// POST /api/ingest - Extract recipe from URL // Use AI to extract structured recipe data const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", max_tokens: 2000,1. Click [**Remix**](/?intent=remix)1. Store your `OPENAI_API_KEY` as an environment variable [here](https://www.val.town/x/templates/leads/environment-variables)1. Customize [`PROMPT.txt`](./PROMPT.txt) (Don't remove any fields from the- The webhook receives each POST request and stores the incoming data as `input_data`- All `input_data` is passed to the OpenAI agent in [`agent.ts`](./agent.ts)**AI Agent**app.post("/", async (c) => { // Early API key check to avoid confusing when using the tester ui if (!Deno.env.get("OPENAI_API_KEY")) { return c.json( { error: "Add OPENAI_API_KEY in Environment Variables" }, 503, );Vals
No vals found
Users
No users found
Docs
No docs found