chore: delegate text handling to one place, html sanitization in progress

This commit is contained in:
Danny Avila 2023-03-14 16:05:46 -04:00
parent 2e20b28c4d
commit d0ef0f84c8
4 changed files with 27 additions and 10 deletions

View file

@ -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 };