Files
life-echo/api/app/features/evaluation/phase1_job_timing.py
Kevin b0251e5b26 feat(eval): server-side replay/phase1 timing + memoir phase1 batch chunking
- Replay and memoir-submit responses include started/finished UTC and elapsed_ms;
  Phase1 poll exposes Redis-backed submit time and elapsed_ms_since_submit.
- Phase1 batch LLM splits segments by memoir_phase1_batch_llm_chunk_size with
  bisect fallback per chunk; Playground shows server timings.

Made-with: Cursor
2026-04-09 13:39:04 +08:00

57 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Playground Phase1 提交时间:供 memoir-phase1-ready 轮询展示服务端等待耗时。"""
from __future__ import annotations
import json
from datetime import datetime, timezone
from typing import Any
from app.core.logging import get_logger
from app.core.redis import redis_service
logger = get_logger(__name__)
TTL_SECONDS = 172800 # 48h覆盖长队列与多次评测下次 submit 会覆盖
_EVAL_PREFIX = "internal_eval:playground_phase1_job:"
def _redis_key(conversation_id: str) -> str:
return f"{_EVAL_PREFIX}{conversation_id}"
async def record_phase1_job_submitted(
conversation_id: str,
*,
celery_task_id: str | None,
segment_count: int,
) -> datetime:
now = datetime.now(timezone.utc)
payload: dict[str, Any] = {
"submitted_at_utc": now.isoformat().replace("+00:00", "Z"),
"celery_task_id": celery_task_id,
"segment_count": segment_count,
}
try:
client = await redis_service.get_client()
await client.setex(
_redis_key(conversation_id),
TTL_SECONDS,
json.dumps(payload, ensure_ascii=False),
)
except Exception as e:
logger.warning("eval phase1 job timing redis write failed: {}", e)
return now
async def load_phase1_job_meta(conversation_id: str) -> dict[str, Any] | None:
try:
client = await redis_service.get_client()
raw = await client.get(_redis_key(conversation_id))
if not raw:
return None
return json.loads(raw)
except Exception as e:
logger.warning("eval phase1 job timing redis read failed: {}", e)
return None