-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (29 loc) · 937 Bytes
/
index.js
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
import express from "express";
import bodyParser from "body-parser";
import cors from "cors";
import runEmbeddings from "./openai_embedings.js";
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(express.static("public"));
app.use(express.urlencoded({ extended: true }));
app.get("/", (req, res) => {
res.sendFile(__dirname + "/public/index.html");
});
app.post("/chat", async (req, res) => {
try {
let { userInput } = req.body;
console.log("User Data", userInput);
// Convert user data to a format suitable for the prompt template
const response = await runEmbeddings(userInput);
res.json({ response: response });
console.log("Response Received", response);
} catch (error) {
console.error(error);
res.status(500).send("An error occurred");
}
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});