Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified tools/server/public/index.html.gz
Binary file not shown.
28 changes: 18 additions & 10 deletions tools/server/webui/src/lib/stores/chat.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ class ChatStore {
await this.updateConversationName(this.activeConversation.id, title);
}

const allMessages = await DatabaseStore.getConversationMessages(this.activeConversation.id);
const assistantMessage = await this.createAssistantMessage(userMessage.id);

if (!assistantMessage) {
Expand All @@ -560,15 +559,23 @@ class ChatStore {
this.activeMessages.push(assistantMessage);
// Don't update currNode until after streaming completes to maintain proper conversation path

await this.streamChatCompletion(allMessages, assistantMessage, undefined, (error: Error) => {
if (error.name === 'ContextError' && userMessage) {
const userMessageIndex = this.findMessageIndex(userMessage.id);
if (userMessageIndex !== -1) {
this.activeMessages.splice(userMessageIndex, 1);
DatabaseStore.deleteMessage(userMessage.id).catch(console.error);
const conversationContext = this.activeMessages.slice(0, -1);

await this.streamChatCompletion(
conversationContext,
assistantMessage,
undefined,
(error: Error) => {
if (error.name === 'ContextError' && userMessage) {
const userMessageIndex = this.findMessageIndex(userMessage.id);

if (userMessageIndex !== -1) {
this.activeMessages.splice(userMessageIndex, 1);
DatabaseStore.deleteMessage(userMessage.id).catch(console.error);
}
}
}
});
);
} catch (error) {
if (this.isAbortError(error)) {
this.isLoading = false;
Expand Down Expand Up @@ -810,7 +817,6 @@ class ChatStore {
this.currentResponse = '';

try {
const allMessages = await DatabaseStore.getConversationMessages(this.activeConversation.id);
const assistantMessage = await this.createAssistantMessage();

if (!assistantMessage) {
Expand All @@ -821,7 +827,9 @@ class ChatStore {
await DatabaseStore.updateCurrentNode(this.activeConversation.id, assistantMessage.id);
this.activeConversation.currNode = assistantMessage.id;

await this.streamChatCompletion(allMessages, assistantMessage);
const conversationContext = this.activeMessages.slice(0, -1);

await this.streamChatCompletion(conversationContext, assistantMessage);
} catch (regenerateError) {
console.error('Failed to regenerate response:', regenerateError);
this.isLoading = false;
Expand Down