From cdcd3374ade7f86012801c7e02f65e98891aa08d Mon Sep 17 00:00:00 2001 From: susie-laptop Date: Wed, 2 Apr 2025 21:26:54 -0400 Subject: [PATCH] [dev]edited chat --- src/icons/icons.js | 2 + src/pages/Chat/ChatWindow.jsx | 18 +- src/pages/Chat/NewChat.jsx | 48 +++- .../components/KnowledgeCard.jsx | 5 +- src/services/api.js | 89 ++++++- src/store/chat/chat.slice.js | 99 ++++---- src/store/chat/chat.thunks.js | 233 ++++++++++++++++-- src/styles/style.scss | 39 +++ 8 files changed, 435 insertions(+), 98 deletions(-) diff --git a/src/icons/icons.js b/src/icons/icons.js index 364ba22..fa296b6 100644 --- a/src/icons/icons.js +++ b/src/icons/icons.js @@ -120,4 +120,6 @@ export const icons = { plus: ` `, + building: ``, + group:`` }; diff --git a/src/pages/Chat/ChatWindow.jsx b/src/pages/Chat/ChatWindow.jsx index a2ecbff..fe1782c 100644 --- a/src/pages/Chat/ChatWindow.jsx +++ b/src/pages/Chat/ChatWindow.jsx @@ -254,24 +254,22 @@ export default function ChatWindow({ chatId, knowledgeBaseId }) { ) : ( )} + {message.is_streaming && ( + + + + + + )}
{message.created_at && new Date(message.created_at).toLocaleTimeString()} + {message.is_streaming && ' · 正在生成...'}
))} - {sendStatus === 'loading' && ( -
-
-
- 加载中... -
-
-
- )} -
diff --git a/src/pages/Chat/NewChat.jsx b/src/pages/Chat/NewChat.jsx index 08d76dd..69ede59 100644 --- a/src/pages/Chat/NewChat.jsx +++ b/src/pages/Chat/NewChat.jsx @@ -74,6 +74,9 @@ export default function NewChat() { try { setIsNavigating(true); + // 打印调试信息 + console.log('选中的知识库ID:', selectedDatasetIds); + // 检查是否已存在包含所有选中知识库的聊天记录 // 注意:这里的逻辑简化了,实际可能需要更复杂的匹配算法 const existingChat = chatHistory.find((chat) => { @@ -110,30 +113,49 @@ export default function NewChat() { // 创建新的聊天记录 const formattedIds = selectedDatasetIds.map((id) => id.replace(/-/g, '')); - const response = await dispatch( - createChatRecord({ - dataset_id_list: formattedIds, - question: '选择当前知识库,创建聊天', - }) - ).unwrap(); + console.log('格式化后的知识库ID:', formattedIds); - if (response && response.conversation_id) { - // 使用第一个知识库ID作为URL参数 - const primaryDatasetId = selectedDatasetIds[0]; - console.log(`创建成功,导航到 /chat/${primaryDatasetId}/${response.conversation_id}`); - navigate(`/chat/${primaryDatasetId}/${response.conversation_id}`); - } else { - throw new Error('未能获取会话ID'); + try { + // 尝试创建聊天记录 + const response = await dispatch( + createChatRecord({ + dataset_id_list: formattedIds, + question: '选择当前知识库,创建聊天', + }) + ).unwrap(); + + console.log('创建聊天响应:', response); + + if (response && response.conversation_id) { + // 使用第一个知识库ID作为URL参数 + const primaryDatasetId = selectedDatasetIds[0]; + console.log(`创建成功,导航到 /chat/${primaryDatasetId}/${response.conversation_id}`); + navigate(`/chat/${primaryDatasetId}/${response.conversation_id}`); + } else { + throw new Error('未能获取会话ID:' + JSON.stringify(response)); + } + } catch (apiError) { + // 专门处理API调用错误 + console.error('API调用失败:', apiError); + throw new Error(`API调用失败: ${apiError.message || '未知错误'}`); } } } catch (error) { console.error('导航或创建聊天失败:', error); + + // 添加更详细的错误日志 + if (error.stack) { + console.error('错误堆栈:', error.stack); + } + + // 显示更友好的错误消息 dispatch( showNotification({ message: `创建聊天失败: ${error.message || '请重试'}`, type: 'danger', }) ); + } finally { setIsNavigating(false); } }; diff --git a/src/pages/KnowledgeBase/components/KnowledgeCard.jsx b/src/pages/KnowledgeBase/components/KnowledgeCard.jsx index 8fe7ed2..9649023 100644 --- a/src/pages/KnowledgeBase/components/KnowledgeCard.jsx +++ b/src/pages/KnowledgeBase/components/KnowledgeCard.jsx @@ -58,6 +58,9 @@ export default function KnowledgeCard({ )} +
+ {department || ''} {group || 'N/A'} +

{description}

@@ -95,6 +98,7 @@ export default function KnowledgeCard({ )} {access === 'full' || access === 'read' ? ( <> + ) : ( // - ) : (