-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
81 lines (72 loc) · 2.4 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import express from "express";
import bodyParser from "body-parser";
import cors from "cors";
import { runform } from "./runForm.js";
import { runModel } from "./langchain.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");
});
// Helper function to format userData into a string
function formatUserData(userData) {
return (
`Name: ${userData.question1}\n` +
`Age: ${userData.question2}\n` +
`Gender: ${userData.question3}\n` +
`Educational Level: ${userData.question4}\n` +
`Subjects: ${userData.question5}\n` +
`Financial Background: ${userData.question6}\n` +
`Strengths/Weaknesses: ${userData.question7}\n` +
`Future Goals: ${userData.question8}\n` +
`Additional Information: ${userData.question9}`
);
}
// Modify the /career-chat endpoint to use the formatUserData function
app.post("/career-chat", async (req, res) => {
try {
let chatType = "career";
const { userData } = req.body;
console.log("Career Chat User Data:", userData);
const formattedUserData = formatUserData(userData);
const response = await runModel(formattedUserData, chatType);
res.json({ response: response.text });
} catch (error) {
console.error(error);
res.status(500).send("An error occurred");
}
});
app.post("/open-chat", async (req, res) => {
try {
const { userInput } = req.body;
let chatType = "open";
// askQuestion(userInput, chatType);
console.log("Open Chat User Input:", userInput);
const response = await runModel(userInput, chatType);
console.log("Open Chat Response:", response);
res.json({ response: response.text });
} catch (error) {
console.error(error);
res.status(500).send("An error occurred");
}
});
app.post("/submit-form", async (req, res) => {
try {
const { userInput } = req.body;
console.log("Form User Input:", userInput);
const formattedData = JSON.stringify(userInput);
const response = await runform(formattedData);
console.log("Form Response:", response);
res.json({ response: response.text });
} 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}`);
});