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_lines: list[str],
|
||||||
fact_meta: dict[str, dict[str, Any]],
|
fact_meta: dict[str, dict[str, Any]],
|
||||||
history_lines: list[str],
|
history_lines: list[str],
|
||||||
mode: str,
|
|
||||||
state: ThoughtState | None = None,
|
state: ThoughtState | None = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
model = _model_for_mode(mode)
|
model = _model_for_mode("deep")
|
||||||
if mode == "fast":
|
total_steps = _open_ended_total_steps("deep")
|
||||||
total_steps = 4
|
|
||||||
else:
|
|
||||||
total_steps = 9
|
|
||||||
if state:
|
if state:
|
||||||
state.total_steps = total_steps
|
state.total_steps = total_steps
|
||||||
|
|
||||||
@ -3591,52 +3587,6 @@ def _open_ended_multi(
|
|||||||
focus_tags = set(_ALLOWED_INSIGHT_TAGS)
|
focus_tags = set(_ALLOWED_INSIGHT_TAGS)
|
||||||
avoid_tags = _history_focus_tags(history_lines) if (subjective or _is_followup_query(prompt)) else set()
|
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(
|
angles = _open_ended_plan(
|
||||||
prompt,
|
prompt,
|
||||||
fact_pack=fact_pack,
|
fact_pack=fact_pack,
|
||||||
@ -3757,41 +3707,52 @@ def _open_ended_multi(
|
|||||||
|
|
||||||
def _open_ended_total_steps(mode: str) -> int:
|
def _open_ended_total_steps(mode: str) -> int:
|
||||||
if mode == "fast":
|
if mode == "fast":
|
||||||
return 4
|
return 2
|
||||||
return 9
|
return 9
|
||||||
|
|
||||||
|
|
||||||
def _fast_fact_lines(
|
def _fast_fact_lines(
|
||||||
fact_lines: list[str],
|
fact_lines: list[str],
|
||||||
fact_meta: dict[str, dict[str, Any]],
|
fact_meta: dict[str, dict[str, Any]],
|
||||||
fact_ids: list[str],
|
*,
|
||||||
|
focus_tags: set[str],
|
||||||
|
avoid_tags: set[str],
|
||||||
|
limit: int = 10,
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
if not fact_ids:
|
if not fact_lines:
|
||||||
return fact_lines
|
return []
|
||||||
selected = [
|
selected: list[str] = []
|
||||||
line
|
for idx, line in enumerate(fact_lines):
|
||||||
for line in fact_lines
|
fid = f"F{idx + 1}"
|
||||||
if fact_meta.get(line, {}).get("id") in set(fact_ids)
|
tags = set(fact_meta.get(fid, {}).get("tags") or [])
|
||||||
]
|
if focus_tags and not (focus_tags & tags):
|
||||||
return selected or fact_lines
|
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(
|
def _open_ended_fast_single(
|
||||||
prompt: str,
|
prompt: str,
|
||||||
*,
|
*,
|
||||||
fact_pack: str,
|
context: str,
|
||||||
history_lines: list[str],
|
|
||||||
state: ThoughtState | None = None,
|
state: ThoughtState | None = None,
|
||||||
model: str,
|
model: str,
|
||||||
) -> str:
|
) -> str:
|
||||||
if state:
|
if state:
|
||||||
state.update("drafting", step=2, note="summarizing")
|
state.update("drafting", step=1, note="summarizing")
|
||||||
context = fact_pack
|
|
||||||
reply = _ollama_call(
|
reply = _ollama_call(
|
||||||
("atlasbot_fast", "atlasbot_fast"),
|
("atlasbot_fast", "atlasbot_fast"),
|
||||||
prompt,
|
prompt,
|
||||||
context=context,
|
context=context,
|
||||||
use_history=False,
|
use_history=False,
|
||||||
|
system_override=_open_ended_system(),
|
||||||
model=model,
|
model=model,
|
||||||
)
|
)
|
||||||
if state:
|
if state:
|
||||||
@ -3808,14 +3769,28 @@ def _open_ended_fast(
|
|||||||
history_lines: list[str],
|
history_lines: list[str],
|
||||||
state: ThoughtState | None = None,
|
state: ThoughtState | None = None,
|
||||||
) -> str:
|
) -> 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,
|
prompt,
|
||||||
fact_pack=fact_pack,
|
context=context,
|
||||||
fact_lines=fact_lines,
|
|
||||||
fact_meta=fact_meta,
|
|
||||||
history_lines=history_lines,
|
|
||||||
mode="fast",
|
|
||||||
state=state,
|
state=state,
|
||||||
|
model=model,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -3834,7 +3809,6 @@ def _open_ended_deep(
|
|||||||
fact_lines=fact_lines,
|
fact_lines=fact_lines,
|
||||||
fact_meta=fact_meta,
|
fact_meta=fact_meta,
|
||||||
history_lines=history_lines,
|
history_lines=history_lines,
|
||||||
mode="deep",
|
|
||||||
state=state,
|
state=state,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user