fix: debounce title request and handle error with default title

This commit is contained in:
Danny Avila 2023-03-15 12:47:30 -04:00
parent 96ca783517
commit 2fd50c99b8
7 changed files with 70 additions and 100 deletions

View file

@ -1,4 +1,4 @@
const { citeText, detectCode } = require('../../app/');
const { titleConvo, citeText, detectCode } = require('../../app/');
const _ = require('lodash');
const sanitizeHtml = require('sanitize-html');
@ -14,6 +14,23 @@ const sendMessage = (res, message) => {
res.write(`event: message\ndata: ${JSON.stringify(message)}\n\n`);
};
const genTitle = async ({ model, text, response }) => {
let title = 'New Chat';
try {
title = await titleConvo({
model,
message: text,
response: JSON.stringify(response?.text)
});
} catch (e) {
console.error(e);
console.log('There was an issue generating title, see error above');
}
console.log('CONVERSATION TITLE', title);
return title;
};
const createOnProgress = () => {
let i = 0;
let tokens = '';
@ -56,4 +73,4 @@ const handleText = async (input) => {
return text;
};
module.exports = { handleError, sendMessage, createOnProgress, handleText };
module.exports = { handleError, sendMessage, createOnProgress, genTitle, handleText };