dmChatbotBackend / src /agents /role_utils.py
github-actions
Auto deploy from GitHub
b1198f0
Raw
History Blame Contribute Delete
968 Bytes
import re
def classify_role(user_message: str) -> str | None:
"""Return an inferred role from the user's message using regex cues."""
text = (user_message or "").lower()
if re.search(r"\b(caregiver|care giver|caring for|supporting|helping)\b", text):
return "caregiver"
if re.search(r"\b(pregnant|pregnancy|gestational|pregnant woman|gestational diabetes)\b", text):
return "patient"
if re.search(r"\b(diet|nutrition|meal plan|glycemic|carbohydrate|food facts|calorie|keto|vegetarian|vegan|grocery|menu)\b", text):
return "dietary"
if re.search(r"\b(study|research|paper|trial|meta-analysis|randomized|cohort|evidence|data|epidemiology)\b", text):
return "researcher"
if re.search(r"\b(doctor|dr\.|physician|provider|clinician|prescription|diagnosis|treatment|protocol|dose|medication|management|hba1c|a1c|insulin regimen|therapy|medical advice)\b", text):
return "clinician"
return None