atlasbot: add narrative insights
This commit is contained in:
parent
6fead623fa
commit
0a10a2d861
@ -1616,7 +1616,7 @@ def _insight_candidates(
|
||||
def _select_insight(
|
||||
prompt: str,
|
||||
candidates: list[tuple[str, str, str]],
|
||||
) -> tuple[str, str] | None:
|
||||
) -> tuple[str, str, str] | None:
|
||||
if not candidates:
|
||||
return None
|
||||
q = normalize_query(prompt)
|
||||
@ -1624,13 +1624,43 @@ def _select_insight(
|
||||
if any(word in q for word in ("unconventional", "weird", "odd", "unique", "surprising")):
|
||||
prefer_keys.extend(["hardware", "availability"])
|
||||
if any(word in q for word in ("another", "else", "different", "other")) and len(candidates) > 1:
|
||||
return candidates[1][1], candidates[1][2]
|
||||
return candidates[1]
|
||||
if prefer_keys:
|
||||
for key, text, conf in candidates:
|
||||
if key in prefer_keys:
|
||||
return text, conf
|
||||
key, text, conf = candidates[0]
|
||||
return text, conf
|
||||
return key, text, conf
|
||||
return candidates[0]
|
||||
|
||||
|
||||
def _format_insight_text(key: str, text: str) -> str:
|
||||
cleaned = text.strip().rstrip(".")
|
||||
if not cleaned:
|
||||
return ""
|
||||
if key == "hardware":
|
||||
counts = cleaned.replace("Hardware mix includes ", "")
|
||||
return f"Atlas mixes Raspberry Pi, Jetson, and AMD64 nodes ({counts})."
|
||||
if key == "postgres":
|
||||
detail = cleaned.replace("Postgres is at ", "")
|
||||
return f"Postgres looks healthy at {detail}."
|
||||
if key == "pods":
|
||||
detail = cleaned.replace("There are ", "")
|
||||
return f"Pods look stable with {detail}."
|
||||
if key == "availability":
|
||||
return cleaned + "."
|
||||
if key in ("cpu", "ram"):
|
||||
return cleaned + "."
|
||||
return cleaned + "."
|
||||
|
||||
|
||||
def _insight_prefix(prompt: str) -> str:
|
||||
q = normalize_query(prompt)
|
||||
if any(word in q for word in ("another", "else", "different", "other")):
|
||||
return "Another interesting detail: "
|
||||
if any(word in q for word in ("unconventional", "weird", "odd", "unique", "surprising")):
|
||||
return "What stands out is that "
|
||||
if any(word in q for word in ("interesting", "notable", "fun", "cool")):
|
||||
return "One notable detail: "
|
||||
return ""
|
||||
|
||||
|
||||
def cluster_overview_answer(
|
||||
@ -1714,8 +1744,14 @@ def cluster_answer(
|
||||
candidates = _insight_candidates(inventory, snapshot)
|
||||
selected = _select_insight(prompt, candidates)
|
||||
if selected:
|
||||
text, confidence = selected
|
||||
return _format_confidence(text, confidence)
|
||||
key, raw_text, confidence = selected
|
||||
formatted = _format_insight_text(key, raw_text)
|
||||
if not formatted:
|
||||
formatted = raw_text
|
||||
prefix = _insight_prefix(prompt)
|
||||
if prefix:
|
||||
formatted = prefix + formatted
|
||||
return _format_confidence(formatted, confidence)
|
||||
structured = structured_answer(
|
||||
prompt,
|
||||
inventory=inventory,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user