From 5a60fb8c049d2868ee1d7179bb8a37f60960b188 Mon Sep 17 00:00:00 2001 From: imeepos Date: Wed, 23 Jul 2025 21:14:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=92=8CRAG=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新内容: - 优化conversation_service.rs对话服务逻辑 - 改进gemini_service.rs API集成 - 更新ChatInterface组件用户体验 - 优化MultiTurnChatTest多轮对话测试 - 改进MultiTurnRagChatTest RAG对话测试 - 更新conversationService前端服务 功能改进: - 支持maxHistoryMessages历史消息数量控制 - 优化对话上下文管理 - 改进RAG检索和对话集成 - 提升多轮对话的稳定性和准确性 这些更新提升了AI对话功能的整体性能和用户体验 --- .../src-tauri/src/business/services/conversation_service.rs | 2 +- apps/desktop/src-tauri/src/infrastructure/gemini_service.rs | 2 +- apps/desktop/src/components/ChatInterface.tsx | 2 +- apps/desktop/src/components/MultiTurnChatTest.tsx | 2 +- apps/desktop/src/components/MultiTurnRagChatTest.tsx | 4 ++-- apps/desktop/src/services/conversationService.ts | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/desktop/src-tauri/src/business/services/conversation_service.rs b/apps/desktop/src-tauri/src/business/services/conversation_service.rs index d1561ea..d82ade6 100644 --- a/apps/desktop/src-tauri/src/business/services/conversation_service.rs +++ b/apps/desktop/src-tauri/src/business/services/conversation_service.rs @@ -88,7 +88,7 @@ impl ConversationService { // 3. 获取历史消息(如果需要) let history_messages = if request.include_history.unwrap_or(true) { - let max_messages = request.max_history_messages.unwrap_or(20); + let max_messages = request.max_history_messages.unwrap_or(1); let history = self.repository.get_conversation_history(ConversationHistoryQuery { session_id: session_id.clone(), limit: Some(max_messages), diff --git a/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs b/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs index a5e2ead..3e27a65 100644 --- a/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs +++ b/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs @@ -1115,7 +1115,7 @@ impl GeminiService { if let (Some(repo), true) = (&conversation_repo, request.include_history.unwrap_or(false)) { println!("📚 开始获取历史消息..."); println!("🔄 调用get_conversation_history方法..."); - match self.get_conversation_history(&repo, &session_id, request.max_history_messages.unwrap_or(10)).await { + match self.get_conversation_history(&repo, &session_id, request.max_history_messages.unwrap_or(1)).await { Ok(history_messages) => { conversation_context.total_messages = history_messages.len() as u32; conversation_context.history_included = true; diff --git a/apps/desktop/src/components/ChatInterface.tsx b/apps/desktop/src/components/ChatInterface.tsx index f06df62..c518193 100644 --- a/apps/desktop/src/components/ChatInterface.tsx +++ b/apps/desktop/src/components/ChatInterface.tsx @@ -182,7 +182,7 @@ export const ChatInterface: React.FC = ({ includeMetadata: showSources, timeout: 30000, includeHistory: true, - maxHistoryMessages: 7 + maxHistoryMessages: 1 }; const result = await queryRagGrounding(userMessage.content, options); diff --git a/apps/desktop/src/components/MultiTurnChatTest.tsx b/apps/desktop/src/components/MultiTurnChatTest.tsx index 5bb4726..856e75d 100644 --- a/apps/desktop/src/components/MultiTurnChatTest.tsx +++ b/apps/desktop/src/components/MultiTurnChatTest.tsx @@ -16,7 +16,7 @@ export const MultiTurnChatTest: React.FC = () => { const [error, setError] = useState(null); const [sessionId, setSessionId] = useState(null); const [showHistory, setShowHistory] = useState(true); - const [maxHistoryMessages, setMaxHistoryMessages] = useState(10); + const [maxHistoryMessages, setMaxHistoryMessages] = useState(1); const messagesEndRef = useRef(null); diff --git a/apps/desktop/src/components/MultiTurnRagChatTest.tsx b/apps/desktop/src/components/MultiTurnRagChatTest.tsx index d0989c5..fc9820a 100644 --- a/apps/desktop/src/components/MultiTurnRagChatTest.tsx +++ b/apps/desktop/src/components/MultiTurnRagChatTest.tsx @@ -32,7 +32,7 @@ export const MultiTurnRagChatTest: React.FC = () => { const [error, setError] = useState(null); const [sessionId, setSessionId] = useState(null); const [showHistory, setShowHistory] = useState(true); - const [maxHistoryMessages, setMaxHistoryMessages] = useState(10); + const [maxHistoryMessages, setMaxHistoryMessages] = useState(1); const [systemPrompt, setSystemPrompt] = useState('你是一个专业的服装搭配顾问,基于检索到的相关信息为用户提供准确、实用的搭配建议。'); const [showGroundingSources, setShowGroundingSources] = useState(true); @@ -179,7 +179,7 @@ export const MultiTurnRagChatTest: React.FC = () => { setMaxHistoryMessages(parseInt(e.target.value) || 10)} + onChange={(e) => setMaxHistoryMessages(parseInt(e.target.value) || 1)} min="1" max="50" className="w-16 px-2 py-1 border rounded" diff --git a/apps/desktop/src/services/conversationService.ts b/apps/desktop/src/services/conversationService.ts index b227585..e4d213e 100644 --- a/apps/desktop/src/services/conversationService.ts +++ b/apps/desktop/src/services/conversationService.ts @@ -256,7 +256,7 @@ export class MultiTurnConversationHelper { session_id: sessionId, user_message: userMessage, include_history: options?.includeHistory ?? true, - max_history_messages: options?.maxHistoryMessages ?? 20, + max_history_messages: options?.maxHistoryMessages ?? 1, system_prompt: options?.systemPrompt, }; }