Search

3,372 results found for openai (1794ms)

Code
3,277

Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
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" },
1. The app runs daily via a cron trigger
2. It uses OpenAI to generate fresh, relevant content for each category
3. The content is formatted into a clean, readable email
4. The email is automatically sent to the Val Town account owner
This 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 errors
2. Verify that the OpenAI API is functioning correctly
3. 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 cre
### OpenAI
```ts
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" },
- 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 analyze
- The analysis depends on the capabilities of the OpenAI model being used
## Requirements
This Val requires an OpenAI API key to be set as an environment variable in your Val Town accoun
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 client
const 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-blu
};
// 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 cre
### OpenAI
```ts
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" },
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 headers
3. Extracts both general content and specific promotional elements
4. Uses OpenAI to analyze if there's a special sale or promotion
5. If a sale is detected, it sends an email notification with details
6. Tracks the state of sales to avoid sending duplicate notifications
2. 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.
## Customization
If 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