|
@@ -108,7 +108,7 @@ async def send_deepseek_message(
|
|
|
# 创建或获取对话
|
|
# 创建或获取对话
|
|
|
if not data.conversation_id:
|
|
if not data.conversation_id:
|
|
|
conversation = AIConversation(
|
|
conversation = AIConversation(
|
|
|
- user_id=user.user_id,
|
|
|
|
|
|
|
+ user_id=user.userCode,
|
|
|
content=message[:100],
|
|
content=message[:100],
|
|
|
business_type=data.business_type,
|
|
business_type=data.business_type,
|
|
|
exam_name=data.exam_name if data.business_type == 3 else "",
|
|
exam_name=data.exam_name if data.business_type == 3 else "",
|
|
@@ -241,7 +241,7 @@ async def send_deepseek_message(
|
|
|
"data": {
|
|
"data": {
|
|
|
"conversation_id": conv_id,
|
|
"conversation_id": conv_id,
|
|
|
"response": response_text,
|
|
"response": response_text,
|
|
|
- "user_id": user.user_id,
|
|
|
|
|
|
|
+ "user_id": user.userCode,
|
|
|
"business_type": data.business_type,
|
|
"business_type": data.business_type,
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
@@ -259,7 +259,7 @@ async def get_history_record(request: Request, db: Session = Depends(get_db)):
|
|
|
conversations = (
|
|
conversations = (
|
|
|
db.query(AIConversation)
|
|
db.query(AIConversation)
|
|
|
.filter(
|
|
.filter(
|
|
|
- AIConversation.user_id == user.user_id,
|
|
|
|
|
|
|
+ AIConversation.user_id == user.userCode,
|
|
|
AIConversation.is_deleted == 0,
|
|
AIConversation.is_deleted == 0,
|
|
|
)
|
|
)
|
|
|
.order_by(AIConversation.created_at.desc())
|
|
.order_by(AIConversation.created_at.desc())
|
|
@@ -301,7 +301,7 @@ async def delete_conversation(
|
|
|
|
|
|
|
|
db.query(AIConversation).filter(
|
|
db.query(AIConversation).filter(
|
|
|
AIConversation.id == data.ai_conversation_id,
|
|
AIConversation.id == data.ai_conversation_id,
|
|
|
- AIConversation.user_id == user.user_id,
|
|
|
|
|
|
|
+ AIConversation.user_id == user.userCode,
|
|
|
).update({"is_deleted": 1, "updated_at": int(time.time())})
|
|
).update({"is_deleted": 1, "updated_at": int(time.time())})
|
|
|
|
|
|
|
|
db.query(AIMessage).filter(
|
|
db.query(AIMessage).filter(
|
|
@@ -326,7 +326,7 @@ async def delete_history_record(
|
|
|
return {"statusCode": 401, "msg": "未授权"}
|
|
return {"statusCode": 401, "msg": "未授权"}
|
|
|
db.query(AIConversation).filter(
|
|
db.query(AIConversation).filter(
|
|
|
AIConversation.id == data.ai_conversation_id,
|
|
AIConversation.id == data.ai_conversation_id,
|
|
|
- AIConversation.user_id == user.user_id,
|
|
|
|
|
|
|
+ AIConversation.user_id == user.userCode,
|
|
|
).update({"is_deleted": 1, "updated_at": int(time.time())})
|
|
).update({"is_deleted": 1, "updated_at": int(time.time())})
|
|
|
db.commit()
|
|
db.commit()
|
|
|
return {"statusCode": 200, "msg": "删除成功"}
|
|
return {"statusCode": 200, "msg": "删除成功"}
|
|
@@ -426,7 +426,7 @@ async def stream_chat_with_db(request: Request, data: StreamChatWithDBRequest):
|
|
|
# 1. 创建或获取对话
|
|
# 1. 创建或获取对话
|
|
|
if data.ai_conversation_id == 0:
|
|
if data.ai_conversation_id == 0:
|
|
|
conversation = AIConversation(
|
|
conversation = AIConversation(
|
|
|
- user_id=user.user_id,
|
|
|
|
|
|
|
+ user_id=user.userCode,
|
|
|
content=message[:100],
|
|
content=message[:100],
|
|
|
business_type=data.business_type,
|
|
business_type=data.business_type,
|
|
|
exam_name=data.exam_name,
|
|
exam_name=data.exam_name,
|
|
@@ -444,7 +444,7 @@ async def stream_chat_with_db(request: Request, data: StreamChatWithDBRequest):
|
|
|
# 2. 插入用户消息
|
|
# 2. 插入用户消息
|
|
|
user_msg = AIMessage(
|
|
user_msg = AIMessage(
|
|
|
ai_conversation_id=conv_id,
|
|
ai_conversation_id=conv_id,
|
|
|
- user_id=user.user_id,
|
|
|
|
|
|
|
+ user_id=user.userCode,
|
|
|
type="user",
|
|
type="user",
|
|
|
content=message,
|
|
content=message,
|
|
|
created_at=int(time.time()),
|
|
created_at=int(time.time()),
|
|
@@ -458,7 +458,7 @@ async def stream_chat_with_db(request: Request, data: StreamChatWithDBRequest):
|
|
|
# 3. 插入 AI 占位消息
|
|
# 3. 插入 AI 占位消息
|
|
|
ai_msg = AIMessage(
|
|
ai_msg = AIMessage(
|
|
|
ai_conversation_id=conv_id,
|
|
ai_conversation_id=conv_id,
|
|
|
- user_id=user.user_id,
|
|
|
|
|
|
|
+ user_id=user.userCode,
|
|
|
type="ai",
|
|
type="ai",
|
|
|
content="",
|
|
content="",
|
|
|
prev_user_id=user_msg.id,
|
|
prev_user_id=user_msg.id,
|
|
@@ -661,7 +661,7 @@ async def online_search(question: str, request: Request, db: Session = Depends(g
|
|
|
"max_text_len": 4000 # 最大文本长度
|
|
"max_text_len": 4000 # 最大文本长度
|
|
|
},
|
|
},
|
|
|
"response_mode": "blocking",
|
|
"response_mode": "blocking",
|
|
|
- "user": getattr(user, "account", str(user.user_id)),
|
|
|
|
|
|
|
+ "user": getattr(user, "account", str(user.userCode)),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async with httpx.AsyncClient(timeout=30.0) as client:
|
|
async with httpx.AsyncClient(timeout=30.0) as client:
|
|
@@ -744,7 +744,7 @@ async def intent_recognition(
|
|
|
if data.save_to_db and intent_type in ("greeting", "问候", "faq", "常见问题"):
|
|
if data.save_to_db and intent_type in ("greeting", "问候", "faq", "常见问题"):
|
|
|
if data.ai_conversation_id == 0:
|
|
if data.ai_conversation_id == 0:
|
|
|
conversation = AIConversation(
|
|
conversation = AIConversation(
|
|
|
- user_id=user.user_id,
|
|
|
|
|
|
|
+ user_id=user.userCode,
|
|
|
content=data.message[:100],
|
|
content=data.message[:100],
|
|
|
business_type=0,
|
|
business_type=0,
|
|
|
created_at=int(time.time()),
|
|
created_at=int(time.time()),
|
|
@@ -760,7 +760,7 @@ async def intent_recognition(
|
|
|
|
|
|
|
|
user_msg = AIMessage(
|
|
user_msg = AIMessage(
|
|
|
ai_conversation_id=conv_id,
|
|
ai_conversation_id=conv_id,
|
|
|
- user_id=user.user_id,
|
|
|
|
|
|
|
+ user_id=user.userCode,
|
|
|
type="user",
|
|
type="user",
|
|
|
content=data.message,
|
|
content=data.message,
|
|
|
created_at=int(time.time()),
|
|
created_at=int(time.time()),
|
|
@@ -772,7 +772,7 @@ async def intent_recognition(
|
|
|
|
|
|
|
|
ai_msg = AIMessage(
|
|
ai_msg = AIMessage(
|
|
|
ai_conversation_id=conv_id,
|
|
ai_conversation_id=conv_id,
|
|
|
- user_id=user.user_id,
|
|
|
|
|
|
|
+ user_id=user.userCode,
|
|
|
type="ai",
|
|
type="ai",
|
|
|
content=response_text,
|
|
content=response_text,
|
|
|
prev_user_id=user_msg.id,
|
|
prev_user_id=user_msg.id,
|