2026-04-10 16:43:28 +08:00
|
|
|
from app.clients.llm.base import LLMClient
|
2026-04-10 16:27:51 +08:00
|
|
|
from app.core.logging import get_logger
|
|
|
|
|
from app.models.finetune_models import (
|
|
|
|
|
FinetuneStartRequest,
|
|
|
|
|
FinetuneStartResponse,
|
|
|
|
|
FinetuneStatusResponse,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
|
|
|
|
_STATUS_MAP = {
|
|
|
|
|
"running": "RUNNING",
|
|
|
|
|
"succeeded": "SUCCESS",
|
|
|
|
|
"failed": "FAILED",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-04-10 16:43:28 +08:00
|
|
|
async def submit_finetune(req: FinetuneStartRequest, llm: LLMClient) -> FinetuneStartResponse:
|
|
|
|
|
"""Submit a fine-tune job via the LLMClient interface and return the job ID."""
|
|
|
|
|
job_id = await llm.submit_finetune(req.jsonl_url, req.base_model, req.hyperparams or {})
|
|
|
|
|
logger.info("finetune_submit", extra={"job_id": job_id, "model": req.base_model})
|
|
|
|
|
return FinetuneStartResponse(job_id=job_id)
|
2026-04-10 16:27:51 +08:00
|
|
|
|
|
|
|
|
|
2026-04-10 16:43:28 +08:00
|
|
|
async def get_finetune_status(job_id: str, llm: LLMClient) -> FinetuneStatusResponse:
|
|
|
|
|
"""Retrieve fine-tune job status via the LLMClient interface."""
|
|
|
|
|
raw = await llm.get_finetune_status(job_id)
|
|
|
|
|
status = _STATUS_MAP.get(raw["status"], "RUNNING")
|
|
|
|
|
logger.info("finetune_status", extra={"job_id": job_id, "status": status})
|
|
|
|
|
return FinetuneStatusResponse(
|
|
|
|
|
job_id=raw["job_id"],
|
|
|
|
|
status=status,
|
|
|
|
|
progress=raw["progress"],
|
|
|
|
|
error_message=raw["error_message"],
|
|
|
|
|
)
|