Compare commits
2 Commits
67488a8898
...
80da274eaa
| Author | SHA1 | Date | |
|---|---|---|---|
| 80da274eaa | |||
| 1ef8ae4d3d |
@ -1059,10 +1059,24 @@ def _extract_hardware_usage_facts(lines: list[str], question: str) -> list[str]:
|
|||||||
return []
|
return []
|
||||||
if not any(term in lowered for term in ("average", "avg", "mean", "load", "cpu", "ram", "memory")):
|
if not any(term in lowered for term in ("average", "avg", "mean", "load", "cpu", "ram", "memory")):
|
||||||
return []
|
return []
|
||||||
|
avg_line = None
|
||||||
|
top_line = None
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith("hardware_usage_avg:"):
|
if line.startswith("hardware_usage_avg:"):
|
||||||
return [line]
|
avg_line = line
|
||||||
return []
|
elif line.startswith("hardware_usage_top:"):
|
||||||
|
top_line = line
|
||||||
|
if not avg_line and not top_line:
|
||||||
|
return []
|
||||||
|
wants_top = any(term in lowered for term in ("highest", "lowest", "most", "least", "top", "worst", "best"))
|
||||||
|
if wants_top and top_line:
|
||||||
|
return [top_line]
|
||||||
|
facts: list[str] = []
|
||||||
|
if avg_line:
|
||||||
|
facts.append(avg_line)
|
||||||
|
if top_line:
|
||||||
|
facts.append(top_line)
|
||||||
|
return facts
|
||||||
|
|
||||||
|
|
||||||
def _metric_candidate_lines(lines: list[str], keywords: list[str] | None, limit: int = 40) -> list[str]:
|
def _metric_candidate_lines(lines: list[str], keywords: list[str] | None, limit: int = 40) -> list[str]:
|
||||||
|
|||||||
@ -36,6 +36,7 @@ ROUTE_PROMPT = (
|
|||||||
DECOMPOSE_SYSTEM = (
|
DECOMPOSE_SYSTEM = (
|
||||||
CLUSTER_SYSTEM
|
CLUSTER_SYSTEM
|
||||||
+ " Break complex questions into smaller, answerable sub-questions. "
|
+ " Break complex questions into smaller, answerable sub-questions. "
|
||||||
|
+ "If the question compares hardware classes or node types, include all classes mentioned in context; do not assume only rpi4/rpi5. "
|
||||||
+ "Return JSON only."
|
+ "Return JSON only."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -1580,6 +1580,7 @@ def _append_hardware_usage(lines: list[str], summary: dict[str, Any]) -> None:
|
|||||||
if not isinstance(usage, list) or not usage:
|
if not isinstance(usage, list) or not usage:
|
||||||
return
|
return
|
||||||
parts = []
|
parts = []
|
||||||
|
tops: dict[str, tuple[str, float]] = {}
|
||||||
for entry in usage[:5]:
|
for entry in usage[:5]:
|
||||||
if not isinstance(entry, dict):
|
if not isinstance(entry, dict):
|
||||||
continue
|
continue
|
||||||
@ -1595,8 +1596,27 @@ def _append_hardware_usage(lines: list[str], summary: dict[str, Any]) -> None:
|
|||||||
label += f" cpu={_format_float(cpu)} ram={_format_float(ram)}"
|
label += f" cpu={_format_float(cpu)} ram={_format_float(ram)}"
|
||||||
label += f" io={_format_rate_bytes(io)} net={_format_rate_bytes(net)}"
|
label += f" io={_format_rate_bytes(io)} net={_format_rate_bytes(net)}"
|
||||||
parts.append(label)
|
parts.append(label)
|
||||||
|
for metric, value in (("cpu", cpu), ("ram", ram), ("io", io), ("net", net), ("load", load)):
|
||||||
|
if isinstance(value, (int, float)):
|
||||||
|
current = tops.get(metric)
|
||||||
|
if current is None or float(value) > current[1]:
|
||||||
|
tops[metric] = (hardware, float(value))
|
||||||
if parts:
|
if parts:
|
||||||
lines.append("hardware_usage_avg: " + "; ".join(parts))
|
lines.append("hardware_usage_avg: " + "; ".join(parts))
|
||||||
|
if tops:
|
||||||
|
top_parts = []
|
||||||
|
for metric in ("cpu", "ram", "io", "net", "load"):
|
||||||
|
entry = tops.get(metric)
|
||||||
|
if not entry:
|
||||||
|
continue
|
||||||
|
hardware, value = entry
|
||||||
|
if metric in {"io", "net"}:
|
||||||
|
rendered = _format_rate_bytes(value)
|
||||||
|
else:
|
||||||
|
rendered = _format_float(value)
|
||||||
|
top_parts.append(f"{metric}={hardware} ({rendered})")
|
||||||
|
if top_parts:
|
||||||
|
lines.append("hardware_usage_top: " + "; ".join(top_parts))
|
||||||
|
|
||||||
|
|
||||||
def _append_cluster_watchlist(lines: list[str], summary: dict[str, Any]) -> None:
|
def _append_cluster_watchlist(lines: list[str], summary: dict[str, Any]) -> None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user