mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
chore: delegate text handling to one place, html sanitization in progress
This commit is contained in:
parent
2e20b28c4d
commit
d0ef0f84c8
4 changed files with 27 additions and 10 deletions
|
|
@ -1,4 +1,4 @@
|
|||
const { citeText } = require('../../app/');
|
||||
const { citeText, detectCode } = require('../../app/');
|
||||
const _ = require('lodash');
|
||||
const sanitizeHtml = require('sanitize-html');
|
||||
|
||||
|
|
@ -20,11 +20,14 @@ const createOnProgress = () => {
|
|||
|
||||
const progressCallback = async (partial, { res, text, bing = false, ...rest }) => {
|
||||
tokens += partial === text ? '' : partial;
|
||||
tokens = tokens.trim();
|
||||
tokens = tokens.replaceAll('[DONE]', '');
|
||||
if (tokens.includes('```')) {
|
||||
tokens = sanitizeHtml(tokens);
|
||||
|
||||
if (tokens.match(/^\n/)) {
|
||||
tokens = tokens.replace(/^\n/, '');
|
||||
}
|
||||
// if (tokens.includes('```')) {
|
||||
// tokens = sanitizeHtml(tokens);
|
||||
// }
|
||||
|
||||
if (bing) {
|
||||
tokens = citeText(tokens, true);
|
||||
|
|
@ -42,4 +45,15 @@ const createOnProgress = () => {
|
|||
return onProgress;
|
||||
};
|
||||
|
||||
module.exports = { handleError, sendMessage, createOnProgress };
|
||||
const handleText = async (input) => {
|
||||
let text = input;
|
||||
text = await detectCode(text);
|
||||
// if (text.includes('```')) {
|
||||
// text = sanitizeHtml(text);
|
||||
// text = text.replaceAll(') =>', ') =>');
|
||||
// }
|
||||
|
||||
return text;
|
||||
};
|
||||
|
||||
module.exports = { handleError, sendMessage, createOnProgress, handleText };
|
||||
Loading…
Add table
Add a link
Reference in a new issue