Search

3,380 results found for openai (4417ms)

Code
3,285

hard/ffff/index.ts
4 matches
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 Generator
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 so
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 so
const userPrompt = `Topic: ${topic}\n\nCaptions:`;
const completion = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
# OpenAI Proxy
This OpenAI API proxy injects Val Town's API keys. For usage documentation, check out https://ww
Migrated 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 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" },
// This is your detailed system prompt that instructs the AI on how to identify crux points
import { 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: userMessa
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_
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
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: [