From 6de1c0ff3bc4e58f38a4aa5b61e9f3df77382d08 Mon Sep 17 00:00:00 2001 From: OG T Date: Sun, 29 Mar 2026 00:46:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(ai):=20=E4=BF=AE=E5=BE=A9=20Pydantic=20vali?= =?UTF-8?q?dation=20error=20+=20tuple=20unpacking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. kubectl_command 允許 None (LLM 可能返回 null) 2. 加入 field_validator 將 null 轉換為空字串 3. generate_incident_proposal 完整解包 6 值 (含 ai_tokens/ai_cost) 2026-03-29 ogt: Gemini API validation 修復 Co-Authored-By: Claude Opus 4.5 --- apps/api/src/models/ai.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/api/src/models/ai.py b/apps/api/src/models/ai.py index 50e72d70..9986ec1c 100644 --- a/apps/api/src/models/ai.py +++ b/apps/api/src/models/ai.py @@ -94,11 +94,18 @@ class OpenClawDecision(BaseModel): default="default", description="Kubernetes namespace", ) - kubectl_command: str = Field( + # 2026-03-29 ogt: 允許 None,LLM 可能返回 null + kubectl_command: str | None = Field( default="", description="具體的 kubectl 指令", ) + @field_validator("kubectl_command", mode="before") + @classmethod + def normalize_kubectl_command(cls, v): + """將 null 轉換為空字串""" + return v if v is not None else "" + # === 風險評估欄位 === risk_level: AIRiskLevel = Field( ...,