Search
Code2,230
if (body.action === 'chat') { const { OpenAI } = await import("https://esm.town/v/std/openai"); const openai = new OpenAI(); const completion = await openai.chat.completions.create({ messages: [ { role: "system", content: body.systemPrompt },
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" },
* is defined directly in the main function handler below. * * Assumes the 'openai' secret, containing your OpenAI API key, is set in your Val Town environment. * * Last Updated: 2024-05-22export default async function(req: Request) { // --- Dynamic Imports --- const { OpenAI } = await import("https://esm.town/v/std/openai"); const { fetch } = await import("https://esm.town/v/std/fetch"); const { PDFExtract } = await import("npm:pdf.js-extract"); max_pdf_size_mb: 10, text_truncation_length: 25000, openai_model_name: "gpt-4o", contact_form_placeholders_en: { name: "Your Name", email: "Your Email", message: "Message" }, contact_form_placeholders_es: { name: "Tu Nombre", email: "Tu Correo", message: "Mensaje" }, } // --- Helper Function: Call OpenAI API --- async function callOpenAI( openai: OpenAI, systemPrompt: string, userMessage: string, modelFromConfig = APP_CONFIG.openai_model_name || "gpt-4o", expectJson = false, ): Promise<{ role: "assistant" | "system"; content: string | object }> { const model = modelFromConfig; try { const response = await openai.chat.completions.create({ model, messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }], } } catch (error) { console.error("OpenAI API Error:", error.message); return { role: "system", content: `AI Error: ${error.message}` }; } log: LogEntry[], ): Promise<LogEntry[]> { const openai = new OpenAI(); log.push({ agent: "System", type: "step", message: "Workflow started." }); const agentSystemPrompt = agentConfig.system_prompt.replace("{{document_text}}", truncText); const agentResult = await callOpenAI( openai, agentSystemPrompt, truncText, APP_CONFIG.openai_model_name, agentConfig.expects_json, );
import { OpenAI } from "https://esm.town/v/std/openai";import { sqlite } from "https://esm.town/v/std/sqlite";import { readFile } from "https://esm.town/v/std/utils/index.ts";}// Initialize OpenAIconst openai = new OpenAI();// Initialize cache on startup with error handling } console.log(`Fetching fresh data from OpenAI for: "${plantName}"`); // If not cached, fetch from OpenAI const prompt = `Please provide detailed information about the plant "${plantName}" in the following JSON format. Be specific and accurate:Only return the JSON object, no additional text.`; const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: prompt }, if (!responseText) { return c.json({ error: "No response from OpenAI" }, 500); } } // Parse the JSON response from OpenAI const plantInfo: PlantInfo = JSON.parse(cleanedResponse);
export default async function(req: Request) { const { OpenAI } = await import("https://esm.town/v/std/openai"); const { PDFExtract } = await import("npm:pdf.js-extract"); const action = url.searchParams.get("action"); const sourceUrl = import.meta.url.replace("esm.town", "val.town"); const openai = new OpenAI(); const MAX_TEXT_SUGGEST = 20000; const MAX_TEXT_ANALYZE = 30000; agentName: string, ): Promise<object> { log.push({ agent: agentName, type: "step", message: `Calling OpenAI gpt-4o...` }); try { const response = await openai.chat.completions.create({ model: "gpt-4o", messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
import { OpenAI } from "https://esm.town/v/std/openai";import { Hono } from "npm:hono";// Initialize Hono for routing and OpenAI for the LLMconst app = new Hono();const openai = new OpenAI();/** try { // Call the OpenAI Chat Completions API const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [ return c.json(jsonData); } catch (error) { console.error("Error calling OpenAI or parsing JSON:", error); // Return a structured error message if something goes wrong return c.json({
import { 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" },
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": "*",
OpenAI. Copy page Copy page. Copy this page as Markdown for LLMs. View as Markdown View this page as plain text. Open in ChatGPT Ask questions about this page. Use
= $("p:nth-of-type(2)").first().text(); console.log(intro); Logs OpenAI is an American artificial intelligence (AI) research organization consisting of the non-profit OpenAI, Inc.[5] registered in Delaware and its for-profit subsidiary OpenAI Global, LLC.[6] One
await browser.close(); console.log(intro); Logs "OpenAI is an American artificial intelligence (AI) research laboratory consisting of the non-profit OpenAI Incorporated and its for-profit subsidiary corporation OpenAI Limited Partnership. OpenAI conducts AI
AI. SQLite Store and retrieve structured data Blob Storage Store and retrieve any data OpenAI Use the OpenAI API Email Send emails API and SDK. Section titled “API and SDK”
discordWebhookWeatherHyd - send weather updates to Discord. weather_forecast_in_the_morning - weather forecast on Telegram. weatherBot - OpenAI Weather Bot via function calling. aqi - email alerts when AQI is unhealthy near
You’ll probably want to: Register a new Slash Command. Connect your bot to APIs like OpenAI’s GPT or Dall-E. Come join us in the Val Town Discord if you get
} from "https://esm.town/v/patrickjm/gpt3?v=4"; export let librarySecret = gpt3({ prompt: "what is the meaning of life?", openAiKey: Deno.env.get("openai"), }); Import security. If you’re importing someone else’s code, read the code first