mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
chore: hotfix for browser client
This commit is contained in:
parent
0405206438
commit
80ca3bc375
3 changed files with 21 additions and 5 deletions
|
|
@ -24,6 +24,7 @@ const browserClient = async ({ text, onProgress, convo, abortController }) => {
|
|||
options = { ...options, ...convo };
|
||||
}
|
||||
|
||||
/* will error if given a convoId at the start */
|
||||
if (convo.parentMessageId.startsWith('0000')) {
|
||||
delete options.conversationId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,13 +190,19 @@ module.exports = {
|
|||
}
|
||||
},
|
||||
getConvo,
|
||||
/* chore: this method is not properly error handled */
|
||||
getConvoTitle: async (user, conversationId) => {
|
||||
try {
|
||||
const convo = await getConvo(user, conversationId);
|
||||
return convo.title;
|
||||
/* ChatGPT Browser was triggering error here due to convo being saved later */
|
||||
if (convo && !convo.title) {
|
||||
return null;
|
||||
} else {
|
||||
return convo.title;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return { message: 'Error getting conversation title' };
|
||||
return 'Error getting conversation title';
|
||||
}
|
||||
},
|
||||
deleteConvos: async (user, filter) => {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@ router.post('/', async (req, res) => {
|
|||
return handleError(res, { text: 'Prompt empty or too short' });
|
||||
}
|
||||
|
||||
console.log('model:', model, 'oldConvoId:', oldConversationId);
|
||||
const conversationId = oldConversationId || crypto.randomUUID();
|
||||
console.log('conversationId after old:', conversationId);
|
||||
|
||||
const userMessageId = crypto.randomUUID();
|
||||
const userParentMessageId = parentMessageId || '00000000-0000-0000-0000-000000000000';
|
||||
|
|
@ -36,7 +38,7 @@ router.post('/', async (req, res) => {
|
|||
...convo
|
||||
});
|
||||
|
||||
if (!overrideParentMessageId) {
|
||||
if (!overrideParentMessageId && model !== 'chatgptBrowser') {
|
||||
await saveMessage(userMessage);
|
||||
await saveConvo(req?.session?.user?.username, { ...userMessage, model, ...convo });
|
||||
}
|
||||
|
|
@ -144,6 +146,7 @@ const ask = async ({
|
|||
// gptResponse.final = true;
|
||||
gptResponse.text = await handleText(gptResponse);
|
||||
|
||||
|
||||
if (convo.chatGptLabel?.length > 0 && model === 'chatgptCustom') {
|
||||
gptResponse.chatGptLabel = convo.chatGptLabel;
|
||||
}
|
||||
|
|
@ -155,6 +158,11 @@ const ask = async ({
|
|||
// override the parentMessageId, for the regeneration.
|
||||
gptResponse.parentMessageId = overrideParentMessageId || userMessageId;
|
||||
|
||||
/* this is a hacky solution to get the browserClient working right, will refactor later */
|
||||
if (model === 'chatgptBrowser' && userParentMessageId.startsWith('000')) {
|
||||
await saveMessage({ ...userMessage, conversationId: gptResponse.conversationId });
|
||||
}
|
||||
|
||||
await saveMessage(gptResponse);
|
||||
await saveConvo(req?.session?.user?.username, gptResponse);
|
||||
sendMessage(res, {
|
||||
|
|
@ -171,7 +179,8 @@ const ask = async ({
|
|||
await saveConvo(
|
||||
req?.session?.user?.username,
|
||||
{
|
||||
conversationId,
|
||||
/* again, for sake of browser client, will soon refactor */
|
||||
conversationId: model === 'chatgptBrowser' ? gptResponse.conversationId : conversationId,
|
||||
title
|
||||
}
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue