diet_errors.py 872 B

12345678910111213141516171819202122232425262728293031323334353637
  1. """
  2. 饮食流水线统一错误码(便于 Observability / failure mode 统计)。
  3. """
  4. from __future__ import annotations
  5. from enum import Enum
  6. from typing import Any, Dict, Optional
  7. class DietErrorCode(str, Enum):
  8. LLM_PARSE_ERROR = "LLM_PARSE_ERROR"
  9. VALIDATION_FAILED = "VALIDATION_FAILED"
  10. LLM_TIMEOUT = "LLM_TIMEOUT"
  11. TOOL_ERROR = "TOOL_ERROR"
  12. STAGE_ABORTED = "STAGE_ABORTED"
  13. DEGRADED_FALLBACK = "DEGRADED_FALLBACK"
  14. def diet_error_record(
  15. stage: str,
  16. code: DietErrorCode | str,
  17. message: str,
  18. *,
  19. attempt: Optional[int] = None,
  20. detail: Any = None,
  21. ) -> Dict[str, Any]:
  22. rec: Dict[str, Any] = {
  23. "stage": stage,
  24. "code": str(code),
  25. "message": message,
  26. }
  27. if attempt is not None:
  28. rec["attempt"] = attempt
  29. if detail is not None:
  30. rec["detail"] = detail
  31. return rec