上传学习进度

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框架中的对话列表 # 获取MultiAgents框架中的对话列表
dialog_list = get_multiagents_dialog_list(user_id) dialog_list = get_multiagents_dialog_list(user_id)
his_data = dialog_list['data']
# 构建学习进度数据 # 构建学习进度数据
progress_data = { progress_data = {
"user_uuid": user_uuid, "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, "chapter_chain_now": chatmanager.chapter_chain_now,
"chat_historys": chatmanager.chat_historys, "chat_historys": chatmanager.chat_historys,
"scores": chatmanager.scores, "scores": chatmanager.scores,
"multiagents_dialogs": dialog_list, "multiagents_dialogs": his_data,
"updated_at": datetime.now() "updated_at": datetime.now()
} }
@@ -530,7 +530,7 @@ def get_multiagents_dialog_list(user_id: str) -> List[Dict]:
- user_id: 用户ID - user_id: 用户ID
返回: 返回:
- List[Dict]: 对话列表 - Dict[List]: 对话列表(key 为 History database)
""" """
try: try:
# 从配置中获取ASE引擎URL和token # 从配置中获取ASE引擎URL和token
@@ -596,3 +596,62 @@ def load_learning_progress(user_uuid: str, material_id: str, chapter_name: str,
except Exception as e: except Exception as e:
current_app.logger.error(f"加载学习进度失败: {str(e)}") current_app.logger.error(f"加载学习进度失败: {str(e)}")
return None 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
}

View File

@@ -10,7 +10,7 @@ from ..function_tools import judge
from ..function_tools import next_chapter from ..function_tools import next_chapter
from ..services.backboard_service import realtime_response from ..services.backboard_service import realtime_response
from ..services.markdown_service import load_full_markdown_file from ..services.markdown_service import load_full_markdown_file
from ..services.course_service import save_learning_progress from ..services.course_service import save_learning_progress, upload_learning_progress_to_cloud
from ..extension_ase.ase_client import HSAEngineClient from ..extension_ase.ase_client import HSAEngineClient
from ..services.user_service import get_or_load_current_user from ..services.user_service import get_or_load_current_user
from ..services.course_service import load_learning_progress from ..services.course_service import load_learning_progress
@@ -97,6 +97,7 @@ class AgentNamespace(Namespace):
# 恢复当前章节链 # 恢复当前章节链
if 'chapter_chain_now' in progress: if 'chapter_chain_now' in progress:
chatmanager.chapter_chain_now = progress['chapter_chain_now'] chatmanager.chapter_chain_now = progress['chapter_chain_now']
upload_learning_progress_to_cloud(progress)
else: else:
chatmanager.chat_historys = [] chatmanager.chat_historys = []
chatmanager.scores = [] chatmanager.scores = []
@@ -306,6 +307,7 @@ class AgentNamespace(Namespace):
if chatmanager: if chatmanager:
save_result = save_learning_progress(uuid, chatmanager, user_id) save_result = save_learning_progress(uuid, chatmanager, user_id)
print(f"保存学习进度结果: {save_result}, user_uuid={uuid}") print(f"保存学习进度结果: {save_result}, user_uuid={uuid}")
except Exception as e: except Exception as e:
print(f"保存学习进度时发生异常: {str(e)}") print(f"保存学习进度时发生异常: {str(e)}")