atlasbot: streamline quick answers
This commit is contained in:
parent
349a46ceab
commit
08ac598181
@ -3562,14 +3562,10 @@ def _open_ended_multi(
|
||||
fact_lines: list[str],
|
||||
fact_meta: dict[str, dict[str, Any]],
|
||||
history_lines: list[str],
|
||||
mode: str,
|
||||
state: ThoughtState | None = None,
|
||||
) -> str:
|
||||
model = _model_for_mode(mode)
|
||||
if mode == "fast":
|
||||
total_steps = 4
|
||||
else:
|
||||
total_steps = 9
|
||||
model = _model_for_mode("deep")
|
||||
total_steps = _open_ended_total_steps("deep")
|
||||
if state:
|
||||
state.total_steps = total_steps
|
||||
|
||||
@ -3591,52 +3587,6 @@ def _open_ended_multi(
|
||||
focus_tags = set(_ALLOWED_INSIGHT_TAGS)
|
||||
avoid_tags = _history_focus_tags(history_lines) if (subjective or _is_followup_query(prompt)) else set()
|
||||
|
||||
if mode == "fast":
|
||||
primary_ids = _open_ended_select_facts(
|
||||
prompt,
|
||||
fact_pack=fact_pack,
|
||||
fact_meta=fact_meta,
|
||||
history_lines=history_lines,
|
||||
focus_tags=focus_tags,
|
||||
avoid_tags=avoid_tags,
|
||||
avoid_fact_ids=[],
|
||||
count=3,
|
||||
subjective=subjective,
|
||||
state=state,
|
||||
step=2,
|
||||
model=model,
|
||||
)
|
||||
focus_label = interpretation.get("focus_label") or "primary angle"
|
||||
candidate = _open_ended_candidate(
|
||||
prompt,
|
||||
focus=str(focus_label),
|
||||
fact_pack=fact_pack,
|
||||
history_lines=history_lines,
|
||||
subjective=subjective,
|
||||
tone=str(tone),
|
||||
allow_list=allow_list,
|
||||
state=state,
|
||||
step=3,
|
||||
fact_hints=primary_ids,
|
||||
model=model,
|
||||
)
|
||||
reply = _open_ended_synthesize(
|
||||
prompt,
|
||||
fact_pack=fact_pack,
|
||||
history_lines=history_lines,
|
||||
candidates=[candidate],
|
||||
subjective=subjective,
|
||||
tone=str(tone),
|
||||
allow_list=allow_list,
|
||||
state=state,
|
||||
step=4,
|
||||
model=model,
|
||||
critique=None,
|
||||
)
|
||||
if state:
|
||||
state.update("done", step=total_steps)
|
||||
return reply
|
||||
|
||||
angles = _open_ended_plan(
|
||||
prompt,
|
||||
fact_pack=fact_pack,
|
||||
@ -3757,41 +3707,52 @@ def _open_ended_multi(
|
||||
|
||||
def _open_ended_total_steps(mode: str) -> int:
|
||||
if mode == "fast":
|
||||
return 4
|
||||
return 2
|
||||
return 9
|
||||
|
||||
|
||||
def _fast_fact_lines(
|
||||
fact_lines: list[str],
|
||||
fact_meta: dict[str, dict[str, Any]],
|
||||
fact_ids: list[str],
|
||||
*,
|
||||
focus_tags: set[str],
|
||||
avoid_tags: set[str],
|
||||
limit: int = 10,
|
||||
) -> list[str]:
|
||||
if not fact_ids:
|
||||
return fact_lines
|
||||
selected = [
|
||||
line
|
||||
for line in fact_lines
|
||||
if fact_meta.get(line, {}).get("id") in set(fact_ids)
|
||||
]
|
||||
return selected or fact_lines
|
||||
if not fact_lines:
|
||||
return []
|
||||
selected: list[str] = []
|
||||
for idx, line in enumerate(fact_lines):
|
||||
fid = f"F{idx + 1}"
|
||||
tags = set(fact_meta.get(fid, {}).get("tags") or [])
|
||||
if focus_tags and not (focus_tags & tags):
|
||||
continue
|
||||
if avoid_tags and (avoid_tags & tags):
|
||||
continue
|
||||
selected.append(line)
|
||||
if len(selected) >= limit:
|
||||
break
|
||||
if selected:
|
||||
return selected
|
||||
trimmed = fact_lines[:limit]
|
||||
return trimmed or fact_lines
|
||||
|
||||
|
||||
def _open_ended_fast_single(
|
||||
prompt: str,
|
||||
*,
|
||||
fact_pack: str,
|
||||
history_lines: list[str],
|
||||
context: str,
|
||||
state: ThoughtState | None = None,
|
||||
model: str,
|
||||
) -> str:
|
||||
if state:
|
||||
state.update("drafting", step=2, note="summarizing")
|
||||
context = fact_pack
|
||||
state.update("drafting", step=1, note="summarizing")
|
||||
reply = _ollama_call(
|
||||
("atlasbot_fast", "atlasbot_fast"),
|
||||
prompt,
|
||||
context=context,
|
||||
use_history=False,
|
||||
system_override=_open_ended_system(),
|
||||
model=model,
|
||||
)
|
||||
if state:
|
||||
@ -3808,14 +3769,28 @@ def _open_ended_fast(
|
||||
history_lines: list[str],
|
||||
state: ThoughtState | None = None,
|
||||
) -> str:
|
||||
return _open_ended_multi(
|
||||
model = _model_for_mode("fast")
|
||||
subjective = _is_subjective_query(prompt)
|
||||
focus_tags = _preferred_tags_for_prompt(prompt)
|
||||
if not focus_tags and subjective:
|
||||
focus_tags = set(_ALLOWED_INSIGHT_TAGS)
|
||||
avoid_tags = _history_focus_tags(history_lines) if (subjective or _is_followup_query(prompt)) else set()
|
||||
selected_lines = _fast_fact_lines(
|
||||
fact_lines,
|
||||
fact_meta,
|
||||
focus_tags=focus_tags,
|
||||
avoid_tags=avoid_tags,
|
||||
)
|
||||
selected_meta = _fact_pack_meta(selected_lines)
|
||||
selected_pack = _fact_pack_text(selected_lines, selected_meta)
|
||||
context = _append_history_context(selected_pack, history_lines)
|
||||
if state:
|
||||
state.total_steps = _open_ended_total_steps("fast")
|
||||
return _open_ended_fast_single(
|
||||
prompt,
|
||||
fact_pack=fact_pack,
|
||||
fact_lines=fact_lines,
|
||||
fact_meta=fact_meta,
|
||||
history_lines=history_lines,
|
||||
mode="fast",
|
||||
context=context,
|
||||
state=state,
|
||||
model=model,
|
||||
)
|
||||
|
||||
|
||||
@ -3834,7 +3809,6 @@ def _open_ended_deep(
|
||||
fact_lines=fact_lines,
|
||||
fact_meta=fact_meta,
|
||||
history_lines=history_lines,
|
||||
mode="deep",
|
||||
state=state,
|
||||
)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user