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)
ContentGenindex.ts5 matches
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";
429}
3031const openai = new OpenAI();
3233const 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.`;
35const userPrompt = `Topic: ${topic}\n\nCaptions:`;
3637const completion = await openai.chat.completions.create({
38model: "gpt-4o-mini",
39messages: [
64}
6566const openai = new OpenAI();
6768const 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.`;
70const userPrompt = `Topic: ${topic}\n\nCaptions:`;
7172const completion = await openai.chat.completions.create({
73model: "gpt-4o-mini",
74messages: [
openaiproxyREADME.md3 matches
1# OpenAI Proxy
23This OpenAI API proxy injects Val Town's API keys. For usage documentation, check out https://www.val.town/v/std/openai
45Migrated from folder: openai/openaiproxy
openaiproxymain.tsx8 matches
1import { parseBearerString } from "https://esm.town/v/andreterron/parseBearerString";
2import { API_URL } from "https://esm.town/v/std/API_URL?v=5";
3import { OpenAIUsage } from "https://esm.town/v/std/OpenAIUsage";
4import { RateLimit } from "npm:@rlimit/http";
5const client = new OpenAIUsage();
67const allowedPathnames = [
4344// Proxy the request
45const url = new URL("." + pathname, "https://api.openai.com");
46url.search = search;
4748const headers = new Headers(req.headers);
49headers.set("Host", url.hostname);
50headers.set("Authorization", `Bearer ${Deno.env.get("OPENAI_API_KEY")}`);
51headers.set("OpenAI-Organization", Deno.env.get("OPENAI_API_ORG"));
5253const modifiedBody = await limitFreeModel(req, user);
64});
6566const openAIRes = await fetch(url, {
67method: req.method,
68headers,
7273// Remove internal header
74const res = new Response(openAIRes.body, openAIRes);
75res.headers.delete("openai-organization");
76return res;
77}
Valod.cursorrules4 matches
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107messages: [
108{ role: "user", content: "Say hello in a creative way" },
untitled-4336main.tsx12 matches
2// This is your detailed system prompt that instructs the AI on how to identify crux points
34import { OpenAI } from "https://esm.town/v/std/openai";
56// and structure the output JSON.
802export default async function(req: Request) {
803// --- Dynamic Imports ---
804const { OpenAI } = await import("https://esm.town/v/std/openai"); // Updated import path
805const { z } = await import("npm:zod"); // For input validation
806807// --- Helper Function: Call OpenAI API ---
808async function callOpenAIForCrux(
809openai: OpenAI, // Instance passed in
810systemPrompt: string,
811userMessage: string,
812): Promise<object | ErrorResponse> { // Returns parsed JSON object or an ErrorResponse
813try {
814const response = await openai.chat.completions.create({
815model: "gpt-4o", // Or your preferred model
816messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
823return JSON.parse(content) as CruxAnalysisResponse; // Assume it's the correct type
824} catch (parseError) {
825console.error("OpenAI JSON Parse Error:", parseError, "Raw Content:", content);
826return { error: `AI response was not valid JSON. Raw: ${content.substring(0, 200)}...` };
827}
828} catch (error) {
829console.error("OpenAI API call failed:", error);
830return { error: "Error communicating with AI model.", details: error.message };
831}
837): Promise<object | ErrorResponse>
838{
839const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); // Initialize with key
840841console.log(`Analyzing instruction: "${userInstruction}"`);
842const result = await callOpenAIForCrux(openai, cruxSystemPrompt, userInstruction);
843// Basic validation of the result structure (can be enhanced with Zod on server side too)
844if ("error" in result) {
846}
847if (!result || typeof result !== "object" || !("original_instruction" in result) || !("crux_points" in result)) {
848console.error("Invalid structure from OpenAI:", result);
849return { error: "AI returned an unexpected data structure.", details: result };
850}
896return new Response(JSON.stringify(cruxDataOrError), {
897status: (cruxDataOrError.error.includes("Server configuration error")
898|| cruxDataOrError.error.includes("OpenAI API Key"))
899? 500
900: 400, // Internal or Bad Request
VA-TASK-BRAINindex.ts4 matches
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 { TaskAnalysis, AnalyzeRequest } from "../shared/types.ts";
11});
1213const openai = new OpenAI();
1415// Serve static files
63}`;
6465const completion = await openai.chat.completions.create({
66messages: [
67{ role: "system", content: "You are a helpful virtual assistant consultant who provides clear, actionable advice. Always respond with valid JSON only." },
76const responseText = completion.choices[0]?.message?.content;
77if (!responseText) {
78throw new Error("No response from OpenAI");
79}
80