mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
fix the double saving of responses in the chat note
This commit is contained in:
parent
e968e00c80
commit
9eec41816f
@ -549,8 +549,8 @@ export default class LlmChatPanel extends BasicWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the final state to the Chat Note after getting the response
|
// Note: We don't need to save here since the streaming completion and direct response methods
|
||||||
await this.saveCurrentData();
|
// both call saveCurrentData() when they're done
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error processing user message:', error);
|
console.error('Error processing user message:', error);
|
||||||
toastService.showError('Failed to process message');
|
toastService.showError('Failed to process message');
|
||||||
@ -903,13 +903,14 @@ export default class LlmChatPanel extends BasicWidget {
|
|||||||
applySyntaxHighlight($(assistantMessageEl as HTMLElement));
|
applySyntaxHighlight($(assistantMessageEl as HTMLElement));
|
||||||
|
|
||||||
// Update message in the data model for storage
|
// Update message in the data model for storage
|
||||||
const existingMsgIndex = this.messages.findIndex(msg =>
|
// Find the last assistant message to update, or add a new one if none exists
|
||||||
msg.role === 'assistant' && msg.content !== assistantResponse
|
const assistantMessages = this.messages.filter(msg => msg.role === 'assistant');
|
||||||
);
|
const lastAssistantMsgIndex = assistantMessages.length > 0 ?
|
||||||
|
this.messages.lastIndexOf(assistantMessages[assistantMessages.length - 1]) : -1;
|
||||||
|
|
||||||
if (existingMsgIndex >= 0) {
|
if (lastAssistantMsgIndex >= 0) {
|
||||||
// Update existing message
|
// Update existing message
|
||||||
this.messages[existingMsgIndex].content = assistantResponse;
|
this.messages[lastAssistantMsgIndex].content = assistantResponse;
|
||||||
} else {
|
} else {
|
||||||
// Add new message
|
// Add new message
|
||||||
this.messages.push({
|
this.messages.push({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user