Search
Code3,232
import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";import React, { useCallback, useEffect, useState } from "https://esm.sh/react@18.2.0";// NOTE: Backend imports (sqlite, openai) are dynamically imported INSIDE the server function// --- React Frontend --- // Dynamically import backend modules const { sqlite } = await import("https://esm.town/v/std/sqlite"); const { OpenAI } = await import("https://esm.town/v/std/openai"); // --- Database Setup (Expanded Schema) --- } // 2. Call OpenAI with enhanced prompt try { const openai = new OpenAI(); // Needs 'openai' secret in VT // Construct a more detailed prompt let prompt = Do not include any introductory text, markdown formatting, or explanations outside the JSON structure.`; const completion = await openai.chat.completions.create({ messages: [{ role: "user", content: prompt }], model: "gpt-4o-mini", // Or a more powerful model if needed
<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>
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" },
import { Bot } from "https://esm.sh/grammy@1.25.1";import { OpenAI } from "https://esm.town/v/std/openai";// Constants for location and API base URL */async function generateWeatherSummary(weatherDetails: WeatherDetails): Promise<string> { const openai = new OpenAI(); const completion = await openai.chat.completions.create({ messages: [ {
import { Bot, webhookCallback } from "https://deno.land/x/grammy@v1.35.0/mod.ts";import { DateTime } from "https://esm.sh/luxon@3.4.4";import { OpenAI } from "npm:openai";import { backstory } from "../backstory.ts";import { formatMemoriesForPrompt, getRelevantMemories } from "../memoryUtils.ts";async function analyzeMessageContent( openai: OpenAI, username: string, messageText: string, const formattedHistory = chatHistory.length ? formatChatHistoryForAI(chatHistory) : []; const completion = await openai.chat.completions.create({ model: "gpt-4o", // adjust as needed max_tokens: 4096,bot.on("message", async (ctx) => { try { const OPENAI_KEY = Deno.env.get("OPENAI_API_KEY"); if (!OPENAI_KEY) { console.error("OPENAI_API_KEY is not configured."); await ctx.reply("I apologize, but I am not properly configured at present."); return; } const openai = new OpenAI({ apiKey: OPENAI_KEY }); const messageText = ctx.message.text ?? ""; const chatHistory = await getChatHistory(chatId); const analysis = await analyzeMessageContent(openai, username, messageText, chatHistory); // ---------------- Memory CRUD ---------------- //
import { nanoid } from "https://esm.sh/nanoid@5.0.5";import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";import { OpenAI } from "npm:openai";const TABLE_NAME = `memories`;// -----------------------------------------------------------------------------// LLM: generate seven new fun‑facts (OpenAI)// -----------------------------------------------------------------------------async function generateFunFacts(previousFacts: { date: string; text: string }[]) { const apiKey = Deno.env.get("OPENAI_API_KEY"); if (!apiKey) { console.error("OPENAI_API_KEY is not configured."); return []; } const openai = new OpenAI({ apiKey }); // Build auxiliary strings for the prompt try { const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", // inexpensive; change if needed max_tokens: 800, } } catch (err) { console.error("OpenAI error while generating fun facts:", err); return []; }// -----------------------------------------------------------------------------// Manual test run (deno run funFactsOpenAI.ts)// -----------------------------------------------------------------------------if (import.meta.main) {
import { getWeather, WeatherResponse } from "https://esm.town/v/geoffreylitt/getWeather";import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";import { OpenAI } from "npm:openai";const TABLE_NAME = `memories`;/** * Call OpenAI Chat Completions to compress a single day's forecast * into a <25‑word sentence. */async function generateConciseWeatherSummary(weatherDay: ReturnType<typeof summarizeWeather>[number]) { const apiKey = Deno.env.get("OPENAI_API_KEY"); if (!apiKey) { console.error("OPENAI_API_KEY is not configured."); return null; } const openai = new OpenAI({ apiKey }); const systemPrompt = `You are a weather forecaster. Create a very concise summary of a day's forecast.`; try { const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", // cheap & fast; change if desired max_tokens: 100,
import { Bot } from "https://deno.land/x/grammy@v1.35.0/mod.ts";import { DateTime } from "https://esm.sh/luxon@3.4.4";import { OpenAI } from "npm:openai";import { backstory } from "../backstory.ts";import { BOT_SENDER_ID, BOT_SENDER_NAME, storeChatMessage } from "../importers/handleTelegramMessage.ts";/** * Generate the daily briefing using OpenAI Chat Completions */async function generateBriefingContent( openai: OpenAI, memories: Awaited<ReturnType<typeof getRelevantMemories>>, today: DateTime, }; // --------------- OPENAI CALL ----------------- // const completion = await openai.chat.completions.create({ model: "gpt-4o", // adjust as desired max_tokens: 3000,) { // Get API keys from environment const apiKey = Deno.env.get("OPENAI_API_KEY"); const telegramToken = Deno.env.get("TELEGRAM_TOKEN"); if (!apiKey) { console.error("OPENAI_API_KEY is not configured."); return; } } // Initialize OpenAI client const openai = new OpenAI({ apiKey }); // Initialize Telegram bot // Generate briefing content const content = await generateBriefingContent( openai, memories, today,
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" },
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