上传学习进度

This commit is contained in:
CakeCN
2025-12-09 13:16:10 +08:00
parent c08fb49bcd
commit c3c76788fe
2 changed files with 65 additions and 4 deletions

View File

@@ -489,7 +489,7 @@ def save_learning_progress(user_uuid: str, chatmanager, user_id: str) -> bool:
# 获取MultiAgents框架中的对话列表
dialog_list = get_multiagents_dialog_list(user_id)
his_data = dialog_list['data']
# 构建学习进度数据
progress_data = {
"user_uuid": user_uuid,
@@ -500,7 +500,7 @@ def save_learning_progress(user_uuid: str, chatmanager, user_id: str) -> bool:
"chapter_chain_now": chatmanager.chapter_chain_now,
"chat_historys": chatmanager.chat_historys,
"scores": chatmanager.scores,
"multiagents_dialogs": dialog_list,
"multiagents_dialogs": his_data,
"updated_at": datetime.now()
}
@@ -530,7 +530,7 @@ def get_multiagents_dialog_list(user_id: str) -> List[Dict]:
- user_id: 用户ID
返回:
- List[Dict]: 对话列表
- Dict[List]: 对话列表(key 为 History database)
"""
try:
# 从配置中获取ASE引擎URL和token
@@ -596,3 +596,62 @@ def load_learning_progress(user_uuid: str, material_id: str, chapter_name: str,
except Exception as e:
current_app.logger.error(f"加载学习进度失败: {str(e)}")
return None
def upload_learning_progress_to_cloud(progress: Dict) -> Dict:
"""
将学习进度上传到云服务
参数:
- progress: 学习进度数据字典{'databases':{}, 'global_databases':{}, 'session_info_out':{}}
返回:
- Dict: 上传结果包含success和message字段
"""
try:
# 从配置中获取ASE引擎URL和token
config = current_app.config
url_token = config.get("ASE_ENGINE_URL_TOKEN", "")
# 构建请求URL
base_url = config.get("ASE_ENGINE_URL", "")
api_url = f"{base_url}/api/sync/upload"
# 构建请求参数
payload = {
"namespace_url": url_token, # 使用配置中的token作为namespace_url
"user_id": progress.get("user_id", ""),
"data": progress
}
# 发送POST请求
response = requests.post(
api_url,
json=payload,
headers={"Content-Type": "application/json"},
timeout=10
)
# 处理响应
if response.status_code == 200:
result = response.json()
current_app.logger.info(f"学习进度上传成功: user_id={progress.get('user_id')}")
return {
"success": True,
"message": "学习进度上传成功",
"data": result
}
else:
error_msg = f"上传失败HTTP状态码: {response.status_code}"
current_app.logger.error(f"学习进度上传失败: {error_msg}")
return {
"success": False,
"message": error_msg
}
except Exception as e:
error_msg = f"上传异常: {str(e)}"
current_app.logger.error(f"学习进度上传异常: {error_msg}")
return {
"success": False,
"message": error_msg
}