feat: 优化对话服务和RAG功能
更新内容: - 优化conversation_service.rs对话服务逻辑 - 改进gemini_service.rs API集成 - 更新ChatInterface组件用户体验 - 优化MultiTurnChatTest多轮对话测试 - 改进MultiTurnRagChatTest RAG对话测试 - 更新conversationService前端服务 功能改进: - 支持maxHistoryMessages历史消息数量控制 - 优化对话上下文管理 - 改进RAG检索和对话集成 - 提升多轮对话的稳定性和准确性 这些更新提升了AI对话功能的整体性能和用户体验
This commit is contained in:
parent
63014471b4
commit
5a60fb8c04
|
|
@ -88,7 +88,7 @@ impl ConversationService {
|
||||||
|
|
||||||
// 3. 获取历史消息(如果需要)
|
// 3. 获取历史消息(如果需要)
|
||||||
let history_messages = if request.include_history.unwrap_or(true) {
|
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 {
|
let history = self.repository.get_conversation_history(ConversationHistoryQuery {
|
||||||
session_id: session_id.clone(),
|
session_id: session_id.clone(),
|
||||||
limit: Some(max_messages),
|
limit: Some(max_messages),
|
||||||
|
|
|
||||||
|
|
@ -1115,7 +1115,7 @@ impl GeminiService {
|
||||||
if let (Some(repo), true) = (&conversation_repo, request.include_history.unwrap_or(false)) {
|
if let (Some(repo), true) = (&conversation_repo, request.include_history.unwrap_or(false)) {
|
||||||
println!("📚 开始获取历史消息...");
|
println!("📚 开始获取历史消息...");
|
||||||
println!("🔄 调用get_conversation_history方法...");
|
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) => {
|
Ok(history_messages) => {
|
||||||
conversation_context.total_messages = history_messages.len() as u32;
|
conversation_context.total_messages = history_messages.len() as u32;
|
||||||
conversation_context.history_included = true;
|
conversation_context.history_included = true;
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,7 @@ export const ChatInterface: React.FC<ChatInterfaceProps> = ({
|
||||||
includeMetadata: showSources,
|
includeMetadata: showSources,
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
includeHistory: true,
|
includeHistory: true,
|
||||||
maxHistoryMessages: 7
|
maxHistoryMessages: 1
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await queryRagGrounding(userMessage.content, options);
|
const result = await queryRagGrounding(userMessage.content, options);
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ export const MultiTurnChatTest: React.FC = () => {
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [sessionId, setSessionId] = useState<string | null>(null);
|
const [sessionId, setSessionId] = useState<string | null>(null);
|
||||||
const [showHistory, setShowHistory] = useState(true);
|
const [showHistory, setShowHistory] = useState(true);
|
||||||
const [maxHistoryMessages, setMaxHistoryMessages] = useState(10);
|
const [maxHistoryMessages, setMaxHistoryMessages] = useState(1);
|
||||||
|
|
||||||
const messagesEndRef = useRef<HTMLDivElement>(null);
|
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ export const MultiTurnRagChatTest: React.FC = () => {
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [sessionId, setSessionId] = useState<string | null>(null);
|
const [sessionId, setSessionId] = useState<string | null>(null);
|
||||||
const [showHistory, setShowHistory] = useState(true);
|
const [showHistory, setShowHistory] = useState(true);
|
||||||
const [maxHistoryMessages, setMaxHistoryMessages] = useState(10);
|
const [maxHistoryMessages, setMaxHistoryMessages] = useState(1);
|
||||||
const [systemPrompt, setSystemPrompt] = useState('你是一个专业的服装搭配顾问,基于检索到的相关信息为用户提供准确、实用的搭配建议。');
|
const [systemPrompt, setSystemPrompt] = useState('你是一个专业的服装搭配顾问,基于检索到的相关信息为用户提供准确、实用的搭配建议。');
|
||||||
const [showGroundingSources, setShowGroundingSources] = useState(true);
|
const [showGroundingSources, setShowGroundingSources] = useState(true);
|
||||||
|
|
||||||
|
|
@ -179,7 +179,7 @@ export const MultiTurnRagChatTest: React.FC = () => {
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
value={maxHistoryMessages}
|
value={maxHistoryMessages}
|
||||||
onChange={(e) => setMaxHistoryMessages(parseInt(e.target.value) || 10)}
|
onChange={(e) => setMaxHistoryMessages(parseInt(e.target.value) || 1)}
|
||||||
min="1"
|
min="1"
|
||||||
max="50"
|
max="50"
|
||||||
className="w-16 px-2 py-1 border rounded"
|
className="w-16 px-2 py-1 border rounded"
|
||||||
|
|
|
||||||
|
|
@ -256,7 +256,7 @@ export class MultiTurnConversationHelper {
|
||||||
session_id: sessionId,
|
session_id: sessionId,
|
||||||
user_message: userMessage,
|
user_message: userMessage,
|
||||||
include_history: options?.includeHistory ?? true,
|
include_history: options?.includeHistory ?? true,
|
||||||
max_history_messages: options?.maxHistoryMessages ?? 20,
|
max_history_messages: options?.maxHistoryMessages ?? 1,
|
||||||
system_prompt: options?.systemPrompt,
|
system_prompt: options?.systemPrompt,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue