Merge pull request #863 from SuanmoSuanyangTechnology/feature/file_variable_zy
fix(web): stream loading
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
* @Author: ZhaoYing
|
* @Author: ZhaoYing
|
||||||
* @Date: 2025-12-10 16:46:17
|
* @Date: 2025-12-10 16:46:17
|
||||||
* @Last Modified by: ZhaoYing
|
* @Last Modified by: ZhaoYing
|
||||||
* @Last Modified time: 2026-04-08 11:23:18
|
* @Last Modified time: 2026-04-10 18:46:57
|
||||||
*/
|
*/
|
||||||
import { type FC, useRef, useEffect, useState } from 'react'
|
import { type FC, useRef, useEffect, useState } from 'react'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
@@ -217,7 +217,7 @@ const ChatContent: FC<ChatContentProps> = ({
|
|||||||
{/* Message bubble */}
|
{/* Message bubble */}
|
||||||
<div className={clsx('rb:text-left rb:leading-5 rb:inline-block rb:wrap-break-word rb:relative', item.role === 'user' ? contentClassNames : '', {
|
<div className={clsx('rb:text-left rb:leading-5 rb:inline-block rb:wrap-break-word rb:relative', item.role === 'user' ? contentClassNames : '', {
|
||||||
// Error message style (content is null and not assistant message)
|
// Error message style (content is null and not assistant message)
|
||||||
'rb:bg-[rgba(255,93,52,0.08)] rb:text-[#FF5D34]': (item.status && item.status !== 'completed') || (errorDesc && item.role === 'assistant' && item.content === null && !renderRuntime),
|
'rb:text-[#FF5D34]': (item.status && item.status !== 'completed') || (errorDesc && item.role === 'assistant' && item.content === null && !renderRuntime),
|
||||||
// Assistant message style
|
// Assistant message style
|
||||||
'rb:bg-[#E3EBFD] rb:p-[10px_12px_2px_12px] rb:rounded-lg rb:max-w-130': item.role === 'user',
|
'rb:bg-[#E3EBFD] rb:p-[10px_12px_2px_12px] rb:rounded-lg rb:max-w-130': item.role === 'user',
|
||||||
'rb:max-w-full rb:w-full': item.role === 'assistant',
|
'rb:max-w-full rb:w-full': item.role === 'assistant',
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* @Author: ZhaoYing
|
* @Author: ZhaoYing
|
||||||
* @Date: 2026-02-03 16:27:39
|
* @Date: 2026-02-03 16:27:39
|
||||||
* @Last Modified by: ZhaoYing
|
* @Last Modified by: ZhaoYing
|
||||||
* @Last Modified time: 2026-03-31 15:02:07
|
* @Last Modified time: 2026-04-10 18:51:43
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Chat debugging component for application testing
|
* Chat debugging component for application testing
|
||||||
@@ -291,7 +291,6 @@ const Chat: FC<ChatProps> = ({
|
|||||||
addAssistantMessage()
|
addAssistantMessage()
|
||||||
|
|
||||||
const handleStreamMessage = (data: SSEMessage[]) => {
|
const handleStreamMessage = (data: SSEMessage[]) => {
|
||||||
setCompareLoading(false)
|
|
||||||
|
|
||||||
data.map(item => {
|
data.map(item => {
|
||||||
const { model_config_id, conversation_id, content, message_length, audio_url, citations } = item.data as {
|
const { model_config_id, conversation_id, content, message_length, audio_url, citations } = item.data as {
|
||||||
@@ -306,12 +305,21 @@ const Chat: FC<ChatProps> = ({
|
|||||||
|
|
||||||
switch (item.event) {
|
switch (item.event) {
|
||||||
case 'model_reasoning':
|
case 'model_reasoning':
|
||||||
|
if (compareLoading) {
|
||||||
|
setCompareLoading(false)
|
||||||
|
}
|
||||||
updateAssistantReasoningMessage(content, model_config_id, conversation_id)
|
updateAssistantReasoningMessage(content, model_config_id, conversation_id)
|
||||||
break;
|
break;
|
||||||
case 'model_message':
|
case 'model_message':
|
||||||
|
if (compareLoading) {
|
||||||
|
setCompareLoading(false)
|
||||||
|
}
|
||||||
updateAssistantMessage(content, model_config_id, conversation_id, audio_url)
|
updateAssistantMessage(content, model_config_id, conversation_id, audio_url)
|
||||||
break;
|
break;
|
||||||
case 'model_end':
|
case 'model_end':
|
||||||
|
if (compareLoading) {
|
||||||
|
setCompareLoading(false)
|
||||||
|
}
|
||||||
const idToPoll = `${model_config_id}_${audio_url}`
|
const idToPoll = `${model_config_id}_${audio_url}`
|
||||||
if (audio_url && !audioStatusMap[idToPoll]) {
|
if (audio_url && !audioStatusMap[idToPoll]) {
|
||||||
setAudioStatusMap(prev => ({
|
setAudioStatusMap(prev => ({
|
||||||
@@ -352,6 +360,9 @@ const Chat: FC<ChatProps> = ({
|
|||||||
updateErrorAssistantMessage(message_length, model_config_id)
|
updateErrorAssistantMessage(message_length, model_config_id)
|
||||||
break;
|
break;
|
||||||
case 'compare_end':
|
case 'compare_end':
|
||||||
|
if (compareLoading) {
|
||||||
|
setCompareLoading(false)
|
||||||
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -473,7 +484,6 @@ const Chat: FC<ChatProps> = ({
|
|||||||
addClusterAssistantMessage()
|
addClusterAssistantMessage()
|
||||||
|
|
||||||
const handleStreamMessage = (data: SSEMessage[]) => {
|
const handleStreamMessage = (data: SSEMessage[]) => {
|
||||||
setCompareLoading(false)
|
|
||||||
|
|
||||||
data.map(item => {
|
data.map(item => {
|
||||||
const { conversation_id, content, message_length } = item.data as { conversation_id: string, content: string, message_length: number };
|
const { conversation_id, content, message_length } = item.data as { conversation_id: string, content: string, message_length: number };
|
||||||
@@ -485,15 +495,24 @@ const Chat: FC<ChatProps> = ({
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'message':
|
case 'message':
|
||||||
|
if (compareLoading) {
|
||||||
|
setCompareLoading(false)
|
||||||
|
}
|
||||||
updateClusterAssistantMessage(content)
|
updateClusterAssistantMessage(content)
|
||||||
if (conversation_id && conversationId !== conversation_id) {
|
if (conversation_id && conversationId !== conversation_id) {
|
||||||
setConversationId(conversation_id);
|
setConversationId(conversation_id);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'model_end':
|
case 'model_end':
|
||||||
|
if (compareLoading) {
|
||||||
|
setCompareLoading(false)
|
||||||
|
}
|
||||||
updateClusterErrorAssistantMessage(message_length)
|
updateClusterErrorAssistantMessage(message_length)
|
||||||
break;
|
break;
|
||||||
case 'compare_end':
|
case 'compare_end':
|
||||||
|
if (compareLoading) {
|
||||||
|
setCompareLoading(false)
|
||||||
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user