100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101
102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107 messages: [
108 { role: "user", content: "Say hello in a creative way" },
14
151. The app runs daily via a cron trigger
162. It uses OpenAI to generate fresh, relevant content for each category
173. The content is formatted into a clean, readable email
184. The email is automatically sent to the Val Town account owner
38
39This app uses:
40- OpenAI API (via Val Town's standard library)
41- Email functionality (via Val Town's standard library)
42
47If emails are not being received:
481. Check the Val Town logs for any errors
492. Verify that the OpenAI API is functioning correctly
503. Ensure your email settings in Val Town are configured properly
51
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { email } from "https://esm.town/v/std/email";
3
18
19/**
20 * Generates business and tech insights using OpenAI
21 */
22async function generateInsights() {
23 const openai = new OpenAI();
24 const insights: Record<string, string[]> = {};
25
45
46 try {
47 const completion = await openai.chat.completions.create({
48 messages: [{ role: "user", content: prompt }],
49 model: "gpt-4o-mini",
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101
102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107 messages: [
108 { role: "user", content: "Say hello in a creative way" },
7- Fetches the source of any webpage
8- Extracts HTML, CSS, and JavaScript content
9- Uses OpenAI to analyze the page and answer questions about it
10- Provides a simple, user-friendly web interface
11- Also supports JSON API for programmatic usage
74- JavaScript evaluation is limited to static analysis (the Val cannot execute JavaScript)
75- External resources like images, videos, or dynamically loaded content may not be fully analyzed
76- The analysis depends on the capabilities of the OpenAI model being used
77
78## Requirements
79
80This Val requires an OpenAI API key to be set as an environment variable in your Val Town account.
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3/**
4 * Webpage Analyzer
5 *
6 * This Val fetches a webpage, extracts its content, and uses OpenAI to answer
7 * questions about the page based on its HTML, CSS, and JavaScript.
8 */
9
10// Initialize OpenAI client
11const openai = new OpenAI();
12
13// Helper function to extract JavaScript from HTML
122
123 <footer class="mt-8 text-center text-gray-500 text-sm">
124 <p>Powered by Val Town and OpenAI</p>
125 <p class="mt-1">
126 <a href="${import.meta.url.replace("esm.sh", "val.town")}" target="_top" class="text-blue-500 hover:underline">View Source</a>
232 };
233
234 // Use OpenAI to analyze the content and answer the question
235 console.log(`Analyzing webpage and answering question: ${question}`);
236 const completion = await openai.chat.completions.create({
237 model: "gpt-4o",
238 messages: [
2import { nanoid } from "https://esm.sh/nanoid@5.0.5";
3import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
4import OpenAI from "npm:openai@4.26.0";
5
6const TABLE_NAME = `memories`;
71
72/**
73 * Generates fun facts for the next 7 days using OpenAI API
74 * @param previousFacts Previous fun facts to avoid duplication
75 * @returns Array of generated fun facts
78 try {
79 // Get API key from environment
80 const apiKey = Deno.env.get("OPENAI_API_KEY");
81 if (!apiKey) {
82 console.error("OpenAI API key is not configured.");
83 return null;
84 }
85
86 // Initialize OpenAI client
87 const openai = new OpenAI({ apiKey });
88
89 // Format previous facts for the prompt
139 console.log({ message });
140
141 // Call OpenAI API
142 const response = await openai.chat.completions.create({
143 model: "gpt-4-turbo-preview", // You can adjust the model as needed
144 messages: [
193/**
194 * Fallback parser for when JSON parsing fails
195 * @param responseText The raw response text from OpenAI
196 * @param expectedDates Array of expected dates for facts
197 * @returns Array of parsed facts
89Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
90
91### OpenAI
92
93```ts
94import { OpenAI } from "https://esm.town/v/std/openai";
95const openai = new OpenAI();
96const completion = await openai.chat.completions.create({
97 messages: [
98 { role: "user", content: "Say hello in a creative way" },
1import { openai } from "npm:@ai-sdk/openai";
2import { generateText, streamText } from "npm:ai";
3import { getSystemPrompt } from "./prompt.tsx";
34
35 const options = {
36 model: openai("gpt-4.1"),
37 temperature: 0.1,
38 maxSteps,
192. It fetches the Abercrombie & Fitch website with browser-like headers
203. Extracts both general content and specific promotional elements
214. Uses OpenAI to analyze if there's a special sale or promotion
225. If a sale is detected, it sends an email notification with details
236. Tracks the state of sales to avoid sending duplicate notifications
322. The email will be sent to the email address associated with your Val Town account.
33
343. Make sure you have set up your OpenAI API key in Val Town environment variables.
35
36## Customization
46
47If the AI analysis isn't working:
48- Verify your OpenAI API key is correctly set in Val Town
49- Check if you have sufficient credits in your OpenAI account
50- Review the logs to see the AI's response and reasoning