|
@@ -1563,6 +1563,38 @@ def get_user_conversations(user_id: str):
|
|
try:
|
|
try:
|
|
limit = request.args.get('limit', USER_MAX_CONVERSATIONS, type=int)
|
|
limit = request.args.get('limit', USER_MAX_CONVERSATIONS, type=int)
|
|
conversations = redis_conversation_manager.get_conversations(user_id, limit)
|
|
conversations = redis_conversation_manager.get_conversations(user_id, limit)
|
|
|
|
+
|
|
|
|
+ # 为每个对话动态获取标题(第一条用户消息)
|
|
|
|
+ for conversation in conversations:
|
|
|
|
+ conversation_id = conversation['conversation_id']
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ # 获取所有消息,然后取第一条用户消息作为标题
|
|
|
|
+ messages = redis_conversation_manager.get_conversation_messages(conversation_id)
|
|
|
|
+
|
|
|
|
+ if messages and len(messages) > 0:
|
|
|
|
+ # 找到第一条用户消息(按时间顺序)
|
|
|
|
+ first_user_message = None
|
|
|
|
+ for message in messages:
|
|
|
|
+ if message.get('role') == 'user':
|
|
|
|
+ first_user_message = message
|
|
|
|
+ break
|
|
|
|
+
|
|
|
|
+ if first_user_message:
|
|
|
|
+ title = first_user_message.get('content', '对话').strip()
|
|
|
|
+ # 限制标题长度,保持整洁
|
|
|
|
+ if len(title) > 50:
|
|
|
|
+ conversation['conversation_title'] = title[:47] + "..."
|
|
|
|
+ else:
|
|
|
|
+ conversation['conversation_title'] = title
|
|
|
|
+ else:
|
|
|
|
+ conversation['conversation_title'] = "对话"
|
|
|
|
+ else:
|
|
|
|
+ conversation['conversation_title'] = "空对话"
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(f"[WARNING] 获取对话标题失败 {conversation_id}: {str(e)}")
|
|
|
|
+ conversation['conversation_title'] = "对话"
|
|
|
|
|
|
return jsonify(success_response(
|
|
return jsonify(success_response(
|
|
response_text="获取用户对话列表成功",
|
|
response_text="获取用户对话列表成功",
|
|
@@ -1606,7 +1638,7 @@ def get_conversation_context(conversation_id: str):
|
|
"""获取对话上下文(格式化用于LLM)"""
|
|
"""获取对话上下文(格式化用于LLM)"""
|
|
try:
|
|
try:
|
|
count = request.args.get('count', CONVERSATION_CONTEXT_COUNT, type=int)
|
|
count = request.args.get('count', CONVERSATION_CONTEXT_COUNT, type=int)
|
|
- context = redis_conversation_manager.get_context(conversation_id, count)
|
|
|
|
|
|
+ context = redis_conversation_manager.get_context_for_display(conversation_id, count)
|
|
|
|
|
|
return jsonify(success_response(
|
|
return jsonify(success_response(
|
|
response_text="获取对话上下文成功",
|
|
response_text="获取对话上下文成功",
|