- 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
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
"""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
|