Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 26a76b030d |
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)):
|
||||
"""获取会话消息"""
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user