Search

3,380 results found for openai (8251ms)

Code
3,285

# Plant Information API
A REST API that provides detailed plant information using OpenAI's GPT model with intelligent ca
## 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 repeat
- **Admin authentication** - secure login system to protect cache management and admin features
### GET /plant/:name
onse immediately. Otherwise, fetches new information from OpenAI and caches it for future reques
**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 informat
- **Plant name normalization**: Plant names are normalized (lowercased, special characters remov
- **Cache hits**: Subsequent requests for the same plant (even with different capitalization or
- **Cache misses**: New plants trigger OpenAI API calls and the responses are automatically cach
- **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 cre
### OpenAI
```ts
import { 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
```typescript
import { 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>
## OpenAI
Val Town includes a free, proxied OpenAI:
```ts
import { 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 t
`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 cre
### OpenAI
```ts
import { 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" },
svc/Todo/main.tsx
3 matches
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 cre
### OpenAI
```ts
import { 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" },