fix(ai): enforce ollama first for drift governance
All checks were successful
Code Review / ai-code-review (push) Successful in 16s
CD Pipeline / tests (push) Successful in 1m17s
CD Pipeline / build-and-deploy (push) Successful in 4m54s
CD Pipeline / post-deploy-checks (push) Successful in 3m10s

This commit is contained in:
Your Name
2026-05-06 19:26:09 +08:00
parent d90414ddfa
commit 2ef54ccc94
6 changed files with 157 additions and 9 deletions

View File

@@ -21,7 +21,7 @@ from typing import TYPE_CHECKING
import structlog
from src.models.drift import DriftIntent, DriftInterpretation, DriftItem
from src.models.drift import DriftIntent, DriftInterpretation
if TYPE_CHECKING:
from src.models.drift import DriftReport
@@ -62,7 +62,7 @@ class NemotronDriftInterpreter:
❌ 不直接呼叫 kubectl 或 git
"""
async def analyze(self, report: "DriftReport") -> DriftInterpretation:
async def analyze(self, report: DriftReport) -> DriftInterpretation:
"""
分析漂移意圖
@@ -85,7 +85,7 @@ class NemotronDriftInterpreter:
result = await self._call_nemotron(prompt)
return result
def _format_diff_for_prompt(self, report: "DriftReport") -> str:
def _format_diff_for_prompt(self, report: DriftReport) -> str:
"""格式化 diff 給 Nemotron 分析用"""
lines = []
for item in report.items[:10]: # 最多 10 項避免 token 過多
@@ -111,7 +111,17 @@ class NemotronDriftInterpreter:
try:
from src.services.openclaw import get_openclaw
openclaw = get_openclaw()
response_text, _provider, success = await openclaw.call(prompt)
response_text, _provider, success = await openclaw.call(
prompt,
alert_context={
"intent_hint": "config",
"task_type": "diagnose",
"enforce_ollama_first": True,
"allow_gcp_heavy_model": True,
"target_resource": "config-drift",
"alert_type": "ConfigDriftInternalScan",
},
)
if not success or not response_text:
logger.warning("drift_interpreter_openclaw_failed", provider=_provider)