hprasath commited on
Commit
5ee0768
1 Parent(s): 96f4037

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +50 -51
index.js CHANGED
@@ -1,51 +1,50 @@
1
- const express = require("express");
2
- const puppeteer = require("puppeteer");
3
- const morgan = require("morgan");
4
- const axios=require("axios")
5
- const { generate } = require("./groq.js");
6
-
7
- const app = express();
8
- app.use(express.urlencoded({ extended: true }));
9
- const port = 7860;
10
-
11
- app.use(morgan("combined"));
12
- const apiUrl = "http://localhost:8000";
13
- async function scrapeWebPage(url) {
14
- try {
15
- const response = await axios.get(
16
- `${apiUrl}/scrape/?url=${encodeURIComponent(url)}`
17
- );
18
-
19
- return response.data;
20
- } catch (error) {
21
- console.error("Error scraping:", error.message);
22
- throw error;
23
- }
24
- }
25
-
26
- app.get("/", (req, res) => {
27
- res.send("Hello World!");
28
- });
29
-
30
- app.post("/generate", async (req, res) => {
31
- const { text } = req.body;
32
- const scrapedContent = await scrapeWebPage("https://atheshwaran.vercel.app/career");
33
-
34
- if (!text) {
35
- return res.status(400).send("Text is required");
36
- }
37
-
38
- try {
39
- 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`;
40
- console.log(scrapedContent.scraped_content);
41
- const response = await generate(text, prompt);
42
- res.json(response);
43
- } catch (error) {
44
- console.error("Error generating response:", error);
45
- res.status(500).send("Error generating response");
46
- }
47
- });
48
-
49
- app.listen(port, () => {
50
- console.log(`App listening at http://localhost:${port}`);
51
- });
 
1
+ const express = require("express");
2
+ const morgan = require("morgan");
3
+ const axios=require("axios")
4
+ const { generate } = require("./groq.js");
5
+
6
+ const app = express();
7
+ app.use(express.urlencoded({ extended: true }));
8
+ const port = 7860;
9
+
10
+ app.use(morgan("combined"));
11
+ const apiUrl = "http://localhost:8000";
12
+ async function scrapeWebPage(url) {
13
+ try {
14
+ const response = await axios.get(
15
+ `${apiUrl}/scrape/?url=${encodeURIComponent(url)}`
16
+ );
17
+
18
+ return response.data;
19
+ } catch (error) {
20
+ console.error("Error scraping:", error.message);
21
+ throw error;
22
+ }
23
+ }
24
+
25
+ app.get("/", (req, res) => {
26
+ res.send("Hello World!");
27
+ });
28
+
29
+ app.post("/generate", async (req, res) => {
30
+ const { text } = req.body;
31
+ const scrapedContent = await scrapeWebPage("https://atheshwaran.vercel.app/career");
32
+
33
+ if (!text) {
34
+ return res.status(400).send("Text is required");
35
+ }
36
+
37
+ try {
38
+ 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`;
39
+ console.log(scrapedContent.scraped_content);
40
+ const response = await generate(text, prompt);
41
+ res.json(response);
42
+ } catch (error) {
43
+ console.error("Error generating response:", error);
44
+ res.status(500).send("Error generating response");
45
+ }
46
+ });
47
+
48
+ app.listen(port, () => {
49
+ console.log(`App listening at http://localhost:${port}`);
50
+ });