1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
3import { OpenAI } from "https://esm.town/v/std/openai";
4import type { AITextRequest, AITextResponse, MemeTemplate } from "../shared/types.ts";
580try {
81const request: AITextRequest = await c.req.json();
82const openai = new OpenAI();
83
84const prompt = `Generate funny meme text for a "${request.templateName}" meme template.
96Return ONLY a JSON object with "topText" and "bottomText" fields. No other text.`;
9798const completion = await openai.chat.completions.create({
99messages: [
100{ role: "system", content: "You are a hilarious meme generator that creates viral-worthy meme text. Always respond with valid JSON only." },
40- **Backend**: Hono (TypeScript API framework)
41- **Frontend**: React with TypeScript
42- **AI**: OpenAI GPT for funny text generation
43- **Styling**: TailwindCSS
44- **Canvas**: HTML5 Canvas for meme generation
Syphrose1990system_prompt.txt4 matches
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
8990### OpenAI
9192```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96messages: [
97{ role: "user", content: "Say hello in a creative way" },
Syphrose1990.cursorrules4 matches
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
9596### OpenAI
9798```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102messages: [
103{ role: "user", content: "Say hello in a creative way" },
Towniesystem_prompt.txt4 matches
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
8990### OpenAI
9192```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96messages: [
97{ role: "user", content: "Say hello in a creative way" },
Townie.cursorrules4 matches
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
9596### OpenAI
9798```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102messages: [
103{ role: "user", content: "Say hello in a creative way" },
untitled-7672main.tsx11 matches
922export default async function(req: Request) {
923// --- Dynamic Imports ---
924const { OpenAI } = await import("https://esm.town/v/std/openai"); // Updated import path
925const { z } = await import("npm:zod"); // For input validation
926927// --- Helper Function: Call OpenAI API ---
928async function callOpenAIForCrux(
929openai: OpenAI, // Instance passed in
930systemPrompt: string,
931userMessage: string,
932): Promise<object | ErrorResponse> { // Returns parsed JSON object or an ErrorResponse
933try {
934const response = await openai.chat.completions.create({
935model: "gpt-4o", // Or your preferred model
936messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
943return JSON.parse(content) as CruxAnalysisResponse; // Assume it's the correct type
944} catch (parseError) {
945console.error("OpenAI JSON Parse Error:", parseError, "Raw Content:", content);
946return { error: `AI response was not valid JSON. Raw: ${content.substring(0, 200)}...` };
947}
948} catch (error) {
949console.error("OpenAI API call failed:", error);
950return { error: "Error communicating with AI model.", details: error.message };
951}
956userInstruction: string,
957): Promise<object | ErrorResponse> {
958const openai = new OpenAI(); // Initialize with key
959960console.log(`Analyzing instruction: "${userInstruction}"`);
961const result = await callOpenAIForCrux(openai, cruxSystemPrompt, userInstruction);
962// Basic validation of the result structure (can be enhanced with Zod on server side too)
963if ("error" in result) {
965}
966if (!result || typeof result !== "object" || !("original_instruction" in result) || !("crux_points" in result)) {
967console.error("Invalid structure from OpenAI:", result);
968return { error: "AI returned an unexpected data structure.", details: result };
969}
1015return new Response(JSON.stringify(cruxDataOrError), {
1016status: (cruxDataOrError.error.includes("Server configuration error")
1017|| cruxDataOrError.error.includes("OpenAI API Key"))
1018? 500
1019: 400, // Internal or Bad Request
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
4import type { PoemRequest, PoemResponse } from "../shared/types.ts";
30}
3132const openai = new OpenAI();
33
34// Create a detailed prompt for poem generation
45Format your response as JSON with "title" and "poem" fields.`;
4647const completion = await openai.chat.completions.create({
48messages: [
49{
60const content = completion.choices[0]?.message?.content;
61if (!content) {
62throw new Error("No response from OpenAI");
63}
64
5## Features
67- AI-powered poem generation using OpenAI
8- Subtle abstract art backgrounds that complement the text
9- Responsive design with elegant typography
28## Environment Variables
2930- `OPENAI_API_KEY` - Required for poem generation
ContentGenREADME.md2 matches
1# Jeropay Social Media Caption Generator
23A beautiful web application that generates creative social media captions for the Jeropay team using OpenAI's GPT-4o-mini model.
45## Features
6667- **Frontend**: React 18.2.0 with TypeScript
68- **Backend**: Hono framework with OpenAI integration
69- **Styling**: TailwindCSS with custom glass morphism effects
70- **AI Model**: GPT-4o-mini (free tier)