From 25a2c6ee52d28c0f6dc9023ea7431a813a1b1c2b Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 28 Oct 2024 05:34:50 -0700 Subject: [PATCH] fix/refac: use user prompt for title gen fallback --- src/lib/components/chat/Chat.svelte | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index a0feda057..96d2ccf83 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -1895,20 +1895,21 @@ }; const generateChatTitle = async (messages) => { + const lastUserMessage = messages.filter((message) => message.role === 'user').at(-1); + if ($settings?.title?.auto ?? true) { - const lastMessage = messages.at(-1); const modelId = selectedModels[0]; const title = await generateTitle(localStorage.token, modelId, messages, $chatId).catch( (error) => { console.error(error); - return 'New Chat'; + return lastUserMessage?.content ?? 'New Chat'; } ); return title; } else { - return 'New Chat'; + return lastUserMessage?.content ?? 'New Chat'; } };