Search
Code3,285
# Plant Information APIA REST API that provides detailed plant information using OpenAI's GPT model with intelligent caching for improved performance and reduced API costs.## Project Structure- Get comprehensive plant information by name- Structured JSON response with 8 key plant characteristics- Powered by OpenAI GPT-4o-mini for accurate plant data- **Intelligent caching system** - stores successful responses and serves cached data for repeated requests- **Admin authentication** - secure login system to protect cache management and admin features### GET /plant/:nameReturns 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.**Parameters:****Cache Indicators:**- `_cached`: Boolean indicating if the response came from cache (true) or OpenAI (false)- `_cacheTimestamp`: ISO timestamp of when the response was generated- `400`: Bad request (missing plant name)- `401`: Unauthorized (authentication required)- `500`: Server error (OpenAI API issues, parsing errors)Error responses include descriptive error messages and may include additional debugging information.- **Plant name normalization**: Plant names are normalized (lowercased, special characters removed, spaces converted to underscores) for consistent caching- **Cache hits**: Subsequent requests for the same plant (even with different capitalization or spacing) will return cached responses instantly- **Cache misses**: New plants trigger OpenAI API calls and the responses are automatically cached- **Performance**: Cached responses are served in milliseconds vs. seconds for OpenAI API calls- **Cost efficiency**: Reduces OpenAI API usage and associated costs## Technical Details- **Main entry point**: `index.ts` at project root with HTTP trigger- Built with Hono framework- Uses OpenAI GPT-4o-mini model- SQLite database for caching with automatic table creation- **Secure authentication system** with session management and HTTP-only cookies
Firebase or Supabase (auth and storage)OpenAI API (for chatbots)Airtable (resource & user data)
} // Ask OpenAI let rawReply = ""; try { const openaiResponse = await fetch("https://api.openai.com/v1/chat/completions", { method: "POST", headers: { "Authorization": `Bearer ${Deno.env.get("OPENAI_API_KEY")}`, "Content-Type": "application/json", }, }); const openaiData = await openaiResponse.json(); console.log("🧠 Full OpenAI response:", JSON.stringify(openaiData, null, 2)); rawReply = openaiData?.choices?.[0]?.message?.content || ""; } catch (error) { console.log("❌ Error contacting OpenAI:", error); }
import process from "node:process";import { marked } from "npm:marked";import { OpenAI } from "npm:openai";function pm(...lines: string[]): string {
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" },
```### OpenAI Integration```typescriptimport { 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" }],model: "gpt-4o-mini",
<library>## OpenAIVal Town includes a free, proxied 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" },```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.:`const { OpenAI } = await import "https://esm.town/v/std/openai");`</library>
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 "npm: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";// --- TYPE DEFINITIONS ---export default async function(req: Request): Promise<Response> { const openai = new OpenAI(); const url = new URL(req.url); const CORS_HEADERS = { } const completion = await openai.chat.completions.create({ model, messages: [{ role: "system", content: prompt }, { role: "user", content: userContent }],
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 "npm:openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({messages: [{ role: "user", content: "Say hello in a creative way" },
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