-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (55 loc) · 1.75 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
const { Configuration, OpenAIApi } = require("openai");
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
// Open AI Configuration
const configuration = new Configuration({
organization: "",
apiKey: "",
});
const openai = new OpenAIApi(configuration);
// Express Configuration
const app = express()
const port = 3080
app.use(bodyParser.json())
app.use(cors())
app.use(require('morgan')('dev'))
// Routing
app.post('/', async (req, res) => {
const { message, currentModel, temperature } = req.body;
const response = await openai.createCompletion({
model: `${currentModel}`,// "text-davinci-003",
prompt: `${message}`,
max_tokens: 100,
temperature,
});
res.json({
message: response.data.choices[0].text,
})
});
// Primary Open AI Route
// app.post('/', async (req, res) => {
// const { message, currentModel, temperature } = req.body;
// const response = await openai.createCompletion({
// model: `${currentModel}`,// "text-davinci-003",
// prompt: `I want you to act as a travel guide. I will write you my location and you will suggest a place to visit near my location. In some cases, I will also give you the type of places I will visit. You will also suggest me places of similar type that are close to my first location.
// AI Tour Guide: Hello, how can I help you today?
// You: "${message}`,
// max_tokens: 100,
// temperature,
// });
// res.json({
// message: response.data.choices[0].text,
// })
// });
// Get Models Route
app.get('/models', async (req, res) => {
const response = await openai.listEngines();
res.json({
models: response.data
})
});
// Start the server
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
});