-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (28 loc) · 892 Bytes
/
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
import * as dotenv from 'dotenv';
dotenv.config();
import { Configuration, OpenAIApi } from 'openai';
const configuration = new Configuration({
apiKey: process.env.OPENAI,
});
const openai = new OpenAIApi(configuration);
import express from 'express';
import cors from 'cors';
const app = express();
app.use(cors());
app.use(express.json());
app.post('/dream', async (req, res) => {
try {
const prompt = req.body.prompt;
const aiResponse = await openai.createImage({
prompt,
n: 1,
size:'1024x1024',
});
const image = aiResponse.data.data[0].url;
res.send({ image });
} catch(error) {
console.error(error);
res.status(500).send(error?.response.data.error.message || 'Something went wrong');
}
});
app.listen(8080, () => console.log('make art on http://localhost:8080/dream'));