Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
97 lines (77 loc) · 2.35 KB
/
Copy pathserver.js
File metadata and controls
97 lines (77 loc) · 2.35 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const bParse = require('body-parser');
const axios = require('axios')
const hotelAPI = require('./hotelAPI.js');
const pythonAPI = require('./pythonAPI.js');
const app = express();
app.use(cors());
app.use(bParse.json());
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Running Server on ${PORT}`);
});
// app.get('/', async (req, res) => {
// try {
// const response = await axios.get('https://catfact.ninja/fact');
// const data = response.data;
// console.log('Data sent from backend:', data);
// res.json(data);
// } catch (error) {
// console.error(error);
// res.status(500).send('Internal server error');
// }
// });
const messages = [{ "role": "user", "content": "Provide an array of size 3 with popular tourist cities JSON format with the format of city, popular_attractions, city_description" }];
//const messages = [{ "role": "user", "content": "hi" }];
//GPT-3 and DALL-E API Key
const GPTApiKey = process.env.GPT_API_KEY;
const model = 'gpt-3.5-turbo';
const GPTTouristData = {
"messages": messages,
"model": model
};
app.get('/GPTLocationInfo', async (req, res) => {
//console.log("------- GPT IS BEING USED RIGHT NOW -------")
const response = await axios({
method: 'post',
url: 'https://api.openai.com/v1/chat/completions',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + GPTApiKey
},
data: GPTTouristData,
})
const data = JSON.parse('{ "locations" : ' + String(response.data.choices[0].message.content) + '}');
//console.log(data);
res.json(data);
});
app.post('/DALLEPicture', async (req, res) => {
//console.log("------- DALLE IS BEING USED RIGHT NOW -------")
body = req.body;
if (JSON.stringify(body.data) == '{}') {
res.json({
url : ''
});
return;
}
const response = await axios({
method: 'post',
url: 'https://api.openai.com/v1/images/generations',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + GPTApiKey,
},
data: {
"prompt": body.data.place,
'n': 1,
'size': '512x512'
},
})
const data = response.data.data[0];
//console.log(data);
res.json(data);
});
app.use('/hotelAPI', hotelAPI);
app.use('/pythonAPI', pythonAPI);