Search
Code3,280
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" },
```### OpenAIDo not use val.town std library, import from https://esm.town/v/cricks_unmixed4u/openai-client/main.tsx and use## GreenPTClient```tsximport { GreenPTClient } from "https://esm.town/v/cricks_unmixed4u/openai-client/main.tsx";const client = GreenPTClient("green-l");
// @ts-ignoreimport { blob } from "https://esm.town/v/std/blob?v=11";import { OpenAI } from "https://esm.town/v/std/openai?v=4";// --- AI BEHAVIORAL GUIDELINES --- </div> <div class="loading-indicator" id="loading-indicator" style="display: none;">Aura is pondering...</div> <footer class="footer">Powered by <a href="${sourceUrl}" target="_blank">Val Town</a> & OpenAI</footer></div> if (req.method === "POST" && action === "chat") { try { const openai = new OpenAI(); const body = await req.json(); const userMessage = body.message; // 2. Analyze user's mood const moodCompletion = await openai.chat.completions.create({ model: "gpt-4o", messages: [ // 3. Generate Aura's response const auraCompletion = await openai.chat.completions.create({ model: "gpt-4o", messages: systemAndUserMessages,
// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";/** try { if (req.method === "POST" && action === "suggestProjects") { const openai = new OpenAI(); const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [
// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";// --- AI BEHAVIORAL GUIDELINES --- if (req.method === "POST" && action === "generate") { try { const openai = new OpenAI(); const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [
// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";// --- Configuration & Constants ---const OPENAI_MODEL = "gpt-4o";const MAX_TOKENS_RESPONSE = 800;}// --- OpenAI System Prompt ---const SYSTEM_PROMPT = `You are a Rick and Morty-styled transdimensional narrative engine. Your primary role is to generate chaotic, compelling, and atmospherically bizarre narrative turns. } = ensureDefaultsAndInferStates(inputContext); const contextForOpenAI = { ...processedContext, _inferred_states_for_your_convenience: { }, }; const userMessage = `Input Context JSON:\n${JSON.stringify(contextForOpenAI, null, 2)}`; try { const openai = new OpenAI(); const completion = await openai.chat.completions.create({ model: OPENAI_MODEL, response_format: { type: "json_object" }, messages: [ const rawContent = completion.choices[0]?.message?.content; if (!rawContent) { throw new Error("OpenAI returned an empty response message."); } || typeof generatedJson.metadata.scene_id !== "string" ) { throw new Error("OpenAI response missing critical fields or incorrect structure."); } generatedJson.metadata.weather_state = inferredWeather; }); } catch (error) { console.error("Error during OpenAI call or processing:", error); return new Response( JSON.stringify(getFallbackOutput(error.message, processedContext)),
// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";import { Hono } from "npm:hono@4.4.12";/** * Calls the OpenAI API to compress the artistic idea. * @param previousIdea The idea from the last iteration. * @param sentiment The new user-provided sentiment. theme: string,): Promise<{ idea: string; reason: string }> { const openai = new OpenAI(); const userInput = `The previous concept was: "${previousIdea}". The new user input is a sentiment of "${sentiment}" and a theme of "${theme}".`; try { const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [ const content = completion.choices[0].message.content; if (!content) { throw new Error("OpenAI returned an empty response for compression."); } const parsed = extractJson(content);/** * Calls the OpenAI API to generate an SVG from the compressed idea. * @param idea The conceptual phrase to visualize. * @returns The SVG code as a string. */async function generateArtwork(idea: string): Promise<string> { const openai = new OpenAI(); try { const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [ const content = completion.choices[0].message.content; if (!content) { throw new Error("OpenAI returned an empty response for artwork generation."); } const parsed = extractJson(content);
// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";import { Hono } from "npm:hono@4.4.12"; if (action === "generateLevel") { try { const openai = new OpenAI(); const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [ return c.json(levelData); } catch (error) { console.error("OpenAI API Error:", error); // If AI fails, provide a safe fallback level return c.json(FALLBACK_LEVEL, 500);
// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";// --- AI BEHAVIORAL GUIDELINES --- </main> <footer class="footer"> A Val Town Frontier Tale powered by <a href="${sourceUrl}" target="_blank">OpenAI</a> </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,
// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";// --- AI BEHAVIORAL GUIDELINES & PROMPTS --- 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,
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