Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lpm_kernel/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .domains.kernel2.routes_talk import talk_bp
from .domains.user_llm_config.routes import user_llm_config_bp
from .domains.space.space_routes import space_bp
from .domains.backup.routes import backup_bp # Add import for backup blueprint

def init_routes(app: Flask):
"""Initialize all route blueprints"""
Expand All @@ -27,6 +28,7 @@ def init_routes(app: Flask):
app.register_blueprint(space_bp)
app.register_blueprint(talk_bp)
app.register_blueprint(user_llm_config_bp)
app.register_blueprint(backup_bp) # Register backup blueprint
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
app.config['TEMPLATES_AUTO_RELOAD'] = True
# Disable response buffering
Expand Down
1 change: 1 addition & 0 deletions lpm_kernel/api/domains/backup/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .routes import *
63 changes: 63 additions & 0 deletions lpm_kernel/api/domains/backup/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from flask import Blueprint, request, jsonify, current_app
from lpm_kernel.backup.backup_service import BackupService
from lpm_kernel.configs.config import Config # Import Config

backup_bp = Blueprint('backup', __name__, url_prefix='/api/backups')

# Instantiate BackupService using the application config
# Note: This assumes Config is a singleton or can be instantiated here.
# A better approach might involve dependency injection or accessing config via current_app.
config = Config.from_env() # Attempt to load config
backup_service = BackupService(config=config) # Pass the loaded config

@backup_bp.route('/', methods=['POST'])
def create_backup_route():
"""API endpoint to manually trigger a backup."""
try:
data = request.get_json() or {}
description = data.get('description')
result = backup_service.create_backup(description=description)
if result:
return jsonify(result), 201
else:
return jsonify({"status": "error", "message": "Failed to create backup"}), 500
except Exception as e:
current_app.logger.error(f"Backup creation failed: {str(e)}")
return jsonify({"status": "error", "message": f"Backup creation failed: {str(e)}"}), 500

@backup_bp.route('/', methods=['GET'])
def list_backups_route():
"""API endpoint to list available backups."""
try:
backups = backup_service.list_backups()
return jsonify({"status": "success", "backups": backups}), 200
except Exception as e:
current_app.logger.error(f"Listing backups failed: {str(e)}")
return jsonify({"status": "error", "message": f"Listing backups failed: {str(e)}"}), 500

@backup_bp.route('/<string:backup_id>/restore', methods=['POST'])
def restore_backup_route(backup_id):
"""API endpoint to restore data from a specific backup."""
try:
result = backup_service.restore_backup(backup_id)
if result.get('status') == 'error':
return jsonify(result), 404 if 'not found' in result.get('message', '').lower() else 500
return jsonify(result), 200
except Exception as e:
return jsonify({"status": "error", "message": f"Restore failed: {str(e)}"}), 500

@backup_bp.route('/<string:backup_id>', methods=['DELETE'])
def delete_backup_route(backup_id):
"""API endpoint to delete a specific backup."""
try:
result = backup_service.delete_backup(backup_id)
if result.get('status') == 'error':
return jsonify(result), 404 if 'not found' in result.get('message', '').lower() else 500
return jsonify(result), 200
except Exception as e:
current_app.logger.error(f"Backup deletion failed: {str(e)}")
return jsonify({"status": "error", "message": f"Backup deletion failed: {str(e)}"}), 500

# TODO: Add error handling
# TODO: Add more robust error handling (e.g., specific error codes)
# TODO: Consider dependency injection for BackupService
15 changes: 7 additions & 8 deletions lpm_kernel/api/domains/loads/load_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,28 +423,27 @@ def _clean_data_directories() -> None:

@staticmethod
def _reset_training_progress() -> None:
"""Reset training progress objects in memory"""
"""重置内存中的训练进度对象"""
try:
# Get all possible training progress file patterns
from lpm_kernel.api.domains.trainprocess.trainprocess_service import TrainProcessService
import os
# 获取所有可能的训练进度文件模式
base_dir = os.getenv('LOCAL_BASE_DIR', '.')
progress_dir = os.path.join(base_dir, 'data', 'progress')
if os.path.exists(progress_dir):
for file in os.listdir(progress_dir):
if file.startswith('trainprocess_progress_'):
# Extract model name
# 提取模型名称
model_name = file.replace('trainprocess_progress_', '').replace('.json', '')
# Create a new service instance for each model and reset progress
# 为每个模型创建新的服务实例并重置进度
train_service = TrainProcessService(current_model_name=model_name)
train_service.progress.reset_progress()
logger.info(f"Reset training progress for model: {model_name}")

# Reset default training progress
# 重置默认训练进度
default_train_service = TrainProcessService.get_instance()
if default_train_service is not None:
default_train_service.progress.reset_progress()

logger.info("Reset default training progress")

except Exception as e:
logger.error(f"Failed to reset training progress objects: {str(e)}")

Expand Down
Loading