-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (27 loc) · 909 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
const express = require('express');
const bodyParser = require('body-parser');
const OpenAI = require('openai');
const app = express();
const port = 3000;
app.use(bodyParser.json());
// Set your GPT-4 API key here
const gptApiKey = "YOUR_GPT_API_KEY";
const openai = new OpenAI({ key: gptApiKey });
app.post('/generate-content', async (req, res) => {
const { platform, prompt } = req.body;
try {
const gptResponse = await openai.complete({
engine: 'text-davinci-002',
prompt: prompt,
max_tokens: 100
});
const generatedContent = gptResponse.data.choices[0].text.trim();
res.json({ generatedContent });
} catch (error) {
console.error('Error:', error);
res.status(500).send('Internal Server Error');
}
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});