Search
Code3,277
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" },
1. The app runs daily via a cron trigger2. It uses OpenAI to generate fresh, relevant content for each category3. The content is formatted into a clean, readable email4. The email is automatically sent to the Val Town account ownerThis app uses:- OpenAI API (via Val Town's standard library)- Email functionality (via Val Town's standard library)If emails are not being received:1. Check the Val Town logs for any errors2. Verify that the OpenAI API is functioning correctly3. Ensure your email settings in Val Town are configured properly
import { OpenAI } from "https://esm.town/v/std/openai";import { email } from "https://esm.town/v/std/email";/** * Generates business and tech insights using OpenAI */async function generateInsights() { const openai = new OpenAI(); const insights: Record<string, string[]> = {}; try { const completion = await openai.chat.completions.create({ messages: [{ role: "user", content: prompt }], model: "gpt-4o-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" },
- Fetches the source of any webpage- Extracts HTML, CSS, and JavaScript content- Uses OpenAI to analyze the page and answer questions about it- Provides a simple, user-friendly web interface- Also supports JSON API for programmatic usage- JavaScript evaluation is limited to static analysis (the Val cannot execute JavaScript)- External resources like images, videos, or dynamically loaded content may not be fully analyzed- The analysis depends on the capabilities of the OpenAI model being used## RequirementsThis Val requires an OpenAI API key to be set as an environment variable in your Val Town account.
import { OpenAI } from "https://esm.town/v/std/openai";/** * Webpage Analyzer * * This Val fetches a webpage, extracts its content, and uses OpenAI to answer * questions about the page based on its HTML, CSS, and JavaScript. */// Initialize OpenAI clientconst openai = new OpenAI();// Helper function to extract JavaScript from HTML <footer class="mt-8 text-center text-gray-500 text-sm"> <p>Powered by Val Town and OpenAI</p> <p class="mt-1"> <a href="${import.meta.url.replace("esm.sh", "val.town")}" target="_top" class="text-blue-500 hover:underline">View Source</a> }; // Use OpenAI to analyze the content and answer the question console.log(`Analyzing webpage and answering question: ${question}`); const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [
import { nanoid } from "https://esm.sh/nanoid@5.0.5";import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";import OpenAI from "npm:openai@4.26.0";const TABLE_NAME = `memories`;/** * Generates fun facts for the next 7 days using OpenAI API * @param previousFacts Previous fun facts to avoid duplication * @returns Array of generated fun facts try { // Get API key from environment const apiKey = Deno.env.get("OPENAI_API_KEY"); if (!apiKey) { console.error("OpenAI API key is not configured."); return null; } // Initialize OpenAI client const openai = new OpenAI({ apiKey }); // Format previous facts for the prompt console.log({ message }); // Call OpenAI API const response = await openai.chat.completions.create({ model: "gpt-4-turbo-preview", // You can adjust the model as needed messages: [/** * Fallback parser for when JSON parsing fails * @param responseText The raw response text from OpenAI * @param expectedDates Array of expected dates for facts * @returns Array of parsed facts
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 { openai } from "npm:@ai-sdk/openai";import { generateText, streamText } from "npm:ai";import { getSystemPrompt } from "./prompt.tsx"; const options = { model: openai("gpt-4.1"), temperature: 0.1, maxSteps,
2. It fetches the Abercrombie & Fitch website with browser-like headers3. Extracts both general content and specific promotional elements4. Uses OpenAI to analyze if there's a special sale or promotion5. If a sale is detected, it sends an email notification with details6. Tracks the state of sales to avoid sending duplicate notifications2. The email will be sent to the email address associated with your Val Town account.3. Make sure you have set up your OpenAI API key in Val Town environment variables.## CustomizationIf the AI analysis isn't working:- Verify your OpenAI API key is correctly set in Val Town- Check if you have sufficient credits in your OpenAI account- Review the logs to see the AI's response and reasoning
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