From c948b58eb5f6d1a07ce25732c88f2509ab3fb238 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Fri, 20 Sep 2024 03:05:04 -0700 Subject: [PATCH] Aix: all for a dot-dot-dot --- src/apps/chat/editors/chat-persona.ts | 12 +++++++++++- src/modules/aix/client/aix.client.ts | 7 ++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/apps/chat/editors/chat-persona.ts b/src/apps/chat/editors/chat-persona.ts index 3a5ef9641..477c29d5f 100644 --- a/src/apps/chat/editors/chat-persona.ts +++ b/src/apps/chat/editors/chat-persona.ts @@ -64,10 +64,20 @@ export async function runPersonaOnConversationHead( conversationId, { abortSignal: abortController.signal, throttleParallelThreads: parallelViewCount }, (messageOverwrite: AixChatGenerateContent_DMessage, messageComplete: boolean) => { + // Note: there was an abort check here, but it removed the last packet, which contained the cause and final text. + // if (abortController.signal.aborted) + // console.warn('runPersonaOnConversationHead: Aborted', { conversationId, assistantLlmId, messageOverwrite }); // deep copy the object to avoid partial updates - cHandler.messageEdit(assistantMessageId, structuredClone(messageOverwrite), messageComplete, false); + let deepCopy = structuredClone(messageOverwrite); + + // [Cosmetic Logic] if the content hasn't come yet, don't replace the fragments to still show the placeholder + if (!messageComplete && deepCopy.pendingIncomplete && deepCopy.fragments?.length === 0) + delete (deepCopy as any).fragments; + + // update the message + cHandler.messageEdit(assistantMessageId, deepCopy, messageComplete, false); // if requested, speak the message autoSpeaker?.handleMessage(messageOverwrite, messageComplete); diff --git a/src/modules/aix/client/aix.client.ts b/src/modules/aix/client/aix.client.ts index b5ea4c923..1d7780613 100644 --- a/src/modules/aix/client/aix.client.ts +++ b/src/modules/aix/client/aix.client.ts @@ -224,7 +224,12 @@ export async function aixChatGenerateContent_DMessage { if (isDone) return; _llToDMessage(ll, dMessage); - throttler?.decimate(() => onStreamingUpdate?.(dMessage, false)); + if (onStreamingUpdate) { + if (throttler) + throttler.decimate(() => onStreamingUpdate(dMessage, false)); + else + onStreamingUpdate(dMessage, false); + } }, );