Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 26a76b030d | |||
| daccc625c3 | |||
| a2a7fd46c3 | |||
| baf5913bfb | |||
| ae08e01e55 |
44
main_v2.py
44
main_v2.py
@@ -647,17 +647,19 @@ async def get_conversations(db: Session = Depends(get_db)):
|
||||
user = conv_service.get_or_create_user(MAIN_USER_ID, display_name="主用户", user_type='web')
|
||||
conversations = conv_service.get_user_conversations(user.id)
|
||||
|
||||
return {
|
||||
"conversations": [
|
||||
{
|
||||
"id": c.conversation_id,
|
||||
"title": c.title or "新对话",
|
||||
"created_at": c.created_at.isoformat(),
|
||||
"updated_at": c.updated_at.isoformat()
|
||||
}
|
||||
for c in conversations
|
||||
]
|
||||
}
|
||||
# 为每个对话计算消息数量
|
||||
result = []
|
||||
for c in conversations:
|
||||
msg_count = db.query(Message).filter(Message.conversation_id == c.id).count()
|
||||
result.append({
|
||||
"id": c.conversation_id,
|
||||
"title": c.title or "新对话",
|
||||
"created_at": c.created_at.isoformat(),
|
||||
"updated_at": c.updated_at.isoformat(),
|
||||
"message_count": msg_count
|
||||
})
|
||||
|
||||
return {"conversations": result}
|
||||
|
||||
|
||||
@app.get("/api/conversations/latest")
|
||||
@@ -693,6 +695,26 @@ async def create_conversation(db: Session = Depends(get_db)):
|
||||
}
|
||||
|
||||
|
||||
@app.get("/api/conversations/{conversation_id}")
|
||||
async def get_conversation(conversation_id: str, db: Session = Depends(get_db)):
|
||||
"""获取单个对话详情"""
|
||||
conv_service = ConversationService(db)
|
||||
conversation = conv_service.get_conversation(conversation_id)
|
||||
|
||||
if not conversation:
|
||||
raise HTTPException(status_code=404, detail="会话不存在")
|
||||
|
||||
msg_count = db.query(Message).filter(Message.conversation_id == conversation.id).count()
|
||||
|
||||
return {
|
||||
"id": conversation.conversation_id,
|
||||
"title": conversation.title or "新对话",
|
||||
"created_at": conversation.created_at.isoformat(),
|
||||
"updated_at": conversation.updated_at.isoformat(),
|
||||
"message_count": msg_count
|
||||
}
|
||||
|
||||
|
||||
@app.get("/api/conversations/{conversation_id}/messages")
|
||||
async def get_messages(conversation_id: str, db: Session = Depends(get_db)):
|
||||
"""获取会话消息"""
|
||||
|
||||
@@ -550,16 +550,6 @@ class LLMService:
|
||||
}
|
||||
|
||||
logger.info(f"工具结果返回LLM: url={url}, model={model}, 消息数={len(final_messages)}")
|
||||
# 打印消息内容(调试)
|
||||
for i, msg in enumerate(final_messages):
|
||||
role = msg.get('role')
|
||||
content_preview = str(msg.get('content', ''))[:100] if msg.get('content') else 'None'
|
||||
if role == 'tool':
|
||||
logger.info(f"消息[{i}] role={role}, tool_call_id={msg.get('tool_call_id')}, content长度={len(msg.get('content',''))}")
|
||||
elif role == 'assistant' and msg.get('tool_calls'):
|
||||
logger.info(f"消息[{i}] role={role}, tool_calls={len(msg['tool_calls'])}")
|
||||
else:
|
||||
logger.info(f"消息[{i}] role={role}, content={content_preview}...")
|
||||
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=60.0) as client:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user