-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (39 loc) · 1.12 KB
/
Copy pathserver.js
File metadata and controls
44 lines (39 loc) · 1.12 KB
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
//********* EXPRESS SERVER */
import express from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
const app = express();
app.use(bodyParser.json());
app.use(cors());
const port = 3080;
//********* CHAT GPT CODE */
import api_key from './keys/api_key.js';
import { Configuration, OpenAIApi } from 'openai';
const configuration = new Configuration({
organization: 'org-rpY6h9a2QPo5zpxqEoG9c5cC',
// apiKey: process.env.OPENAI_API_KEY,
apiKey: api_key,
});
const openai = new OpenAIApi(configuration);
app.post('/', async (req, res) => {
const { message } = req.body;
// console.log(message);
const response = await openai.createCompletion({
model: 'text-davinci-003',
prompt: `${message}`,
max_tokens: 100,
temperature: 0.5,
});
// console.log(response.data.choices[0].text);
res.json({ message: response.data.choices[0].text });
});
app.get('/models', async (req, res) => {
const response = await openai.listEngines();
console.log(response);
res.json({
models: response.data,
});
});
app.listen(port, () => {
console.log(`server listening on port ${port}`);
});