code-education-rag / src /utils.py
FabIndy's picture
Fix imports: use src package everywhere
247f65e
raw
history blame contribute delete
813 Bytes
# src/utils.py
from __future__ import annotations
from typing import Optional
from src.config import ARTICLE_ID_RE, LIST_TRIGGERS, FULLTEXT_TRIGGERS, EXPLAIN_TRIGGERS
def normalize_article_id(raw: str) -> str:
return (raw or "").strip().upper().replace(" ", "").replace(".", "-")
def extract_article_id(q: str) -> Optional[str]:
m = ARTICLE_ID_RE.search(q or "")
return normalize_article_id(m.group(1)) if m else None
def is_list_request(q: str) -> bool:
ql = (q or "").lower()
return any(t in ql for t in LIST_TRIGGERS)
def is_fulltext_request(q: str) -> bool:
ql = (q or "").lower()
return any(t in ql for t in FULLTEXT_TRIGGERS)
def is_synthesis_request(q: str) -> bool:
ql = (q or "").lower()
return any(t in ql for t in EXPLAIN_TRIGGERS)