-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (23 loc) · 726 Bytes
/
server.js
File metadata and controls
31 lines (23 loc) · 726 Bytes
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
import * as dotenv from 'dotenv';
import { Configuration, OpenAIApi } from 'openai';
import express from 'express';
import cors from 'cors';
dotenv.config();
const configuration = new Configuration({
apiKey: process.env.OPENAI,
});
const openai = new OpenAIApi(configuration);
const app = express();
app.use(cors());
app.use(express.json());
app.post('/fsaig', async (req, res) => {
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 });
});
app.listen(process.env.PORT || 80, () => console.log('make art on https://fsa-ig.surge.sh/fsaig')); //* 8080 *//