-
Notifications
You must be signed in to change notification settings - Fork 67
Refine/Add thinking text and refine streaming chat #438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iceljc
wants to merge
2
commits into
SciSharp:main
Choose a base branch
from
iceljc:refine/upgrade-to-5.x
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| uploadConversationFiles, | ||
| getAddressOptions, | ||
| pinConversationToDashboard, | ||
| stopStreaming as stopStreamingApi, | ||
| } from '$lib/services/conversation-service.js'; | ||
| import { | ||
| PUBLIC_LIVECHAT_ENTRY_ICON, | ||
|
|
@@ -200,7 +201,6 @@ | |
| let isListening = $state(false); | ||
| let isLite = $state(false); | ||
| let isFrame = $state(false); | ||
| let loadTextEditor = $state(false); | ||
| let autoScrollLog = $state(false); | ||
| let loadChatUtils = $state(false); | ||
| let disableSpeech = $state(false); | ||
|
|
@@ -212,12 +212,15 @@ | |
| let copyClicked = $state(false); | ||
| let isStreaming = $state(false); | ||
| let isHandlingQueue = $state(false); | ||
| let isStopStreamClicked = $state(false); | ||
|
|
||
| let loadEditor = $derived(!isSendingMsg && !isThinking && loadTextEditor && messageQueue.length === 0); | ||
| let disableAction = $derived(!ADMIN_ROLES.includes(currentUser?.role || '') && currentUser?.id !== conversationUser?.id || !AgentExtensions.chatable(agent)); | ||
| // let loadEditor = $derived(!isSendingMsg && !isThinking && loadTextEditor && messageQueue.length === 0); | ||
| let loadEditor = true; | ||
| let disableAction = $derived(!ADMIN_ROLES.includes(currentUser?.role || '') | ||
| && currentUser?.id !== conversationUser?.id | ||
| || !AgentExtensions.chatable(agent)); | ||
|
|
||
| $effect(() => { | ||
| loadTextEditor = true; | ||
| if (loadEditor) { | ||
| focusChatTextArea(); | ||
| } | ||
|
|
@@ -578,7 +581,11 @@ | |
| dialogs.push({ | ||
| ...message, | ||
| is_chat_message: false, | ||
| is_dummy: true | ||
| is_dummy: true, | ||
| meta_data: { | ||
| ...(message.meta_data || {}), | ||
| thinking_text: message.meta_data?.thinking_text || '' | ||
| } | ||
| }); | ||
| } | ||
| refresh(); | ||
|
|
@@ -595,6 +602,13 @@ | |
| && lastMsg?.is_dummy | ||
| ) { | ||
| setTimeout(() => { | ||
| const thinkingText = message.meta_data?.thinking_text || ''; | ||
| if (thinkingText) { | ||
| if (!dialogs[dialogs.length - 1].meta_data) { | ||
| dialogs[dialogs.length - 1].meta_data = { thinking_text: '' }; | ||
| } | ||
| dialogs[dialogs.length - 1].meta_data.thinking_text += thinkingText; | ||
| } | ||
| dialogs[dialogs.length - 1].text += message.text; | ||
| refreshDialogs(); | ||
| }, 0); | ||
|
|
@@ -624,6 +638,18 @@ | |
| } | ||
|
|
||
| try { | ||
| const thinkingText = item.meta_data?.thinking_text || ''; | ||
| if (thinkingText) { | ||
| if (!dialogs[dialogs.length - 1].meta_data) { | ||
| dialogs[dialogs.length - 1].meta_data = { thinking_text: '' }; | ||
| } | ||
| for (const tt of thinkingText) { | ||
| dialogs[dialogs.length - 1].meta_data.thinking_text += tt; | ||
| refreshDialogs(); | ||
| await delay(10); | ||
| } | ||
| } | ||
|
|
||
| for (const char of item.text) { | ||
| dialogs[dialogs.length - 1].text += char; | ||
| refreshDialogs(); | ||
|
|
@@ -642,6 +668,22 @@ | |
| refresh(); | ||
| } | ||
|
|
||
| function stopStreaming() { | ||
| isStopStreamClicked = true; | ||
| // @ts-ignore | ||
| stopStreamingApi(page.params.conversationId).then((res) => { | ||
| if (res?.success) { | ||
| isStreaming = false; | ||
| isThinking = false; | ||
| isSendingMsg = false; | ||
| messageQueue = []; | ||
| isHandlingQueue = false; | ||
| refresh(); | ||
| } | ||
| isStopStreamClicked = false; | ||
| }); | ||
|
Comment on lines
+671
to
+684
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Stop click can get stuck In chat-box.svelte, stopStreaming() only resets isStopStreamClicked inside the .then() handler, so if stopStreamingApi rejects the UI can remain in a permanently “clicked” state with no Stop button recovery. This can effectively dead-end the streaming control until a refresh. Agent Prompt
|
||
| } | ||
|
|
||
| /** @param {import('$conversationTypes').ChatResponseModel} message */ | ||
| function onIndicationReceived(message) { | ||
| isThinking = true; | ||
|
|
@@ -757,8 +799,7 @@ | |
| ...data, | ||
| postback: postback, | ||
| states: [ | ||
| ...data?.states || [], | ||
| { key: "use_stream_message", value: PUBLIC_LIVECHAT_STREAM_ENABLED } | ||
| ...data?.states || [] | ||
| ] | ||
| }; | ||
|
|
||
|
|
@@ -801,7 +842,7 @@ | |
| } | ||
|
|
||
| // @ts-ignore | ||
| await sendMessageToHub(agentId, convId, msgText, messageData); | ||
| await sendMessageToHub(agentId, convId, msgText, messageData, PUBLIC_LIVECHAT_STREAM_ENABLED === "true"); | ||
| deleteMessageDraft(); | ||
| isSendingMsg = false; | ||
| } | ||
|
|
@@ -1973,7 +2014,7 @@ | |
| {#if message.sender.role == UserRole.Client} | ||
| <img src="images/users/user-dummy.jpg" class="rounded-circle avatar-sm" style="margin-bottom: -15px;" alt="avatar"> | ||
| {:else} | ||
| {@const isShowIcon = (message?.rich_content?.message?.text || message?.text) || message?.uuid !== lastBotMsg?.uuid} | ||
| {@const isShowIcon = (message?.rich_content?.message?.text || message?.text || message?.meta_data?.thinking_text) || message?.uuid !== lastBotMsg?.uuid} | ||
| <img | ||
| class="rounded-circle avatar-sm" | ||
| style={`display: ${isShowIcon ? 'block' : 'none'}; margin-bottom: -15px;`} | ||
|
|
@@ -1983,7 +2024,7 @@ | |
| {/if} | ||
| </div> | ||
| <div class="msg-container"> | ||
| <RcMessage containerClasses={'bot-msg'} markdownClasses={'markdown-dark text-dark'} message={message} /> | ||
| <RcMessage containerClasses={'bot-msg'} markdownClasses={'markdown-dark text-dark'} message={message} isStreaming={isStreaming || isThinking} /> | ||
| {#if message?.message_id === lastBotMsg?.message_id && message?.uuid === lastBotMsg?.uuid} | ||
| {@const isStreamEnd = (message?.rich_content?.message?.text || message?.text) && !isStreaming && !isHandlingQueue && !isThinking} | ||
| <div style={`display: ${isStreamEnd ? 'flex' : 'none'}; gap: 10px; flex-wrap: wrap; margin-top: 5px;`}> | ||
|
|
@@ -2150,7 +2191,7 @@ | |
| <ChatFileUploader | ||
| accept={'.png,.jpg,.jpeg'} | ||
| containerClasses={'line-align-center text-primary chat-util-item'} | ||
| disabled={disableAction} | ||
| disabled={isSendingMsg || isThinking || disableAction} | ||
| onfiledroped={() => refresh()} | ||
| > | ||
| <span> | ||
|
|
@@ -2164,7 +2205,7 @@ | |
| <ChatFileUploader | ||
| accept={'.pdf,.xlsx,.xls,.csv'} | ||
| containerClasses={'line-align-center text-primary chat-util-item'} | ||
| disabled={disableAction} | ||
| disabled={isSendingMsg || isThinking || disableAction} | ||
| onfiledroped={() => refresh()} | ||
| > | ||
| <span> | ||
|
|
@@ -2178,7 +2219,7 @@ | |
| <ChatFileUploader | ||
| accept={'.wav,.mp3'} | ||
| containerClasses={'line-align-center text-primary chat-util-item'} | ||
| disabled={disableAction} | ||
| disabled={isSendingMsg || isThinking || disableAction} | ||
| onfiledroped={() => refresh()} | ||
| > | ||
| <span> | ||
|
|
@@ -2196,21 +2237,35 @@ | |
| onclick={() => toggleBigMessageModal()} | ||
| /> | ||
| {#if PUBLIC_LIVECHAT_FILES_ENABLED === 'true'} | ||
| <ChatUtil disabled={disableAction} onclick={() => loadChatUtils = true} /> | ||
| <ChatUtil | ||
| disabled={isSendingMsg || isThinking || disableAction} | ||
| onclick={() => loadChatUtils = true} | ||
| /> | ||
| {/if} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div class="col-auto"> | ||
| <button | ||
| type="submit" | ||
| class={`btn btn-rounded chat-send waves-effect waves-light ${mode === TRAINING_MODE ? 'btn-danger' : 'btn-primary'}`} | ||
| disabled={!_.trim(text) || isSendingMsg || isThinking || disableAction} | ||
| onclick={() => sentTextMessage()} | ||
| > | ||
| <span class="d-none d-md-inline-block me-2">Send</span> | ||
| <i class="mdi mdi-send"></i> | ||
| </button> | ||
| {#if !isStopStreamClicked && isStreaming && PUBLIC_LIVECHAT_STREAM_ENABLED === 'true'} | ||
| <button | ||
| type="button" | ||
| class="btn btn-rounded chat-send waves-effect waves-light btn-danger" | ||
| aria-label="Stop streaming" | ||
| onclick={() => stopStreaming()} | ||
| > | ||
| <i class="mdi mdi-stop"></i> | ||
| </button> | ||
| {:else} | ||
| <button | ||
| type="submit" | ||
| class={`btn btn-rounded chat-send waves-effect waves-light ${mode === TRAINING_MODE ? 'btn-danger' : 'btn-primary'}`} | ||
| disabled={!_.trim(text) || isSendingMsg || isThinking || disableAction} | ||
| onclick={() => sentTextMessage()} | ||
| > | ||
| <span class="d-none d-md-inline-block me-2">Send</span> | ||
| <i class="mdi mdi-send"></i> | ||
| </button> | ||
| {/if} | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Streaming update can throw
🐞 Bug☼ ReliabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools