docs: update README and CLAUDE.md to v2.2.0
- Added documentation for audit tracking (IP address, invocation method). - Updated database model descriptions for enhanced WorkOrder and Conversation fields. - Documented the new UnifiedConfig system. - Reflected enhanced logging transparency for knowledge base parsing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
BIN
src/dialogue/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
src/dialogue/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/dialogue/__pycache__/conversation_history.cpython-310.pyc
Normal file
BIN
src/dialogue/__pycache__/conversation_history.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/dialogue/__pycache__/dialogue_manager.cpython-310.pyc
Normal file
BIN
src/dialogue/__pycache__/dialogue_manager.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/dialogue/__pycache__/realtime_chat.cpython-310.pyc
Normal file
BIN
src/dialogue/__pycache__/realtime_chat.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
@@ -13,7 +13,7 @@ from sqlalchemy.orm import Session
|
||||
from ..core.database import db_manager
|
||||
from ..core.models import Conversation, WorkOrder, WorkOrderSuggestion, KnowledgeEntry
|
||||
from ..core.redis_manager import redis_manager
|
||||
from ..config.config import Config
|
||||
from src.config.unified_config import get_config
|
||||
from sqlalchemy import and_, or_, desc
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -43,11 +43,13 @@ class ConversationHistoryManager:
|
||||
work_order_id: Optional[int] = None,
|
||||
confidence_score: Optional[float] = None,
|
||||
response_time: Optional[float] = None,
|
||||
knowledge_used: Optional[List[int]] = None
|
||||
knowledge_used: Optional[List[int]] = None,
|
||||
ip_address: Optional[str] = None,
|
||||
invocation_method: Optional[str] = None
|
||||
) -> int:
|
||||
"""保存对话记录到数据库和Redis"""
|
||||
conversation_id = 0
|
||||
|
||||
|
||||
try:
|
||||
# 保存到数据库
|
||||
with db_manager.get_session() as session:
|
||||
@@ -58,12 +60,14 @@ class ConversationHistoryManager:
|
||||
confidence_score=confidence_score,
|
||||
response_time=response_time,
|
||||
knowledge_used=json.dumps(knowledge_used or [], ensure_ascii=False),
|
||||
ip_address=ip_address,
|
||||
invocation_method=invocation_method,
|
||||
timestamp=datetime.now()
|
||||
)
|
||||
session.add(conversation)
|
||||
session.commit()
|
||||
conversation_id = conversation.id
|
||||
|
||||
|
||||
# 保存到Redis缓存
|
||||
self._save_to_cache(
|
||||
user_id=user_id,
|
||||
@@ -72,7 +76,9 @@ class ConversationHistoryManager:
|
||||
assistant_response=assistant_response,
|
||||
conversation_id=conversation_id,
|
||||
confidence_score=confidence_score,
|
||||
response_time=response_time
|
||||
response_time=response_time,
|
||||
ip_address=ip_address,
|
||||
invocation_method=invocation_method
|
||||
)
|
||||
|
||||
logger.info(f"对话记录保存成功: ID={conversation_id}")
|
||||
@@ -90,16 +96,18 @@ class ConversationHistoryManager:
|
||||
assistant_response: str,
|
||||
conversation_id: int,
|
||||
confidence_score: Optional[float] = None,
|
||||
response_time: Optional[float] = None
|
||||
response_time: Optional[float] = None,
|
||||
ip_address: Optional[str] = None,
|
||||
invocation_method: Optional[str] = None
|
||||
):
|
||||
"""保存对话到Redis缓存"""
|
||||
redis_client = self._get_redis_client()
|
||||
if not redis_client:
|
||||
return
|
||||
|
||||
|
||||
try:
|
||||
cache_key = self._get_cache_key(user_id, work_order_id)
|
||||
|
||||
|
||||
# 构建对话记录
|
||||
conversation_record = {
|
||||
"id": conversation_id,
|
||||
@@ -107,7 +115,9 @@ class ConversationHistoryManager:
|
||||
"assistant_response": assistant_response,
|
||||
"timestamp": datetime.now().isoformat(),
|
||||
"confidence_score": confidence_score,
|
||||
"response_time": response_time
|
||||
"response_time": response_time,
|
||||
"ip_address": ip_address,
|
||||
"invocation_method": invocation_method
|
||||
}
|
||||
|
||||
# 添加到Redis列表
|
||||
@@ -205,6 +215,8 @@ class ConversationHistoryManager:
|
||||
"timestamp": conv.timestamp.isoformat(),
|
||||
"confidence_score": conv.confidence_score,
|
||||
"response_time": conv.response_time,
|
||||
"ip_address": conv.ip_address,
|
||||
"invocation_method": conv.invocation_method,
|
||||
"knowledge_used": json.loads(conv.knowledge_used) if conv.knowledge_used else []
|
||||
})
|
||||
|
||||
|
||||
@@ -58,15 +58,17 @@ class RealtimeChatManager:
|
||||
logger.info(f"创建新会话: {session_id}")
|
||||
return session_id
|
||||
|
||||
def process_message(self, session_id: str, user_message: str) -> Dict[str, Any]:
|
||||
def process_message(self, session_id: str, user_message: str, ip_address: str = None, invocation_method: str = "websocket") -> Dict[str, Any]:
|
||||
"""处理用户消息"""
|
||||
try:
|
||||
if session_id not in self.active_sessions:
|
||||
return {"error": "会话不存在"}
|
||||
|
||||
|
||||
session = self.active_sessions[session_id]
|
||||
session["last_activity"] = datetime.now()
|
||||
session["message_count"] += 1
|
||||
session["ip_address"] = ip_address
|
||||
session["invocation_method"] = invocation_method
|
||||
|
||||
# 创建用户消息
|
||||
user_msg = ChatMessage(
|
||||
@@ -140,7 +142,7 @@ class RealtimeChatManager:
|
||||
session["context"] = session["context"][-20:]
|
||||
|
||||
# 保存到数据库(每轮一条,带会话标记)
|
||||
self._save_conversation(session_id, user_msg, assistant_msg)
|
||||
self._save_conversation(session_id, user_msg, assistant_msg, ip_address, invocation_method)
|
||||
|
||||
# 更新知识库使用次数
|
||||
if knowledge_results:
|
||||
@@ -350,7 +352,7 @@ class RealtimeChatManager:
|
||||
|
||||
return base_confidence
|
||||
|
||||
def _save_conversation(self, session_id: str, user_msg: ChatMessage, assistant_msg: ChatMessage):
|
||||
def _save_conversation(self, session_id: str, user_msg: ChatMessage, assistant_msg: ChatMessage, ip_address: str = None, invocation_method: str = None):
|
||||
"""保存对话到数据库"""
|
||||
try:
|
||||
with db_manager.get_session() as session:
|
||||
@@ -377,7 +379,9 @@ class RealtimeChatManager:
|
||||
timestamp=assistant_msg.timestamp or user_msg.timestamp,
|
||||
confidence_score=assistant_msg.confidence_score,
|
||||
knowledge_used=json.dumps(marked_knowledge, ensure_ascii=False) if marked_knowledge else None,
|
||||
response_time=response_time
|
||||
response_time=response_time,
|
||||
ip_address=ip_address,
|
||||
invocation_method=invocation_method
|
||||
)
|
||||
session.add(conversation)
|
||||
session.commit()
|
||||
|
||||
Reference in New Issue
Block a user