fix(ai): stabilize GCP Ollama alert lane
This commit is contained in:
@@ -77,7 +77,7 @@ class OllamaProvider:
|
||||
client = await self._get_client()
|
||||
|
||||
registry = get_model_registry()
|
||||
model_name = registry.get_model("ollama", "rca")
|
||||
model_name = str((context or {}).get("ollama_model") or registry.get_model("ollama", "rca")).strip()
|
||||
options = registry.get_provider_options("ollama")
|
||||
|
||||
# P0 2026-04-04 Claude Code: per-task timeout(Option C 分情境)
|
||||
@@ -112,7 +112,13 @@ class OllamaProvider:
|
||||
tokens = data.get("eval_count", 0) + data.get("prompt_eval_count", 0)
|
||||
latency = (time.perf_counter() - start) * 1000
|
||||
|
||||
logger.info("ollama_provider_success", response_length=len(result), tokens=tokens, latency_ms=round(latency, 1))
|
||||
logger.info(
|
||||
"ollama_provider_success",
|
||||
response_length=len(result),
|
||||
tokens=tokens,
|
||||
latency_ms=round(latency, 1),
|
||||
model=model_name,
|
||||
)
|
||||
return AIResult(
|
||||
raw_response=result,
|
||||
success=True,
|
||||
@@ -158,7 +164,7 @@ class OllamaProvider:
|
||||
total_tokens = 0
|
||||
messages: list[dict] = [{"role": "user", "content": prompt}]
|
||||
registry = get_model_registry()
|
||||
model_name = registry.get_model("ollama", "rca")
|
||||
model_name = str((context or {}).get("ollama_model") or registry.get_model("ollama", "rca")).strip()
|
||||
options = registry.get_provider_options("ollama")
|
||||
task_type = (context or {}).get("task_type", "")
|
||||
if task_type in ("diagnose", "force_local"):
|
||||
@@ -321,9 +327,9 @@ class Ollama188Provider(OllamaProvider):
|
||||
registry = get_model_registry()
|
||||
# 嘗試取 ollama_188 專屬設定,fallback 到 ollama 預設
|
||||
try:
|
||||
model_name = registry.get_model("ollama_188", "rca")
|
||||
model_name = str((context or {}).get("ollama_model") or registry.get_model("ollama_188", "rca")).strip()
|
||||
except Exception:
|
||||
model_name = getattr(settings, "OLLAMA_HEALTH_CHECK_MODEL", "qwen2.5:7b-instruct")
|
||||
model_name = str((context or {}).get("ollama_model") or getattr(settings, "OLLAMA_HEALTH_CHECK_MODEL", "qwen2.5:7b-instruct")).strip()
|
||||
|
||||
try:
|
||||
options = registry.get_provider_options("ollama_188")
|
||||
@@ -364,6 +370,7 @@ class Ollama188Provider(OllamaProvider):
|
||||
tokens=tokens,
|
||||
latency_ms=round(latency, 1),
|
||||
endpoint=fallback_url,
|
||||
model=model_name,
|
||||
)
|
||||
return AIResult(
|
||||
raw_response=result,
|
||||
|
||||
@@ -165,9 +165,11 @@ class GovernanceAgent:
|
||||
auto_deprecated=len(auto_deprecated_ids),
|
||||
kept=len(kept_ids),
|
||||
)
|
||||
drift_ratio = len(drifted) / total if total > 0 else 0.0
|
||||
return {
|
||||
"checked": total,
|
||||
"drifted": len(drifted),
|
||||
"drift_ratio": drift_ratio,
|
||||
"auto_deprecated": len(auto_deprecated_ids),
|
||||
"kept": len(kept_ids),
|
||||
}
|
||||
|
||||
@@ -1142,6 +1142,8 @@ class OpenClawService:
|
||||
exec_context = dict(alert_context) if alert_context else {}
|
||||
if decision.intent == IntentType.DIAGNOSE:
|
||||
exec_context["task_type"] = "diagnose"
|
||||
if self._is_incident_alert_context(alert_context):
|
||||
exec_context["ollama_model"] = getattr(settings, "ALERT_OLLAMA_MODEL", "gemma3:4b")
|
||||
|
||||
result = await executor.execute(
|
||||
prompt=prompt,
|
||||
|
||||
Reference in New Issue
Block a user