learn progress

This commit is contained in:
CakeCN
2025-12-09 22:56:51 +08:00
parent 15cbeb93ee
commit 4d5a8bb23f
3 changed files with 90 additions and 10 deletions

View File

@@ -100,7 +100,7 @@ def get_multiagents_dialog_list(user_id: str) -> List[Dict]:
current_app.logger.error(f"获取MultiAgents对话列表异常: {str(e)}")
return []
def load_learning_progress(user_id: str, material_id: str, chapter_name: str, lesson_name: str) -> Optional[Dict]:
def load_learning_progress(user_id: str, material_id: str, chapter_name: str, lesson_name: str) -> Dict:
"""
加载用户学习进度
@@ -111,7 +111,10 @@ def load_learning_progress(user_id: str, material_id: str, chapter_name: str, le
- lesson_name: 课时名
返回:
- Optional[Dict]: 学习进度数据,如果不存在则返回None
- Dict: 学习进度数据,包含以下字段:
- exists: bool表示学习记录是否存在
- data: Dict学习进度详细数据包含chat_historys、scores、chapter_chain_now等字段
- message: str操作结果描述
"""
try:
mongo = current_app.extensions["mongo"]
@@ -126,11 +129,44 @@ def load_learning_progress(user_id: str, material_id: str, chapter_name: str, le
# 转换ObjectId为字符串
if "_id" in progress:
progress["_id"] = str(progress["_id"])
return progress
return None
return {
"exists": True,
"data": progress,
"message": "学习记录加载成功"
}
# 返回默认值,确保即使没有学习记录也有完整的结构
return {
"exists": False,
"data": {
"user_id": user_id,
"material_id": material_id,
"chapter_name": chapter_name,
"lesson_name": lesson_name,
"chat_historys": [],
"scores": [],
"chapter_chain_now": None,
"updated_at": datetime.now().isoformat()
},
"message": "未找到学习记录,返回默认值"
}
except Exception as e:
current_app.logger.error(f"加载学习进度失败: {str(e)}")
return None
error_msg = f"加载学习进度失败: {str(e)}"
current_app.logger.error(error_msg)
# 发生错误时返回默认结构,确保系统稳定性
return {
"exists": False,
"data": {
"user_id": user_id,
"material_id": material_id,
"chapter_name": chapter_name,
"lesson_name": lesson_name,
"chat_historys": [],
"scores": [],
"chapter_chain_now": None,
"updated_at": datetime.now().isoformat()
},
"message": error_msg
}
def upload_learning_progress_to_cloud(progress: Dict) -> Dict:

View File

@@ -86,10 +86,11 @@ class AgentNamespace(Namespace):
chatmanager.function_manager.add_function(next_chapter, {'user_uuid': user_uuid})
if not chatmanager.restart:# 尝试加载用户学习进度
progress = load_learning_progress(user_id, course_id, chapter_name, lesson_name)
progress_result = load_learning_progress(user_id, course_id, chapter_name, lesson_name)
need_skip_chapters = 0
if progress:
if progress_result['exists']:
progress = progress_result['data']
# 恢复学习进度数据
if 'scores' in progress:
# 根据scores的数量确定需要跳过的章节数
@@ -108,8 +109,10 @@ class AgentNamespace(Namespace):
chatmanager.chapter_chain_now = progress['chapter_chain_now']
upload_learning_progress_to_cloud(progress)
else:
chatmanager.chat_historys = []
chatmanager.scores = []
# 使用默认值,确保有完整的结构
chatmanager.chat_historys = progress_result['data']['chat_historys']
chatmanager.scores = progress_result['data']['scores']
print(f"未找到学习记录,使用默认值: {progress_result['message']}")
fmd,fmdp,fsp = load_full_markdown_file(course_id, chapter_name, lesson_name)
user_uuid2ase_client[user_uuid] = HSAEngineClient(current_app.config["ASE_ENGINE_URL"], current_app.config["ASE_ENGINE_NAMESPACE"],id=user_id, chatmanager = chatmanager)