fix(drift-narrator): 修復 JSON 裸奔 — 從 NEMOTRON 回傳解析 description 欄位
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 10m44s
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 10m44s
根因:openclaw.call() 經 NEMOTRON 路由後強制輸出 JSON(NEMOTRON_SYSTEM_PROMPT 鐵律)
但 _generate_narrative 期待純文字 → JSON 整包吐到 Telegram <pre> 區塊裸奔
修復:收到 text 後先嘗試 JSON 解析
- 成功 → 按優先順序取 description / action_title / reasoning
- 失敗(非 JSON)→ 原文使用(向下相容 Ollama qwen 純文字回傳)
效果:Telegram Config Drift 卡片顯示繁中人話摘要,不再吐原始 JSON
2026-04-17 ogt + Claude Sonnet 4.6
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -165,7 +165,25 @@ class DriftNarratorService:
|
||||
text, _provider, success = await openclaw.call(prompt)
|
||||
|
||||
if success and text and text.strip():
|
||||
return text.strip()
|
||||
# 2026-04-17 ogt + Claude Sonnet 4.6: 修復 JSON 裸奔問題
|
||||
# 根因:openclaw.call() 經 NEMOTRON 路由後強制回傳 JSON(NEMOTRON_SYSTEM_PROMPT 要求)
|
||||
# 但此處需要純文字敘述 → JSON 被直接吐到 Telegram <pre> 區塊
|
||||
# 修復:嘗試解析 JSON,優先取 description;否則視為純文字使用
|
||||
import json as _json
|
||||
_raw = text.strip()
|
||||
try:
|
||||
_parsed = _json.loads(_raw)
|
||||
if isinstance(_parsed, dict):
|
||||
narrative = (
|
||||
_parsed.get("description")
|
||||
or _parsed.get("action_title")
|
||||
or _parsed.get("reasoning")
|
||||
or _raw
|
||||
)
|
||||
return str(narrative).strip()
|
||||
except (_json.JSONDecodeError, ValueError):
|
||||
pass
|
||||
return _raw
|
||||
|
||||
logger.warning("drift_narrator_openclaw_failed", provider=_provider)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user