The code below works. The problem is when ChatGPT replies only 1 line is rendered to the terminal and the rest of the text is cut off. I am not familiar with curl commands. How do I update the code so that multi-line replies are rendered?
EDIT: I tried console.log() the response inside the express post request believing that CURL was the problem. It appears CURL is not the problem and ChatGPT simply cuts off mid reply
const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: "my-api-key",
});
const openai = new OpenAIApi(configuration);
// Set up the server
const app = express();
app.use(bodyParser.json());
app.use(cors())
// Set up the ChatGPT endpoint
app.post("/chat", async (req, res) => {
// Get the prompt from the request
const { prompt } = req.body;
// Generate a response with ChatGPT
const completion = await openai.createCompletion({
model: "text-davinci-002",
prompt: prompt,
});
console.log(completion.data.choices[0].text) // still cuts off
res.send(completion.data.choices[0].text);
});
// Start the server
const port = 8080;
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});
Curl
curl -X POST -H "Content-Type: application/json" -d '{"prompt":"Hello, how are you doing today?"}' http://localhost:8080/chat