const express = require("express"); const morgan = require("morgan"); const axios=require("axios") const { generate } = require("./groq.js"); const app = express(); app.use(express.urlencoded({ extended: true })); const port = 7860; app.use(morgan("combined")); const apiUrl = process.env.API_URL; async function scrapeWebPage(url) { try { const response = await axios.get( `${apiUrl}/scrape/?url=${encodeURIComponent(url)}` ); return response.data; } catch (error) { console.error("Error scraping:", error.message); throw error; } } app.get("/", (req, res) => { res.send("Hello World!"); }); app.post("/generate", async (req, res) => { const { text } = req.body; const scrapedContent = await scrapeWebPage("https://atheshwaran.vercel.app/career"); if (!text) { return res.status(400).send("Text is required"); } try { const prompt = `Your name is Alexa. You have knowledge about the career of a person named Atheshwaran. Please provide insights or knowledge about this person's career without mentioning specific websites or URLs. use this ${scrapedContent.scraped_content} to get the knowledge about the person`; console.log(scrapedContent.scraped_content); const response = await generate(text, prompt); res.json(response); } catch (error) { console.error("Error generating response:", error); res.status(500).send("Error generating response"); } }); app.listen(port, () => { console.log(`App listening at http://localhost:${port}`); });