Spaces:
Runtime error
Runtime error
Update index.js
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051const express = require("express");const puppeteer = require("puppeteer");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 = "http://localhost:8000";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}`);});1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950const 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 = "http://localhost:8000";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}`);});
index.js+50-51