mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
chatgpt is taking shape, convo persists, layout mimics original
This commit is contained in:
parent
3a199757ae
commit
f889f23792
9 changed files with 161 additions and 35 deletions
|
|
@ -15,22 +15,32 @@ app.get('/', function (req, res) {
|
|||
res.sendFile(path.join(projectPath, 'public', 'index.html'));
|
||||
});
|
||||
|
||||
app.post('/ask', (req, res) => {
|
||||
console.log(req.body, 'we in here');
|
||||
app.post('/ask', async (req, res) => {
|
||||
console.log(req.body);
|
||||
const { text, parentMessageId, conversationId } = req.body;
|
||||
|
||||
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'
|
||||
'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);
|
||||
|
||||
let i = 0;
|
||||
const progressCallback = (partial) => {
|
||||
// console.log('partial', partial);
|
||||
if (i === 0) {
|
||||
res.write(`event: message\ndata: ${JSON.stringify({ ...partial, initial: true })}\n\n`);
|
||||
i++;
|
||||
}
|
||||
const data = JSON.stringify({...partial, message: true });
|
||||
res.write(`event: message\ndata: ${data}\n\n`);
|
||||
};
|
||||
|
||||
const gptResponse = await ask(text, progressCallback, { parentMessageId, conversationId });
|
||||
res.write(`event: message\ndata: ${JSON.stringify(gptResponse)}\n\n`);
|
||||
res.end();
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue