196 let statusHtml = '<h3 class="font-medium">System Status</h3><ul class="mt-2 text-sm">';
197
198 // Check OpenAI
199 if (data.environment.hasOpenAIKey) {
200 statusHtml += '<li class="text-green-700">✅ OpenAI API key is configured</li>';
201 } else {
202 statusHtml += '<li class="text-red-700">❌ OpenAI API key is missing</li>';
203 }
204
3import { serveFile, readFile } from "https://esm.town/v/std/utils@85-main/index.ts";
4import { fetchWikipediaArticle } from "./wikipedia.ts";
5import { generatePodcastScript } from "./openai.ts";
6import { textToSpeech } from "./tts.ts";
7import { blob } from "https://esm.town/v/std/blob";
30// Debug endpoint to check environment
31app.get("/api/debug", async (c) => {
32 const hasOpenAI = !!Deno.env.get("OPENAI_API_KEY");
33 const hasGoogleCreds = !!Deno.env.get("GOOGLE_APPLICATION_CREDENTIALS");
34
35 return c.json({
36 environment: {
37 hasOpenAIKey: hasOpenAI,
38 hasGoogleCredentials: hasGoogleCreds,
39 googleCredsLength: hasGoogleCreds ? Deno.env.get("GOOGLE_APPLICATION_CREDENTIALS")?.length : 0
78 console.log(`Successfully fetched article: "${title}" (${content.length} characters)`);
79
80 // Step 2: Generate podcast script using OpenAI
81 console.log("Generating podcast script with OpenAI...");
82 const script = await generatePodcastScript(title, content);
83 console.log(`Successfully generated script (${script.length} characters)`);
1/**
2 * OpenAI integration for generating podcast scripts from Wikipedia articles
3 */
4import { OpenAI } from "https://esm.town/v/std/openai";
5import { truncateContent } from "./wikipedia.ts";
6
7// Initialize OpenAI client
8const openai = new OpenAI();
9
10/**
19
20 try {
21 const completion = await openai.chat.completions.create({
22 model: "gpt-4o",
23 messages: [
4
51. Fetches content from Wikipedia articles
62. Transforms the content into engaging podcast scripts using OpenAI
73. Converts the scripts to audio using Google's Text-to-Speech service
8
11To use this app, you'll need to set up the following environment variables in Val Town:
12
13- `OPENAI_API_KEY`: Your OpenAI API key
14- `GOOGLE_APPLICATION_CREDENTIALS`: Your Google Cloud credentials JSON (stringified)
15
30- `index.ts`: Main HTTP handler
31- `wikipedia.ts`: Wikipedia article fetching
32- `openai.ts`: Script generation with OpenAI
33- `tts.ts`: Google Text-to-Speech integration
34- `frontend/`: Simple web interface for the app
1import { openai } from "npm:@ai-sdk/openai";
2import { Mastra } from "npm:@mastra/core";
3import { LibSQLStore, LibSQLVector } from "@mastra/libsql";
7 name: "My Agent",
8 instructions: "You are a helpful assistant.",
9 model: openai("gpt-4o-mini"),
10 memory: new Memory(),
11});
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
89
90### OpenAI
91
92```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96 messages: [
97 { role: "user", content: "Say hello in a creative way" },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
1// AI-powered content suggestion generator
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { TweetAnalysis } from "./analyzer.ts";
4
26): Promise<ContentSuggestion[]> {
27 try {
28 const openai = new OpenAI();
29
30 // Create a sample of recent tweets for context
67 `;
68
69 const completion = await openai.chat.completions.create({
70 messages: [{ role: "user", content: prompt }],
71 model: "gpt-4o-mini",
35 const postingFrequency = calculatePostingFrequency(tweets);
36
37 // Use OpenAI to analyze the content more deeply
38 const aiAnalysis = await performAIContentAnalysis(allContent);
39
89
90/**
91 * Uses OpenAI to perform deeper content analysis
92 */
93async function performAIContentAnalysis(content: string): Promise<{
99}> {
100 try {
101 import { OpenAI } from "https://esm.town/v/std/openai";
102 const openai = new OpenAI();
103
104 const prompt = `
124 `;
125
126 const completion = await openai.chat.completions.create({
127 messages: [{ role: "user", content: prompt }],
128 model: "gpt-4o-mini",
40
41- **Backend**: `/backend/index.ts` - Handles API requests and serves frontend assets
42 - OpenAI integration for chat completions
43 - API endpoints for authentication, chat, and user data
44 - Supabase integration for database and authentication
68- **Database**: Supabase
69- **Authentication**: Supabase Auth
70- **AI**: OpenAI API
71- **Styling**: Custom CSS with Tailwind utility classes
72