File size: 1,624 Bytes
96f4037
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const 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}`);
});