Search
Code3,172
if (!text?.trim()) return new Response("No text provided", { status: 400 }); const openaiKey = process.env.OPENAI_API_KEY; if (!openaiKey) return new Response("Missing API key", { status: 500 }); const keyphrases = await generateKeyphrases(text, openaiKey); return new Response(JSON.stringify(keyphrases), { headers: { ...corsHeaders, "Content-Type": "application/json" }, `Analyze this text and output EXACTLY 10 unique keyphrases (2+ words each) as JSON array. Text: "${text}"`; const response = await fetch("https://api.openai.com/v1/chat/completions", { method: "POST", headers: {
}, { "title": "An Introduction to OpenAI fine-tuning", "slug": "an-introduction-to-openai-fine-tuning", "link": "/blog/an-introduction-to-openai-fine-tuning", "description": "How to customize OpenAI to your liking", "pubDate": "Fri, 25 Aug 2023 00:00:00 GMT", "author": "Steve Krouse", "slug": "val-town-newsletter-16", "link": "/blog/val-town-newsletter-16", "description": "Our seed round, growing team, Codeium completions, @std/openai, and more", "pubDate": "Mon, 22 Apr 2024 00:00:00 GMT", "author": "Steve Krouse",
}, { "title": "An Introduction to OpenAI fine-tuning", "slug": "an-introduction-to-openai-fine-tuning", "link": "/blog/an-introduction-to-openai-fine-tuning", "description": "How to customize OpenAI to your liking", "pubDate": "Fri, 25 Aug 2023 00:00:00 GMT", "author": "Steve Krouse", "slug": "val-town-newsletter-16", "link": "/blog/val-town-newsletter-16", "description": "Our seed round, growing team, Codeium completions, @std/openai, and more", "pubDate": "Mon, 22 Apr 2024 00:00:00 GMT", "author": "Steve Krouse",
// Combined Frontend (React/ChakraUI) and Backend (Hono/OpenAI) for Val Town// Funding Assistant Dashboard Prototype - v6 (Corrected AgencyInfo Prompt Logic)export default async function server(request: Request): Promise<Response> { // Only import server-side dependencies here const { OpenAI } = await import("https://esm.town/v/std/openai"); // const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite"); // DB optional const { Hono } = await import("npm:hono"); // --- OpenAI Client --- // Ensure API key is set as Val Town env var 'openai' let openai; try { openai = new OpenAI(); } catch (e) { console.error("FATAL: Failed to initialize OpenAI client. Is the 'openai' environment variable set?", e); // Return a generic server error response if OpenAI cannot be initialized return new Response(JSON.stringify({ error: "Server configuration error. Unable to initialize OpenAI client." }), { status: 500, headers: { "Content-Type": "application/json" }, ]; // --- Call OpenAI --- console.log(`Calling OpenAI for agent: ${agentType}...`); const completion = await openai.chat.completions.create({ messages: messages, model: "gpt-4o", } catch (error) { // Catches errors in request handling, OpenAI API call itself, etc. console.error(`Critical error initiating agent ${agentType}:`, error); let errorMsg = `Server error initiating agent ${agentType}.`; // Check for specific OpenAI errors if needed for better diagnostics // if (error instanceof OpenAI.APIError) { errorMsg = `OpenAI API Error: ${error.status} ${error.message}`; } else if (error.message) { errorMsg = `${errorMsg} Details: ${error.message}`;
}, { "title": "An Introduction to OpenAI fine-tuning", "slug": "an-introduction-to-openai-fine-tuning", "link": "/blog/an-introduction-to-openai-fine-tuning", "description": "How to customize OpenAI to your liking", "pubDate": "Fri, 25 Aug 2023 00:00:00 GMT", "author": "Steve Krouse", "slug": "val-town-newsletter-16", "link": "/blog/val-town-newsletter-16", "description": "Our seed round, growing team, Codeium completions, @std/openai, and more", "pubDate": "Mon, 22 Apr 2024 00:00:00 GMT", "author": "Steve Krouse",
}, { "title": "An Introduction to OpenAI fine-tuning", "slug": "an-introduction-to-openai-fine-tuning", "link": "/blog/an-introduction-to-openai-fine-tuning", "description": "How to customize OpenAI to your liking", "pubDate": "Fri, 25 Aug 2023 00:00:00 GMT", "author": "Steve Krouse", "slug": "val-town-newsletter-16", "link": "/blog/val-town-newsletter-16", "description": "Our seed round, growing team, Codeium completions, @std/openai, and more", "pubDate": "Mon, 22 Apr 2024 00:00:00 GMT", "author": "Steve Krouse",
async function gpt4(prompt: string): Promise<string> { const { OpenAI } = await import("https://esm.town/v/std/openai"); const openai = new OpenAI(); const completion = await openai.chat.completions.create({ messages: [{ role: "user", content: prompt }], model: "gpt-4-mini",
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" },
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" },
// --- Backend Server (Val Town) ---export default async function server(request: Request): Promise<Response> { const { OpenAI } = await import("https://esm.town/v/std/openai"); if (request.method === "OPTIONS") { if (request.method === "POST" && new URL(request.url).pathname === "/grade-card") { try { // Check for OpenAI API Key in Val Town secrets const openai = new OpenAI(); // Assumes OPENAI_API_KEY is set in Val Town secrets const { imageBase64 } = await request.json(); if (!imageBase64 || typeof imageBase64 !== "string") { } console.log("Received image data, preparing request to OpenAI..."); const modelChoice = "gpt-4o"; // Or "gpt-4o-mini" // --- Construct the detailed prompt for OpenAI --- const prompt = `Alright, listen up, collector fam—here’s the no-BS, sharp-as-a-PSA-10 shorthand guide to grading and authenticating cards. No fluff, just gospel truths. Let’s get it:`; const response = await openai.chat.completions.create({ model: modelChoice, response_format: { type: "json_object" }, }); console.log("Received response from OpenAI."); const jsonString = response.choices[0]?.message?.content; if (!jsonString) { throw new Error("OpenAI did not return valid response content."); } console.log("Successfully parsed JSON response."); } catch (parseError) { console.error("Failed to parse JSON from OpenAI:", jsonString); throw new Error("AI returned improperly formatted JSON data."); }
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