Search

3,377 results found for openai (7375ms)

Code
3,282

// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
}
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
import { Hono } from "npm:hono@4.4.12";
if (!userText) throw new Error("User description is required.");
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
}
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
}
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
export class ApiLogger {
/**
* Log OpenAI API response with headers and request ID
*/
static logOpenAIResponse(response: Response, data: Record<string, unknown>, context: string):
const respId = response.headers.get("x-request-id") || response.headers.get("resp-id") || "u
const model = data.model || "unknown";
console.log(`OpenAI ${context}: model=${model} resp_id=${respId} status=${response.status}`)
console.log("Response headers:", Object.fromEntries(response.headers.entries()));
console.log("Response data:", JSON.stringify(data, null, 2));
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
import ValTown from "npm:@valtown/sdk@1.5.0";
import { Hono } from "npm:hono@4.4.12";
Adhere to these non-negotiable rules:
1. **Analyze and Elevate:** Scrutinize the user's core idea. Augment it with essential, modern
ON:** Every application MUST have a valuable, non-trivial OpenAI feature at its core. Invent a c
- *Example for a Todo List:* An AI feature that suggests the most logical next task based
- *Example for a Blog:* An AI-powered assistant to generate 5 compelling title variations
3. **Mandate Interactive UI with Inputs:** The application's primary purpose must be interactiv
nforce Strict JSON Contract for AI:** When defining the \`openai_integration\`, the \`prompt_tem
5. **Mandate Val Town Standard Library & Schema Structure:** Explicitly command the use of Val
6. **Define a Polished UI/UX Vision:** Describe a modern, aesthetically pleasing user interface
"application_type": "The type of application (e.g., 'AI-Powered Poll Creator', 'Smart Gues
"core_features": ["An array of specific, actionable features, including the user's ability
"openai_integration": {
"feature_description": "A clear description of the AI feature.",
"prompt_template": "A concise, effective prompt for the LLM that explicitly tells it to
- **User's Simple Idea:** "A poll app"
- **Your Enriched JSON Output:**
,"Results are displayed in real-time with percentages."],"openai_integration":{"feature_descript
`;
--- CORE PRINCIPLES ---
1. **Deno-First:** All code is for the Deno runtime, using modern JavaScript/TypeScript.
orts (e.g., \`npm:hono@4.4.12\`, \`https://esm.town/v/std/openai?v=4\`) to guarantee stability.
3. **OpenAI is Core:** The specified OpenAI feature must be a central, value-adding part of the
4. **Use Standard Library:** Religiously use the Val Town standard library (\`std/sqlite\`, \`s
5. **Secrets in Environment:** API keys or other secrets must be accessed via \`Deno.env.get()\
* **Query:** \`const { rows } = await sqlite.execute("SELECT * FROM users");\`
**OpenAI JSON Usage (MANDATORY PATTERN):**
\`\`\`typescript
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Tell me a joke about APIs in a JSON object with a 'joke'
* In this context, template literals (strings with backticks \`\`) MUST be standard and vali
* **NEVER escape backticks or dollar-sign placeholders in this context.**
st x = \`hello \${world}\`;\`. This applies especially to OpenAI prompt messages.
2. **CLIENT-SIDE CONTEXT (The JS inside the \`<script>\` tag within the HTML string):**
import { Hono } from "npm:hono@4.4.12";
import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
const DB_SCHEMA = [
if (!message) return c.json({ error: "Message is required." }, 400);
const openai = new OpenAI();
// This is a server-side OpenAI call. Per escaping rules, template literals here are sta
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
}
const openai = new OpenAI();
// STEP 1: Enrich the user's idea into a detailed JSON prompt
const enrichmentCompletion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
const codeGenUserMessage = `Generate the Val Town code for the following specification: ${en
// STEP 2: Generate code with OpenAI using the enriched JSON prompt
const codeGenCompletion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
// --- POST-PROCESSING STEPS ---
let correctedCode = generatedCode
// Fix incorrectly escaped server-side OpenAI prompt template literals
.replace(/(content:\s*)\\\`/g, "$1`")
.replace(/\\\$\{/g, "${")
// @ts-ignore
import { blob } from "https://esm.town/v/std/blob?v=11";
import { OpenAI } from "https://esm.town/v/std/openai";
import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
import { Hono } from "npm:hono@4.4.12";
// --- CORE AI & DATABASE LOGIC ---
const openai = new OpenAI();
async function getTodos() {
async function addTodo(rawTitle: string) {
// Step 1: Refine the incoming task.
const refinementCompletion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: TASK_REFINEMENT_PROMPT }, {
const existingTodosForCheck = existingTodosRaw.map(r => ({ id: r[0], title: r[1] }));
const duplicateCheckCompletion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// --- AI BEHAVIORAL GUIDELINES & PROMPTS ---
const url = new URL(req.url);
const action = url.searchParams.get("action");
const openai = new OpenAI();
if (req.method !== "POST") {
Desired Resolution: ${userInput.resolution}
`;
const analysisCompletion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: PROMPT_ANALYZE }, { role: "user", content: userCon
sender: userInput.sender,
};
const composeCompletion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: PROMPT_COMPOSE }, {
// --- Stage 3: Internal Critique of Pre-Draft ---
const firstReviewCompletion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: PROMPT_REDTEAM_REVIEW }, { role: "user", content:
JSON.stringify(firstCritique)
}`;
const revisionCompletion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: PROMPT_REVISE }, { role: "user", content: revision
// --- Stage 5: Final Critique of Revised Draft ---
const finalReviewCompletion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: PROMPT_REDTEAM_REVIEW }, { role: "user", content:
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// --- AI SYSTEM PROMPT ---
if (req.method === "POST" && action === "generate") {
try {
const openai = new OpenAI();
const body = await req.json();
const topic = body.topic;
];
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: messages,
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// --- AI SYSTEM PROMPTS ---
<main class="game-window" id="game-window">
</main>
by <a href="${sourceUrl}" target="_blank">Val Town</a> & OpenAI</footer>
</div>
if (req.method === "POST") {
try {
const openai = new OpenAI();
const body = await req.json();
}
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: messages,
### ✅ Phase 2: Data Ingestion & AI Rating (COMPLETE)
- NYT data fetching and parsing with category words
- OpenAI integration for category rating with full context
- Cron job for daily automation
- Historical backfill on first run
- **Database**: SQLite with versioned table names for schema changes
- **AI**: OpenAI GPT-4o-mini for cost-effective rating generation
- **Frontend**: React 18.2.0 with TailwindCSS for rapid development
- **Backend**: Hono for lightweight, fast API routes
import { OpenAI } from "https://esm.town/v/std/openai";
// =================================================================
const url = new URL(req.url);
const action = url.searchParams.get("action");
const openai = new OpenAI();
if (req.method === "POST" && action === "getNextAiTurn") {
];
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: messages,