對齊 Ollama-first flag 語義
All checks were successful
CD Pipeline / deploy (push) Successful in 56s

This commit is contained in:
OoO
2026-05-13 12:00:21 +08:00
parent ce208921af
commit 6313fdd293
6 changed files with 43 additions and 32 deletions

View File

@@ -110,8 +110,8 @@ _nim_call_count = {"date": "", "count": 0}
# ── Operation Ollama-First v5.0 / Phase 3 / A9 ──────────────────
# GCP Ollama qwen3:14b 灰度切換開關
# - 預設 false → 行為與戰前完全相同(仍走 NIM
# - true → qwen3 主路徑NIM 降為備援,最後仍兜底 Hermes 規則引擎ADR-004
# - false → 緊急停用 Ollama-first 時才回 NIM-first
# 模型選擇A2 web-research 紅綠燈報告 docs/phase0_research_report_20260503.md
# 原戰役計畫 deepseek-r1:14b 的 Ollama tool_calls chat template 缺對應 jinja
# GitHub Issue #10935 未解),改採 qwen3:14bOllama 官方 + qwenlm 雙確認 tools 支援)。
@@ -1397,7 +1397,7 @@ class NemotronDispatcher:
}
# ── Operation Ollama-First v5.0 / Phase 3 / A9qwen3 主路徑feature flag 灰度)──
# 預設 NEMOTRON_OLLAMA_FIRST=false 時不進入此分支,行為與戰前完全相同
# NEMOTRON_OLLAMA_FIRST=false 時不進入此分支,僅作緊急退路
# 若 qwen3 成功取得 tool_calls沿用既有 TOOL_MAP 執行邏輯(共用 footprint/threat 注入)。
# 若 qwen3 失敗或 0 tool_calls → 不直接降到 Hermes 規則,先嘗試 NIM 備援,再走 ADR-004。
qwen3_used = False
@@ -1440,7 +1440,7 @@ class NemotronDispatcher:
pre_errors=errors,
)
# ── 進入 NIM 路徑flag=false 預設主路徑flag=true 則為 qwen3 失敗備援)──
# ── 進入 NIM 路徑flag=false 緊急主路徑flag=true 則為 qwen3 失敗備援)──
if not NIM_API_KEY:
logger.warning("[Dispatcher][ADR-004] NVIDIA_API_KEY 未設定,啟動 Hermes 規則引擎降級")
fb = self._hermes_rule_fallback(nim_candidates, hermes_stats)

View File

@@ -48,12 +48,12 @@ NVIDIA_FALLBACK_MODEL = "meta/llama-3.3-70b-instruct"
TAIPEI_TZ_OFFSET = 8 # UTC+8
# ──────────────────────────────────────────────────────────────────────────────
# Operation Ollama-First v5.0 — Phase 3 feature flag (預設 OFF統帥手動開灰度)
# - OPENCLAW_QA_OLLAMA_FIRST: false=維持戰前 Gemini-first 行為,true=走 Ollama 主、Gemini fallback
# Operation Ollama-First v5.0 — Phase 3 feature flag預設 ONGemini 僅 fallback
# - OPENCLAW_QA_OLLAMA_FIRST: true=走 Ollama 主、Gemini fallbackfalse=緊急退回 legacy Gemini-first
# - OPENCLAW_QA_OLLAMA_MODEL: GCP Ollama 上的模型 tagA2 推薦 qwen3:14b9.3GB
# - OPENCLAW_QA_OLLAMA_HOST: 允許獨立指定 QA 用主機;未設則 fallback 到通用 OLLAMA_HOST_PRIMARY
# - OPENCLAW_QA_OLLAMA_TIMEOUT: 單次 Ollama 呼叫超時(秒),低品質判定後仍會升級 Gemini
# 任何 deploy 不開 flag → 行為與戰前完全相同regression-safe
# 任何 deploy 不開 flag → Ollama-first緊急時才顯式設 false 回 legacy
# ──────────────────────────────────────────────────────────────────────────────
@@ -163,8 +163,8 @@ def generate_strategy_response(query: str, context: Optional[Dict[str, Any]] = N
繁體中文回覆字串。所有 LLM 失敗時回降級訊息(永遠回字串、不拋例外)。
路由Operation Ollama-First v5.0 — Phase 3:
OPENCLAW_QA_OLLAMA_FIRST=false預設→ Gemini → NIM(戰前行為)
OPENCLAW_QA_OLLAMA_FIRST=true GCP Ollama qwen3:14b → 品質檢測 → fallback Gemini → NIM
OPENCLAW_QA_OLLAMA_FIRST=true預設 GCP Ollama qwen3:14b → 品質檢測 → fallback Gemini → NIM
OPENCLAW_QA_OLLAMA_FIRST=false緊急停用時才回 Gemini → NIM legacy 路徑
"""
q = (query or "").strip()
if not q:
@@ -174,7 +174,7 @@ def generate_strategy_response(query: str, context: Optional[Dict[str, Any]] = N
# ── Phase 11 RAG-firstfeature flag 預設 OFF只在 Q&A 入口接,週月年報不接)──
# 高信心 RAG 命中 → 直接回 ai_insights 內容,避免 LLM 呼叫
# 低信心或 flag OFF → 走既有 Ollama → Gemini → NIM 路徑
# 低信心或 flag OFF → 走後續 Ollama-first / fallback 路徑
if is_rag_enabled():
try:
rag = rag_service.query(
@@ -191,7 +191,7 @@ def generate_strategy_response(query: str, context: Optional[Dict[str, Any]] = N
except Exception as exc:
logger.warning("[OpenClaw][QA] RAG query failed (%s), fallback LLM", exc)
# ── 灰度路徑Ollama 優先flag=true 才走,預設 OFF)──
# ── 路徑Ollama 優先flag=true預設 ON)──
if _qa_ollama_first_enabled():
ollama_reply = _call_qwen3_qa(q, context, request_id)
if ollama_reply and not _is_low_quality_response(ollama_reply):
@@ -202,7 +202,7 @@ def generate_strategy_response(query: str, context: Optional[Dict[str, Any]] = N
request_id,
)
# ── 既有路徑Gemini → NIMA4 已接 ai_call_logger──
# ── 備援路徑Gemini → NIMA4 已接 ai_call_logger──
return _legacy_gemini_first_qa(q, context, request_id=request_id)
@@ -211,7 +211,7 @@ def _legacy_gemini_first_qa(
context: Optional[Dict[str, Any]],
request_id: Optional[str] = None,
) -> str:
"""戰前 Gemini-first 路徑;抽出獨立函式以利 Phase 3 灰度與 regression test"""
"""legacy Gemini-first 緊急退路;正常情況只在 Ollama 主路徑失敗後使用"""
system_prompt = (
"你是 MOMO Pro 電商情報策略師「OpenClaw」。以繁體中文台灣用語回覆使用者。"
"嚴禁簡體字,嚴禁空洞套話。若使用者要求的資料需即時查詢,"
@@ -1482,7 +1482,7 @@ def _daily_hermes_template_enabled() -> bool:
"""Operation Ollama-First v5.0 Phase 3 — Hermes 模板模式 feature flag.
每次呼叫即時讀取,允許 runtime toggle 灰度(不需重啟 scheduler
預設 false → 走 _legacy_full_gemini_daily_report(戰前行為,零 regression
預設 true → Hermes/Ollama 模板模式;false 才回 _legacy_full_gemini_daily_report。
"""
# 統帥 2026-05-03 23:30 指令:「免費優先」
# 預設 ONHermes 算 KPI + 模板填充Gemini 只寫 200 字洞察(戰前 28K → ~8K tokens, -71%
@@ -1495,9 +1495,9 @@ def generate_daily_report() -> dict:
OpenClaw 電商日報(每日 09:00— Operation Ollama-First v5.0 Phase 3 路由層。
依 ``OPENCLAW_DAILY_HERMES_TEMPLATE`` 分流:
- false預設``_legacy_full_gemini_daily_report``Gemini 全文寫稿(~28K tokens
- true``_generate_daily_report_hermes_template``Hermes 算 KPI + 模板填充 +
- true預設``_generate_daily_report_hermes_template``Hermes 算 KPI + 模板填充 +
Gemini 寫 200 字洞察(~8K tokens, -71%
- false``_legacy_full_gemini_daily_report``Gemini 全文寫稿(~28K tokens
回傳合約兩條路徑一致:``{status, report_type, insight_id, period, ...}``
cron 不需修改ai_insights schema 不變(仍 type='daily_report')。