mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🚤 refactor: Optimize Request Lifecycle Speeds (#3222)
* refactor: optimize backend operations for client requests * fix: message styling * refactor: Improve handleKeyUp logic in StreamRunManager.js and handleText.js * refactor: Improve handleKeyUp logic in StreamRunManager.js and handleText.js * fix: clear new convo messages on clear all convos * fix: forgot to pass userId to getConvo * refactor: update getPartialText to send basePayload.text
This commit is contained in:
parent
83619de158
commit
a2fd975cd5
17 changed files with 115 additions and 65 deletions
|
|
@ -12,33 +12,35 @@ const citationRegex = /\[\^\d+?\^]/g;
|
|||
|
||||
const addSpaceIfNeeded = (text) => (text.length > 0 && !text.endsWith(' ') ? text + ' ' : text);
|
||||
|
||||
const base = { message: true, initial: true };
|
||||
const createOnProgress = ({ generation = '', onProgress: _onProgress }) => {
|
||||
let i = 0;
|
||||
let tokens = addSpaceIfNeeded(generation);
|
||||
|
||||
const progressCallback = async (partial, { res, text, bing = false, ...rest }) => {
|
||||
const basePayload = Object.assign({}, base, { text: tokens || '' });
|
||||
|
||||
const progressCallback = (partial, { res, text, ...rest }) => {
|
||||
let chunk = partial === text ? '' : partial;
|
||||
tokens += chunk;
|
||||
tokens = tokens.replaceAll('[DONE]', '');
|
||||
basePayload.text = basePayload.text + chunk;
|
||||
|
||||
if (bing) {
|
||||
tokens = citeText(tokens, true);
|
||||
const payload = Object.assign({}, basePayload, rest);
|
||||
sendMessage(res, payload);
|
||||
if (_onProgress) {
|
||||
_onProgress(payload);
|
||||
}
|
||||
if (i === 0) {
|
||||
basePayload.initial = false;
|
||||
}
|
||||
|
||||
const payload = { text: tokens, message: true, initial: i === 0, ...rest };
|
||||
sendMessage(res, { ...payload, text: tokens });
|
||||
_onProgress && _onProgress(payload);
|
||||
i++;
|
||||
};
|
||||
|
||||
const sendIntermediateMessage = (res, payload, extraTokens = '') => {
|
||||
tokens += extraTokens;
|
||||
sendMessage(res, {
|
||||
text: tokens?.length === 0 ? '' : tokens,
|
||||
message: true,
|
||||
initial: i === 0,
|
||||
...payload,
|
||||
});
|
||||
basePayload.text = basePayload.text + extraTokens;
|
||||
const message = Object.assign({}, basePayload, payload);
|
||||
sendMessage(res, message);
|
||||
if (i === 0) {
|
||||
basePayload.initial = false;
|
||||
}
|
||||
i++;
|
||||
};
|
||||
|
||||
|
|
@ -47,7 +49,7 @@ const createOnProgress = ({ generation = '', onProgress: _onProgress }) => {
|
|||
};
|
||||
|
||||
const getPartialText = () => {
|
||||
return tokens;
|
||||
return basePayload.text;
|
||||
};
|
||||
|
||||
return { onProgress, getPartialText, sendIntermediateMessage };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue