fix(bot): chat agent — ГРЛС excerpts in drug check, questions with alcohol answered, retry, clearer logs
CI / ruff · pytest (pull_request) Successful in 2m13s
CI / ruff · pytest (pull_request) Successful in 2m13s
Live run through the API (Andrey, real OpenRouter): onset questions now answered from the instruction excerpt, «можно пиво?» reaches the agent although the check-in records alcohol, quit intent keeps the single rule reaction, findings are mentioned only for intake/combination questions, one retry on a provider error, provider error message logged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import re
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
from app.integrations.base import integrations
|
||||
from app.integrations.emias_record import PatientRecord, emias_records
|
||||
from app.llm.agent.drug_safety import check_patient, find_drug, load_db
|
||||
from app.llm.rag import retrieve
|
||||
@@ -183,10 +184,12 @@ async def _check(ctx: ToolContext, name: str) -> dict[str, Any]:
|
||||
if hit
|
||||
else "в примере состава этого вещества нет; состав зависит от производителя."
|
||||
)
|
||||
instruction = await _instruction(ctx, entry.inn)
|
||||
return {
|
||||
"found": True,
|
||||
"inn": entry.inn,
|
||||
"record": True,
|
||||
"instruction": instruction, # ГРЛС excerpts: onset, side effects, discontinuation, administration
|
||||
"findings": [f.model_dump() for f in findings],
|
||||
"intolerance_check": intolerance_check,
|
||||
"composition": comp.model_dump(exclude={"excipient_tags"}) if comp else None,
|
||||
@@ -196,5 +199,21 @@ async def _check(ctx: ToolContext, name: str) -> dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
INSTRUCTION_SECTIONS = ("onset", "side_effects", "discontinuation", "administration", "alcohol")
|
||||
|
||||
|
||||
async def _instruction(ctx: ToolContext, inn: str) -> dict[str, str]:
|
||||
"""ГРЛС excerpts for the drug (no doses in mg — see data/meds/grls)."""
|
||||
try:
|
||||
sections = await integrations.drug_info.sections(inn)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
log.error("drug_info unavailable: %s", type(exc).__name__)
|
||||
return {}
|
||||
out = {s.section: s.text for s in sections if s.section in INSTRUCTION_SECTIONS}
|
||||
if out:
|
||||
ctx.cite(sections[0].source.split(",")[0] + ": инструкция к препарату")
|
||||
return out
|
||||
|
||||
|
||||
def _json(data: Any) -> str:
|
||||
return json.dumps(data, ensure_ascii=False)
|
||||
|
||||
Reference in New Issue
Block a user