|
|
|
|
@ -136,8 +136,10 @@ const [currentStreamingMessageId, setCurrentStreamingMessageId] = useState(null)
|
|
|
|
|
|
|
|
|
|
// 模拟流式效果
|
|
|
|
|
const simulateStreamingEffect = (fullContent, messageId) => {
|
|
|
|
|
console.log('开始流式效果:', { fullContent: fullContent.substring(0, 100) + '...', messageId, length: fullContent.length })
|
|
|
|
|
setIsStreaming(true)
|
|
|
|
|
setStreamingContent('')
|
|
|
|
|
setCurrentStreamingMessageId(messageId)
|
|
|
|
|
|
|
|
|
|
let currentIndex = 0
|
|
|
|
|
const chunkSize = 3 // 每次显示3个字符
|
|
|
|
|
@ -148,6 +150,8 @@ const [currentStreamingMessageId, setCurrentStreamingMessageId] = useState(null)
|
|
|
|
|
const nextIndex = Math.min(currentIndex + chunkSize, fullContent.length)
|
|
|
|
|
const currentContent = fullContent.substring(0, nextIndex)
|
|
|
|
|
|
|
|
|
|
console.log('流式进度:', { currentIndex, nextIndex, currentContent: currentContent.substring(0, 50) + '...' })
|
|
|
|
|
|
|
|
|
|
setStreamingContent(currentContent)
|
|
|
|
|
conversationStore.updateMessage(messageId, currentContent)
|
|
|
|
|
|
|
|
|
|
@ -155,6 +159,7 @@ const [currentStreamingMessageId, setCurrentStreamingMessageId] = useState(null)
|
|
|
|
|
setTimeout(streamNext, delay)
|
|
|
|
|
} else {
|
|
|
|
|
// 流式效果完成
|
|
|
|
|
console.log('流式效果完成')
|
|
|
|
|
setIsStreaming(false)
|
|
|
|
|
setStreamingContent('')
|
|
|
|
|
setCurrentStreamingMessageId(null)
|
|
|
|
|
@ -394,11 +399,67 @@ const [currentStreamingMessageId, setCurrentStreamingMessageId] = useState(null)
|
|
|
|
|
{/* 回答框 */}
|
|
|
|
|
<div className='ds-message-content'>
|
|
|
|
|
{displayContent ? (
|
|
|
|
|
<ReactMarkdown
|
|
|
|
|
remarkPlugins={[remarkGfm]}
|
|
|
|
|
>
|
|
|
|
|
{displayContent}
|
|
|
|
|
</ReactMarkdown>
|
|
|
|
|
<div>
|
|
|
|
|
{deepThinkingEnabled && displayContent.includes('\n\n') ? (
|
|
|
|
|
// 当开启深度思考且有思考内容时,分别渲染
|
|
|
|
|
(() => {
|
|
|
|
|
const parts = displayContent.split('\n\n')
|
|
|
|
|
const thought = parts[0]
|
|
|
|
|
const message = parts.slice(1).join('\n\n')
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{/* 思考过程 */}
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
fontSize: '14px',
|
|
|
|
|
color: '#666',
|
|
|
|
|
padding: '5px',
|
|
|
|
|
backgroundColor: '#f5f5f5',
|
|
|
|
|
borderRadius: '4px',
|
|
|
|
|
marginBottom: '10px',
|
|
|
|
|
// fontStyle: 'italic',
|
|
|
|
|
borderLeft: '3px solid #d9d9d9'
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<strong>思考过程:</strong>
|
|
|
|
|
<ReactMarkdown
|
|
|
|
|
remarkPlugins={[remarkGfm]}
|
|
|
|
|
components={{
|
|
|
|
|
p: ({children}) => <span style={{fontSize: '14px'}}>{children}</span>,
|
|
|
|
|
strong: ({children}) => <strong style={{fontSize: '14px'}}>{children}</strong>,
|
|
|
|
|
em: ({children}) => <em style={{fontSize: '14px'}}>{children}</em>,
|
|
|
|
|
code: ({children}) => <code style={{fontSize: '14px'}}>{children}</code>,
|
|
|
|
|
pre: ({children}) => <pre style={{fontSize: '14px'}}>{children}</pre>
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{thought}
|
|
|
|
|
</ReactMarkdown>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* 正式回答 */}
|
|
|
|
|
{message && (
|
|
|
|
|
<div>
|
|
|
|
|
{/* <strong style={{fontSize: '12px', color: '#333', marginBottom: '4px', display: 'block'}}>回答:</strong> */}
|
|
|
|
|
<ReactMarkdown
|
|
|
|
|
remarkPlugins={[remarkGfm]}
|
|
|
|
|
>
|
|
|
|
|
{message}
|
|
|
|
|
</ReactMarkdown>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
})()
|
|
|
|
|
) : (
|
|
|
|
|
// 普通渲染
|
|
|
|
|
<ReactMarkdown
|
|
|
|
|
remarkPlugins={[remarkGfm]}
|
|
|
|
|
>
|
|
|
|
|
{displayContent}
|
|
|
|
|
</ReactMarkdown>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div style={{ color: '#999', fontStyle: 'italic' }}>
|
|
|
|
|
暂无内容
|
|
|
|
|
|