training.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from fastapi import APIRouter
  2. from app.schemas.training import TrainingConfig, TrainingJobResponse, TrainingProgress
  3. router = APIRouter()
  4. @router.post("/jobs", response_model=TrainingJobResponse)
  5. async def create_training_job(config: TrainingConfig):
  6. """创建并加入训练任务。"""
  7. return TrainingJobResponse(
  8. id="placeholder",
  9. model_id=config.model_id,
  10. model_type=config.model_type.value,
  11. peft_method=config.peft_method.value,
  12. status="pending",
  13. created_at="",
  14. )
  15. @router.get("/jobs", response_model=list[TrainingJobResponse])
  16. async def list_training_jobs():
  17. """列出所有训练任务。"""
  18. return []
  19. @router.get("/jobs/{job_id}", response_model=TrainingJobResponse)
  20. async def get_training_job(job_id: str):
  21. """获取指定任务详情。"""
  22. return TrainingJobResponse(
  23. id=job_id,
  24. model_id="",
  25. model_type="text",
  26. peft_method="lora",
  27. status="pending",
  28. created_at="",
  29. )
  30. @router.post("/jobs/{job_id}/cancel")
  31. async def cancel_training_job(job_id: str):
  32. """取消运行中的训练任务。"""
  33. return {"status": "cancelled"}
  34. @router.get("/jobs/{job_id}/logs")
  35. async def stream_training_logs(job_id: str):
  36. """通过 SSE 流式推送训练日志。"""
  37. return {"logs": []}