Spaces:
Sleeping
Sleeping
Update index.js
Browse files
index.js
CHANGED
@@ -1,51 +1,50 @@
|
|
1 |
-
const express = require("express");
|
2 |
-
const
|
3 |
-
const
|
4 |
-
const
|
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 |
-
const
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
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 |
+
});
|
|