diff --git a/src/config/api.js b/src/config/api.js index c8ec997..da05fe2 100644 --- a/src/config/api.js +++ b/src/config/api.js @@ -110,21 +110,36 @@ export const callLocalChatAPI = async (prompt, onStreamData) => { // 按行处理响应 const lines = responseText.split(/\r?\n/) + console.log('总行数:', lines.length) - for (const line of lines) { + for (let i = 0; i < lines.length; i++) { + const line = lines[i] + if (line.startsWith('event:')) { currentEvent = line.substring(6).trim() + console.log(`第${i}行 - 事件类型:`, currentEvent) } else if (line.startsWith('data:')) { const data = line.substring(5) + console.log(`第${i}行 - 数据类型:${currentEvent}, 数据长度:${data.length}, 数据内容:${data.substring(0, 50)}...`) if (currentEvent === 'thought') { thoughtContent += data } else if (currentEvent === 'message') { + // 累加所有 message 数据,而不是只处理第一个 messageContent += data + console.log(`messageContent 当前长度: ${messageContent.length}`) } } } + // 调试:打印解析结果 + console.log('解析结果:', { + thoughtLength: thoughtContent.length, + messageLength: messageContent.length, + thought: thoughtContent.substring(0, 100) + '...', + message: messageContent.substring(0, 100) + '...' + }) + // 返回最终结果 console.log('API returning:3333', { thought: thoughtContent, message: messageContent }) // 调试信息 diff --git a/src/pages/chatConversation/ChatConversation.js b/src/pages/chatConversation/ChatConversation.js index 49bf2b8..4d8ef1b 100644 --- a/src/pages/chatConversation/ChatConversation.js +++ b/src/pages/chatConversation/ChatConversation.js @@ -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) {/* 回答框 */}
{displayContent ? ( - - {displayContent} - +
+ {deepThinkingEnabled && displayContent.includes('\n\n') ? ( + // 当开启深度思考且有思考内容时,分别渲染 + (() => { + const parts = displayContent.split('\n\n') + const thought = parts[0] + const message = parts.slice(1).join('\n\n') + + return ( + <> + {/* 思考过程 */} +
+ 思考过程: + {children}, + strong: ({children}) => {children}, + em: ({children}) => {children}, + code: ({children}) => {children}, + pre: ({children}) =>
{children}
+ }} + > + {thought} +
+
+ + {/* 正式回答 */} + {message && ( +
+ {/* 回答: */} + + {message} + +
+ )} + + ) + })() + ) : ( + // 普通渲染 + + {displayContent} + + )} +
) : (
暂无内容 diff --git a/src/utils/pageConversationStore.js b/src/utils/pageConversationStore.js index ff511df..554f227 100644 --- a/src/utils/pageConversationStore.js +++ b/src/utils/pageConversationStore.js @@ -126,15 +126,21 @@ class PageConversationStore { // 更新指定消息的内容 updateMessage(messageId, newContent) { + console.log('updateMessage 调用:', { messageId, newContent: newContent.substring(0, 50) + '...', length: newContent.length }) const currentConversation = this.getCurrentConversation() if (currentConversation) { const message = currentConversation.messages.find(msg => msg.id === messageId) if (message) { + console.log('找到消息,更新内容:', { oldContent: message.content.substring(0, 50) + '...', newContent: newContent.substring(0, 50) + '...' }) message.content = newContent currentConversation.lastUpdate = new Date() this.saveToStorage() this.notifySubscribers() + } else { + console.log('未找到消息:', messageId) } + } else { + console.log('未找到当前对话') } }