AI Comment Reply Generator (MVP)

 


import express from "express"; import cors from "cors"; import dotenv from "dotenv"; import OpenAI from "openai"; dotenv.config(); const app = express(); app.use(cors()); app.use(express.json()); const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, }); // UI app.get("/", (req, res) => { res.send(` AI Comment Reply Generator

💬 AI Reply Generator

Paste comments (one per line)



`); }); // API app.post("/generate", async (req, res) => { const { comments, tone } = req.body; const prompt = ` You are a social media expert. Reply to each comment in a ${tone} way that increases engagement. Rules: - Keep replies short (1 sentence max) - Add curiosity or emotion - Sometimes ask a question - Sound human, not robotic Comments: ${comments} `; try { const completion = await openai.chat.completions.create({ model: "gpt-4.1-mini", messages: [{ role: "user", content: prompt }], }); const text = completion.choices[0].message.content; const replies = text.split("\\n").filter(line => line.trim() !== ""); res.json({ replies }); } catch (err) { res.status(500).json({ error: err.message }); } }); app.listen(3000, () => { console.log("Running on http://localhost:3000"); });

Post a Comment

Previous Post Next Post