feat(bot): answer treatment questions from the clinical-guideline knowledge base
CI / ruff · pytest (pull_request) Successful in 1m30s
CI / ruff · pytest (pull_request) Successful in 1m30s
- menu button «Вопрос о лечении» -> kb.question -> rag.answer (KR quote + source) or «уточните у врача»; dose questions get a fixed doctor redirect - free text in idle that looks like a question (no check-in signals, not a drug question) -> knowledge base; no answer -> the usual support phrase - routing order unchanged: consent/safety first, side effects/quit/alcohol -> check-in, own drug -> med_qa (instruction only, SPEC §7 p.5) - question cues, small talk and texts in config/texts/knowledge.yaml; scrub placeholders before "что такое X" no longer hide the definition question Refs #64 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -47,6 +47,7 @@ from app.db import repo
|
||||
from app.dialog.contracts import Button, Event, Reply
|
||||
from app.dialog.flows import intake
|
||||
from app.dialog.flows.core import menu_reply
|
||||
from app.dialog.flows.knowledge import knowledge_answer, looks_like_question
|
||||
from app.dialog.flows.meds import (
|
||||
answer_question,
|
||||
checkin_of,
|
||||
@@ -423,11 +424,13 @@ async def _visit(ctx: Ctx, event: Event) -> Step:
|
||||
@trigger("text:idle", replace=True)
|
||||
async def _idle_text(ctx: Ctx, event: Event) -> Step:
|
||||
"""Free text outside the check-in: drug question → instruction excerpt; side effects / quit intent / alcohol
|
||||
→ today's check-in (the rules react); otherwise the neutral support phrase with the menu."""
|
||||
→ today's check-in (the rules react); another question → clinical guidelines (knowledge base); otherwise
|
||||
the neutral support phrase with the menu."""
|
||||
assert ctx.text is not None
|
||||
facts = await ctx.gateway.extract_checkin(ctx.text)
|
||||
if facts is None:
|
||||
return Step(replies=[menu_reply(ctx, await ctx.gateway.phrase("support"))])
|
||||
text = await knowledge_answer(ctx, explicit=False) if looks_like_question(ctx.text) else None
|
||||
return Step(replies=[menu_reply(ctx, text or await ctx.gateway.phrase("support"))])
|
||||
fields: dict[str, Any] = {}
|
||||
if facts.quit_intent:
|
||||
fields["quit_intent"] = True
|
||||
@@ -445,6 +448,8 @@ async def _idle_text(ctx: Ctx, event: Event) -> Step:
|
||||
await save_checkin(ctx, **fields)
|
||||
if text is None and facts.med_question and not facts.quit_intent:
|
||||
text = await answer_question(ctx, await current_prescription(ctx))
|
||||
if text is None and not fields and looks_like_question(ctx.text):
|
||||
text = await knowledge_answer(ctx, explicit=False) # general question → clinical guidelines (#64)
|
||||
if text is None:
|
||||
text = await ctx.gateway.phrase("support")
|
||||
return Step(replies=[menu_reply(ctx, text)], notify_monitoring=bool(fields or facts.side_effects))
|
||||
|
||||
Reference in New Issue
Block a user