mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-24 04:10:15 +01:00
working SSE stream
This commit is contained in:
parent
81866f197a
commit
27f7276fc8
2 changed files with 235 additions and 15 deletions
|
|
@ -1,8 +1,10 @@
|
|||
const path = require('path');
|
||||
const express = require('express');
|
||||
const { ask } = require('./app/chatgpt');
|
||||
const { ask } = require('../app/chatgpt');
|
||||
const app = express();
|
||||
const port = 3050;
|
||||
const cors = require('cors');
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
const projectPath = path.join(__dirname, '..');
|
||||
|
|
@ -14,21 +16,21 @@ app.get('/', function (req, res) {
|
|||
});
|
||||
|
||||
app.post('/ask', (req, res) => {
|
||||
console.log(req.body);
|
||||
console.log(req.body, 'we in here');
|
||||
|
||||
// res.writeHead(200, {
|
||||
// Connection: 'keep-alive',
|
||||
// 'Content-Type': 'text/event-stream',
|
||||
// 'Cache-Control': 'no-cache, no-transform',
|
||||
// 'Access-Control-Allow-Origin':'*',
|
||||
// 'X-Accel-Buffering':'no'
|
||||
// });
|
||||
// res.write('data: This is chunk 1\n');
|
||||
// res.write('data: This is chunk 2\n');
|
||||
// setTimeout(() => {
|
||||
// res.write('data: This is chunk 3\n');
|
||||
// res.end();
|
||||
// }, 3500);
|
||||
res.writeHead(200, {
|
||||
Connection: 'keep-alive',
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Cache-Control': 'no-cache, no-transform',
|
||||
'Access-Control-Allow-Origin':'*',
|
||||
'X-Accel-Buffering':'no'
|
||||
});
|
||||
res.write('event: message\ndata: This is chunk 1\n\n');
|
||||
res.write('event: message\ndata: This is chunk 2\n\n');
|
||||
setTimeout(() => {
|
||||
res.write('event: message\ndata: This is chunk 3\n\n');
|
||||
res.end();
|
||||
}, 3500);
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue