Merge pull request #85 from danny-avila/bing-refusal

Bing refusal
This commit is contained in:
Danny Avila 2023-03-17 09:14:40 -04:00 committed by GitHub
commit 1eab4d240d
4 changed files with 6 additions and 23 deletions

1
.gitignore vendored
View file

@ -33,6 +33,7 @@ client/public/main.js.LICENSE.txt
# Deployed apps should consider commenting these lines out: # Deployed apps should consider commenting these lines out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules/ node_modules/
meili_data/
api/node_modules/ api/node_modules/
client/node_modules/ client/node_modules/
bower_components/ bower_components/

View file

@ -117,8 +117,8 @@ const ask = async ({
); );
conversationId = userMessage.conversationId; conversationId = userMessage.conversationId;
response.text = response.response; response.text = response.response || response.details.spokenText || '**Bing refused to answer.**';
delete response.response; // delete response.response;
// response.id = response.details.messageId; // response.id = response.details.messageId;
response.suggestions = response.suggestions =
response.details.suggestedResponses && response.details.suggestedResponses &&

View file

@ -111,8 +111,8 @@ const ask = async ({
response.conversationSignature = convo.conversationSignature response.conversationSignature = convo.conversationSignature
? convo.conversationSignature ? convo.conversationSignature
: crypto.randomUUID(); : crypto.randomUUID();
response.text = response.response; response.text = response.response || response.details.spokenText || '**Bing refused to answer.**';
delete response.response; // delete response.response;
response.suggestions = response.suggestions =
response.details.suggestedResponses && response.details.suggestedResponses &&
response.details.suggestedResponses.map((s) => s.text); response.details.suggestedResponses.map((s) => s.text);

View file

@ -1,8 +1,6 @@
const _ = require('lodash'); const _ = require('lodash');
const sanitizeHtml = require('sanitize-html');
const citationRegex = /\[\^\d+?\^]/g; const citationRegex = /\[\^\d+?\^]/g;
const { getCitations, citeText, detectCode } = require('../../app/'); const { getCitations, citeText, detectCode } = require('../../app/');
// const htmlTagRegex = /(<\/?\s*[a-zA-Z]*\s*(?:\s+[a-zA-Z]+\s*=\s*(?:"[^"]*"|'[^']*'))*\s*(?:\/?)>|<\s*[a-zA-Z]+\s*(?:\s+[a-zA-Z]+\s*=\s*(?:"[^"]*"|'[^']*'))*\s*(?:\/?>|<\/?>))/g;
const handleError = (res, message) => { const handleError = (res, message) => {
res.write(`event: error\ndata: ${JSON.stringify(message)}\n\n`); res.write(`event: error\ndata: ${JSON.stringify(message)}\n\n`);
@ -28,14 +26,6 @@ const createOnProgress = () => {
tokens = tokens.replace(/^\n/, ''); tokens = tokens.replace(/^\n/, '');
} }
// const htmlTags = tokens.match(htmlTagRegex);
// if (tokens.includes('```') && htmlTags && htmlTags.length > 0) {
// htmlTags.forEach((tag) => {
// const sanitizedTag = sanitizeHtml(tag);
// tokens = tokens.replaceAll(tag, sanitizedTag);
// });
// }
if (bing) { if (bing) {
tokens = citeText(tokens, true); tokens = citeText(tokens, true);
} }
@ -54,7 +44,7 @@ const createOnProgress = () => {
const handleText = async (response, bing = false) => { const handleText = async (response, bing = false) => {
let { text } = response; let { text } = response;
text = await detectCode(text); // text = await detectCode(text);
response.text = text; response.text = text;
if (bing) { if (bing) {
@ -66,14 +56,6 @@ const handleText = async (response, bing = false) => {
text += links?.length > 0 ? `\n<small>${links}</small>` : ''; text += links?.length > 0 ? `\n<small>${links}</small>` : '';
} }
// const htmlTags = text.match(htmlTagRegex);
// if (text.includes('```') && htmlTags && htmlTags.length > 0) {
// htmlTags.forEach((tag) => {
// const sanitizedTag = sanitizeHtml(tag);
// text = text.replaceAll(tag, sanitizedTag);
// });
// }
return text; return text;
}; };