diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 5cc01ed267..84574cb9bd 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -4552,13 +4552,18 @@ const id = $chatId; generatingTitle = true; titleDraft = ''; - const messages = createMessagesList(history, history.currentId).map((message) => ({ + const branch = createMessagesList(history, history.currentId); + const messages = branch.map((message) => ({ role: message.role, content: getOutputText(message.output) || message.content || '' })); + const modelId = selectedModels.find((modelId: string) => modelId) ?? ''; + const responseMessage = branch + .filter((message) => message.role === 'assistant' && message.model === modelId) + .at(-1); const generatedTitle = await generateTitle( localStorage.token, - selectedModels.find((modelId: string) => modelId) ?? '', + responseMessage?.selectedModelId ?? modelId, messages ).catch((error) => { toast.error(`${error}`); diff --git a/src/lib/components/layout/Sidebar/ChatItem.svelte b/src/lib/components/layout/Sidebar/ChatItem.svelte index e6af32bc98..99a9f5914f 100644 --- a/src/lib/components/layout/Sidebar/ChatItem.svelte +++ b/src/lib/components/layout/Sidebar/ChatItem.svelte @@ -567,13 +567,13 @@ } catch {} } - if (!model && history?.messages && history?.currentId) { + if (history?.messages && history?.currentId) { let currentId = history.currentId; while (currentId) { const msg = history.messages[currentId]; if (!msg) break; - if (msg.role === 'assistant' && msg.model) { - model = msg.model; + if (msg.role === 'assistant' && msg.model && (!model || msg.model === model)) { + model = msg.selectedModelId ?? msg.model; break; } currentId = msg.parentId;