atlasbot: add fact-pack fallback for fast
This commit is contained in:
parent
885e7b6489
commit
19b52ac5e3
@ -3823,6 +3823,37 @@ def _has_body_lines(answer: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _fallback_fact_answer(prompt: str, context: str) -> str:
|
||||||
|
facts: list[str] = []
|
||||||
|
for line in (context or "").splitlines():
|
||||||
|
trimmed = line.strip()
|
||||||
|
if not trimmed.startswith("F"):
|
||||||
|
continue
|
||||||
|
if ":" not in trimmed:
|
||||||
|
continue
|
||||||
|
fact = trimmed.split(":", 1)[1].strip()
|
||||||
|
if fact.startswith("-"):
|
||||||
|
fact = fact.lstrip("-").strip()
|
||||||
|
if fact:
|
||||||
|
facts.append(fact)
|
||||||
|
if not facts:
|
||||||
|
return ""
|
||||||
|
tokens = set(_tokens(prompt))
|
||||||
|
best_fact = ""
|
||||||
|
best_score = -1
|
||||||
|
for fact in facts:
|
||||||
|
score = len(tokens & set(_tokens(fact)))
|
||||||
|
if score > best_score:
|
||||||
|
best_score = score
|
||||||
|
best_fact = fact
|
||||||
|
if best_score <= 0:
|
||||||
|
return ""
|
||||||
|
sentence = f"Based on the snapshot, {best_fact}"
|
||||||
|
if not sentence.endswith((".", "!", "?")):
|
||||||
|
sentence += "."
|
||||||
|
return sentence
|
||||||
|
|
||||||
|
|
||||||
def _open_ended_fast_single(
|
def _open_ended_fast_single(
|
||||||
prompt: str,
|
prompt: str,
|
||||||
*,
|
*,
|
||||||
@ -3849,6 +3880,10 @@ def _open_ended_fast_single(
|
|||||||
system_override=_open_ended_system(),
|
system_override=_open_ended_system(),
|
||||||
model=model,
|
model=model,
|
||||||
)
|
)
|
||||||
|
if not _has_body_lines(reply):
|
||||||
|
fallback = _fallback_fact_answer(prompt, context)
|
||||||
|
if fallback:
|
||||||
|
reply = fallback
|
||||||
if state:
|
if state:
|
||||||
state.update("done", step=_open_ended_total_steps("fast"))
|
state.update("done", step=_open_ended_total_steps("fast"))
|
||||||
return _ensure_scores(reply)
|
return _ensure_scores(reply)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user