Search
Code3,285
import { Hono } from "https://esm.sh/hono@3.11.7";import { OpenAI } from "https://esm.town/v/std/openai";import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";import type { PoemRequest, PoemResponse } from "../shared/types.ts"; } const openai = new OpenAI(); // Create a detailed prompt for poem generation Format your response as JSON with "title" and "poem" fields.`; const completion = await openai.chat.completions.create({ messages: [ { const content = completion.choices[0]?.message?.content; if (!content) { throw new Error("No response from OpenAI"); }
## Features- AI-powered poem generation using OpenAI- Subtle abstract art backgrounds that complement the text- Responsive design with elegant typography## Environment Variables- `OPENAI_API_KEY` - Required for poem generation
# Jeropay Social Media Caption GeneratorA beautiful web application that generates creative social media captions for the Jeropay team using OpenAI's GPT-4o-mini model.## Features- **Frontend**: React 18.2.0 with TypeScript- **Backend**: Hono framework with OpenAI integration- **Styling**: TailwindCSS with custom glass morphism effects- **AI Model**: GPT-4o-mini (free tier)
import { Hono } from "https://esm.sh/hono@3.11.7";import { OpenAI } from "https://esm.town/v/std/openai";import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts"; } const openai = new OpenAI(); const systemPrompt = `You're a creative content writer working with the Jeropay team on a social media campaign for the month of June. Based on the following topic, generate 5 short, catchy, and audience-friendly captions or content ideas. The tone should be helpful, positive, and aligned with young professionals and creatives. Avoid generic phrases, and focus on engaging hooks or action-oriented copy.`; const userPrompt = `Topic: ${topic}\n\nCaptions:`; const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [ } const openai = new OpenAI(); const systemPrompt = `You're a creative content writer working with the Jeropay team on a social media campaign for the month of June. Based on the following topic, generate 5 short, catchy, and audience-friendly captions or content ideas. The tone should be helpful, positive, and aligned with young professionals and creatives. Avoid generic phrases, and focus on engaging hooks or action-oriented copy.`; const userPrompt = `Topic: ${topic}\n\nCaptions:`; const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [
# OpenAI ProxyThis OpenAI API proxy injects Val Town's API keys. For usage documentation, check out https://www.val.town/v/std/openaiMigrated from folder: openai/openaiproxy
import { parseBearerString } from "https://esm.town/v/andreterron/parseBearerString";import { API_URL } from "https://esm.town/v/std/API_URL?v=5";import { OpenAIUsage } from "https://esm.town/v/std/OpenAIUsage";import { RateLimit } from "npm:@rlimit/http";const client = new OpenAIUsage();const allowedPathnames = [ // Proxy the request const url = new URL("." + pathname, "https://api.openai.com"); url.search = search; const headers = new Headers(req.headers); headers.set("Host", url.hostname); headers.set("Authorization", `Bearer ${Deno.env.get("OPENAI_API_KEY")}`); headers.set("OpenAI-Organization", Deno.env.get("OPENAI_API_ORG")); const modifiedBody = await limitFreeModel(req, user); }); const openAIRes = await fetch(url, { method: req.method, headers, // Remove internal header const res = new Response(openAIRes.body, openAIRes); res.headers.delete("openai-organization"); return res;}
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" },
// This is your detailed system prompt that instructs the AI on how to identify crux pointsimport { OpenAI } from "https://esm.town/v/std/openai";// and structure the output JSON.export default async function(req: Request) { // --- Dynamic Imports --- const { OpenAI } = await import("https://esm.town/v/std/openai"); // Updated import path const { z } = await import("npm:zod"); // For input validation // --- Helper Function: Call OpenAI API --- async function callOpenAIForCrux( openai: OpenAI, // Instance passed in systemPrompt: string, userMessage: string, ): Promise<object | ErrorResponse> { // Returns parsed JSON object or an ErrorResponse try { const response = await openai.chat.completions.create({ model: "gpt-4o", // Or your preferred model messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }], return JSON.parse(content) as CruxAnalysisResponse; // Assume it's the correct type } catch (parseError) { console.error("OpenAI JSON Parse Error:", parseError, "Raw Content:", content); return { error: `AI response was not valid JSON. Raw: ${content.substring(0, 200)}...` }; } } catch (error) { console.error("OpenAI API call failed:", error); return { error: "Error communicating with AI model.", details: error.message }; } ): Promise<object | ErrorResponse> { const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); // Initialize with key console.log(`Analyzing instruction: "${userInstruction}"`); const result = await callOpenAIForCrux(openai, cruxSystemPrompt, userInstruction); // Basic validation of the result structure (can be enhanced with Zod on server side too) if ("error" in result) { } if (!result || typeof result !== "object" || !("original_instruction" in result) || !("crux_points" in result)) { console.error("Invalid structure from OpenAI:", result); return { error: "AI returned an unexpected data structure.", details: result }; } return new Response(JSON.stringify(cruxDataOrError), { status: (cruxDataOrError.error.includes("Server configuration error") || cruxDataOrError.error.includes("OpenAI API Key")) ? 500 : 400, // Internal or Bad Request
import { Hono } from "https://esm.sh/hono@3.11.7";import { OpenAI } from "https://esm.town/v/std/openai";import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";import type { TaskAnalysis, AnalyzeRequest } from "../shared/types.ts";});const openai = new OpenAI();// Serve static files}`; const completion = await openai.chat.completions.create({ messages: [ { role: "system", content: "You are a helpful virtual assistant consultant who provides clear, actionable advice. Always respond with valid JSON only." }, const responseText = completion.choices[0]?.message?.content; if (!responseText) { throw new Error("No response from OpenAI"); }
import { OpenAI } from "https://esm.town/v/std/openai";import { CodeReviewRequest, export class AIReviewEngine { private openai: OpenAI; constructor() { this.openai = new OpenAI(); } try { const completion = await this.openai.chat.completions.create({ model: "gpt-4o-mini", messages: [
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