const Groq = require('groq-sdk'); /** * Groq Service — Lightning-fast Script Writing * Offloads text generation from Gemini to save quotas. */ const groq = new Groq({ apiKey: process.env.GROQ_API_KEY }); /** * Generate a YouTube Shorts script using Llama 3 on Groq */ async function generateShortsScript(topic, niche = 'interesting facts', durationSec = 45) { if (!process.env.GROQ_API_KEY) { throw new Error('GROQ_API_KEY not set'); } const prompt = `You are a viral YouTube Shorts content expert. Create a highly engaging 30–45 second script for a faceless YouTube Shorts video about: "${topic}" in the "${niche}" niche. REQUIREMENTS: - Start with a powerful hook in the first 2 seconds (pattern interrupt, shocking fact, or bold statement) - Use simple, conversational language (no complex words) - Keep sentences short and punchy - Structure: 1. Hook, 2. Curiosity build, 3. 3 key points (fast-paced), 4. Strong ending with subtle call-to-action - Make it emotionally engaging (curiosity, surprise, urgency) - Avoid generic phrases like "in this video" - Make it sound like a viral reel, not a lecture RESPOND IN THIS EXACT JSON FORMAT: { "title": "Viral Title", "hook": "Shocking Hook", "script": "Full high-retention narration", "scenes": [ { "sceneNumber": 1, "narration": "Narration for this segment", "visualPrompt": "Detailed Pexels search keywords (cinematic, high quality)", "durationSec": 8 } ], "hashtags": ["#shorts", "#viral"], "description": "Optimized description", "musicSuggestion": "The mood/type of background music (e.g., Suspenseful, Energetic, Sad, Lo-fi)" }`; const completion = await groq.chat.completions.create({ messages: [{ role: 'user', content: prompt }], model: 'llama-3.3-70b-versatile', response_format: { type: 'json_object' } }); return JSON.parse(completion.choices[0].message.content); } async function generateContentIdeas(niche, count = 5) { const prompt = `Generate ${count} viral YouTube Shorts video ideas for a channel in the "${niche}" niche. RESPOND IN THIS EXACT JSON FORMAT: { "ideas": [ { "title": "Video Title", "topic": "Specific topic description", "viralScore": 95 } ] }`; const completion = await groq.chat.completions.create({ messages: [{ role: 'user', content: prompt }], model: 'llama-3.3-70b-versatile', response_format: { type: 'json_object' } }); const data = JSON.parse(completion.choices[0].message.content); return data.ideas || data; } module.exports = { generateShortsScript, generateContentIdeas };