Search
Code3,172
* Hono JSX* HTMX (probably overcomplicates things; should remove)* @stevekrouse/openai, which is a light wrapper around @std/openaiI'm finding HTMX a bit overpowered for this, so I have two experimental forks without it:
import { email } from "https://esm.town/v/std/email";import { extractValInfo } from "https://esm.town/v/stevekrouse/extractValInfo";import { OpenAI } from "npm:openai";function stripHtmlBackticks(html: string): string {export default async function(e: Email) { const openai = new OpenAI(); console.log(`from: ${e.from} to: ${e.to} subject: ${e.subject}, cc: ${e.cc}, bcc: ${e.bcc}`); } const summary = await openai.chat.completions.create({ messages: [ {
import process from "node:process";import { marked } from "npm:marked";import { OpenAI } from "npm:openai";function pm(...lines: string[]): string { ); const client = new OpenAI({ apiKey: process.env.PERPLEXITY_API_KEY, baseURL: "https://api.perplexity.ai" }); const response = await client.chat.completions.create({ model: "sonar",
<a href="?q=function" className="example-link">function</a> <a href="?q=discord" className="example-link">discord</a> <a href="?q=openai" className="example-link">openai</a> <a href="?q=react" className="example-link">react</a> </div> <a href="?q=function" className="example-link">function</a> <a href="?q=discord" className="example-link">discord</a> <a href="?q=openai" className="example-link">openai</a> <a href="?q=react" className="example-link">react</a> </div>
<a href="?q=function" className="example-link">function</a> <a href="?q=discord" className="example-link">discord</a> <a href="?q=openai" className="example-link">openai</a> <a href="?q=react" className="example-link">react</a> </div> <a href="?q=function" className="example-link">function</a> <a href="?q=discord" className="example-link">discord</a> <a href="?q=openai" className="example-link">openai</a> <a href="?q=react" className="example-link">react</a> </div>
<a href="?q=function" className="example-link">function</a> <a href="?q=discord" className="example-link">discord</a> <a href="?q=openai" className="example-link">openai</a> <a href="?q=react" className="example-link">react</a> </div> <a href="?q=function" className="example-link">function</a> <a href="?q=discord" className="example-link">discord</a> <a href="?q=openai" className="example-link">openai</a> <a href="?q=react" className="example-link">react</a> </div>
// 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}`;
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" },
- [ ] Get OpenTownie or Gemini or Claude or OpenAI to synthesize the core of these patterns into a prompt we can use to make more ReactRouter apps, such as...- [ ] Convert this or into the basic react router guest book (and preserve this forum app in another project?)- [ ] To what extent can these patterns be packaged up into a Val Town Router project? Would be neat to get the version pinning thing all centralized, can this as-a-library be that centralized place?
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