-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (42 loc) · 1.32 KB
/
server.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
import express from "express";
import * as dotenv from "dotenv";
import cors from "cors";
import { Configuration, OpenAIApi } from "openai";
dotenv.config();
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const model = "davinci:ft-the-ntf-group-2023-02-10-12-46-17";
const openai = new OpenAIApi(configuration);
const app = express();
app.use(cors());
app.use(express.json());
app.get("/", async (req, res) => {
res.status(200).send({
message: "Hello from Vinloco",
});
});
app.post("/", async (req, res) => {
try {
const prompt = req.body.prompt;
const response = await openai.createCompletion({
model: model,
prompt: `The following is a conversation with a wine shop virtual assistant and a customer. The virtual assistant helps customers to get proper wine name as they wish by telling exact & clear wine name plus vintage.\n\nCustomer: ${prompt}\nAssistant:`,
temperature: 0.5,
max_tokens: 300,
top_p: 1,
frequency_penalty: 0.0,
presence_penalty: 0.0,
stop: ["Customer:"],
});
res.status(200).send({
bot: response.data.choices[0].text,
});
} catch (error) {
console.log(error);
res.status(500).send({ error });
}
});
app.listen(5000, () =>
console.log("Server is running on port http://localhost:5000")
);