github-actions commited on
Commit ·
76962bf
1
Parent(s): 6c5879c
Auto deploy from GitHub
Browse files- .env.example +12 -0
- .gitignore +14 -0
- Dockerfile +18 -0
- app.py +177 -0
- data/Sources.md +14 -0
- data/full_test_set.json +1204 -0
- data/small_test_set.json +88 -0
- main.py +224 -0
- performance_reports/initial baseline openrouter_gpt_oss_20b.md +220 -0
- performance_reports/master_performance_report.md +6 -0
- performance_reports/report_openrouter_llama3.2_latest_2026-05-08_00-09-10.md +218 -0
- performance_reports/report_openrouter_openai_gpt-oss-20b_free_2026-04-28_15-06-07.md +220 -0
- requirements.txt +23 -0
- scripts/check_mongo.py +13 -0
- scripts/csvToJson.py +16 -0
- scripts/migrate_db.py +39 -0
- scripts/migrate_kb_mongo_to_supabase.py +82 -0
- scripts/migrate_mongo_to_supabase.py +104 -0
- src/agents/agent_instances.py +51 -0
- src/agents/agents.py +237 -0
- src/agents/cdm_agents.py +84 -0
- src/core/graph.py +323 -0
- src/core/graph_cdm.py +136 -0
- src/core/model_manager.py +46 -0
- src/core/state.py +37 -0
- src/mcp/server.py +93 -0
- src/prompts/ClinicalSpecialist_Diagnosis.txt +1 -0
- src/prompts/ClinicalSpecialist_General Clinical Support.txt +1 -0
- src/prompts/ClinicalSpecialist_General.txt +1 -0
- src/prompts/ClinicalSpecialist_Monitoring.txt +1 -0
- src/prompts/ClinicalSpecialist_Treatment.txt +1 -0
- src/prompts/DietarySpecialist.txt +10 -0
- src/prompts/IntentClassifier.txt +6 -0
- src/prompts/OutputMerger.txt +9 -0
- src/prompts/PatientLLM.txt +10 -0
- src/prompts/ResearchAgent.txt +10 -0
- src/prompts/ResponseValidator.txt +8 -0
- src/prompts/RoleClassifier.txt +10 -0
- src/prompts/SafetyCheck.txt +8 -0
- src/tools/dietary_tools.py +106 -0
- src/tools/fhir_memory.py +292 -0
- src/tools/patient_memory.py +100 -0
- src/tools/web_tools.py +9 -0
- src/utils/auth.py +46 -0
- src/utils/export_prompts.py +41 -0
- src/utils/kb_manager.py +77 -0
- src/utils/logger.py +29 -0
- src/utils/visualizer.py +121 -0
.env.example
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
OLLAMA_MODEL=llama3.2:latest
|
| 2 |
+
|
| 3 |
+
# Provider Selection (ollama or openrouter)
|
| 4 |
+
MODEL_PROVIDER=openrouter
|
| 5 |
+
OPENROUTER_API_KEY=apiKey
|
| 6 |
+
OPENROUTER_MODEL_NAME=openai/gpt-oss-20b:free
|
| 7 |
+
|
| 8 |
+
# Supabase Configuration
|
| 9 |
+
SUPABASE_URL=your_project_url
|
| 10 |
+
SUPABASE_KEY=your_anon_key
|
| 11 |
+
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key
|
| 12 |
+
SUPABASE_JWT_SECRET=your_jwt_secret
|
.gitignore
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__
|
| 2 |
+
test
|
| 3 |
+
research
|
| 4 |
+
data/chroma_db
|
| 5 |
+
data/sources
|
| 6 |
+
data/csvFiles
|
| 7 |
+
|
| 8 |
+
*.env
|
| 9 |
+
*.log
|
| 10 |
+
*.pyc
|
| 11 |
+
.venv/*
|
| 12 |
+
.vscode/*
|
| 13 |
+
.sqlite3
|
| 14 |
+
.db
|
Dockerfile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use an official Python runtime
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Set the working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy requirements and install
|
| 8 |
+
COPY requirements.txt .
|
| 9 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 10 |
+
|
| 11 |
+
# Copy the rest of the backend files
|
| 12 |
+
COPY . .
|
| 13 |
+
|
| 14 |
+
# Expose the mandatory Hugging Face port
|
| 15 |
+
EXPOSE 7860
|
| 16 |
+
|
| 17 |
+
# Run the FastAPI server. Update "main:app" to "app:app" if app.py is your true entrypoint.
|
| 18 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, Depends
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from typing import List, Dict, Any, Optional
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
from langchain_core.messages import HumanMessage, AIMessage, ToolMessage
|
| 8 |
+
from src.utils.logger import setup_logger
|
| 9 |
+
from src.utils.auth import get_current_user, get_active_user
|
| 10 |
+
|
| 11 |
+
# Absolute import management
|
| 12 |
+
project_root = os.path.dirname(os.path.abspath(__file__))
|
| 13 |
+
if project_root not in sys.path:
|
| 14 |
+
sys.path.append(project_root)
|
| 15 |
+
|
| 16 |
+
from src.core.graph import medical_pipeline
|
| 17 |
+
from src.core.graph_cdm import cdm_pipeline
|
| 18 |
+
from src.core.model_manager import model_manager
|
| 19 |
+
from src.agents.agent_instances import update_all_agents_llm
|
| 20 |
+
from src.tools.fhir_memory import (
|
| 21 |
+
get_patient_summary_fhir,
|
| 22 |
+
save_observation,
|
| 23 |
+
save_patient,
|
| 24 |
+
create_session,
|
| 25 |
+
get_sessions_by_patient,
|
| 26 |
+
get_chat_history_by_session,
|
| 27 |
+
save_chat_as_fhir
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
load_dotenv()
|
| 31 |
+
logger = setup_logger("FastAPI")
|
| 32 |
+
|
| 33 |
+
app = FastAPI(title="Medical AI Backend")
|
| 34 |
+
|
| 35 |
+
class ChatMessage(BaseModel):
|
| 36 |
+
role: str
|
| 37 |
+
content: str
|
| 38 |
+
|
| 39 |
+
class PipelineRequest(BaseModel):
|
| 40 |
+
prompt: str
|
| 41 |
+
patient_id: Optional[str] = None
|
| 42 |
+
session_id: Optional[str] = None
|
| 43 |
+
mode: str = "Standard Triage" # "Standard Triage" or "CDM Proactive"
|
| 44 |
+
history: List[Dict[str, Any]] = []
|
| 45 |
+
|
| 46 |
+
class PipelineResponse(BaseModel):
|
| 47 |
+
messages: List[Dict[str, Any]]
|
| 48 |
+
final_state: Dict[str, Any]
|
| 49 |
+
session_id: Optional[str]
|
| 50 |
+
|
| 51 |
+
def convert_to_langchain_messages(history):
|
| 52 |
+
messages = []
|
| 53 |
+
for msg in history:
|
| 54 |
+
if msg["role"] == "user":
|
| 55 |
+
messages.append(HumanMessage(content=msg["content"]))
|
| 56 |
+
elif msg["role"] == "assistant":
|
| 57 |
+
messages.append(AIMessage(content=msg["content"]))
|
| 58 |
+
return messages
|
| 59 |
+
|
| 60 |
+
@app.post("/process", response_model=PipelineResponse)
|
| 61 |
+
async def process_pipeline(request: PipelineRequest, user_id: str = Depends(get_active_user)):
|
| 62 |
+
# user_id from token is used as the default patient_id if not provided
|
| 63 |
+
patient_id = request.patient_id or user_id
|
| 64 |
+
logger.info(f"Processing request for user: {user_id}, patient: {patient_id}")
|
| 65 |
+
|
| 66 |
+
# Session handling
|
| 67 |
+
session_id = request.session_id
|
| 68 |
+
if not session_id:
|
| 69 |
+
session_id = create_session.invoke({"patient_id": patient_id, "title": f"Session {datetime.datetime.now().strftime('%Y-%m-%d %H:%M')}"})
|
| 70 |
+
history = request.history
|
| 71 |
+
else:
|
| 72 |
+
# If session_id is provided but history is empty, fetch from Supabase
|
| 73 |
+
history = request.history
|
| 74 |
+
if not history:
|
| 75 |
+
logger.info(f"Fetching history for session: {session_id}")
|
| 76 |
+
raw_history = get_chat_history_by_session.invoke({"session_id": session_id})
|
| 77 |
+
# Convert FHIR Communication resources back to simple role/content dicts
|
| 78 |
+
for comm in raw_history:
|
| 79 |
+
payload = comm.get("payload", [])
|
| 80 |
+
for item in payload:
|
| 81 |
+
content = item.get("contentString", "")
|
| 82 |
+
if ":" in content:
|
| 83 |
+
role, text = content.split(":", 1)
|
| 84 |
+
history.append({"role": role.strip(), "content": text.strip()})
|
| 85 |
+
|
| 86 |
+
# Select pipeline
|
| 87 |
+
active_pipeline = cdm_pipeline if request.mode == "CDM Proactive" else medical_pipeline
|
| 88 |
+
|
| 89 |
+
# Prepare initial state
|
| 90 |
+
enhanced_prompt = f"[System: User's Patient ID is {patient_id}]\n\n{request.prompt}"
|
| 91 |
+
initial_messages = convert_to_langchain_messages(history)
|
| 92 |
+
initial_messages.append(HumanMessage(content=enhanced_prompt))
|
| 93 |
+
|
| 94 |
+
initial_state = {
|
| 95 |
+
"messages": initial_messages,
|
| 96 |
+
"user_role": "unknown",
|
| 97 |
+
"intent_type": "unknown",
|
| 98 |
+
"is_valid": False,
|
| 99 |
+
"is_safe": False,
|
| 100 |
+
"attempts": 0,
|
| 101 |
+
"clinician_outputs": [],
|
| 102 |
+
"patient_response": "",
|
| 103 |
+
"research_output": "",
|
| 104 |
+
"sources": [],
|
| 105 |
+
"logs": [],
|
| 106 |
+
"metrics": []
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
initial_state["patient_id"] = patient_id
|
| 110 |
+
|
| 111 |
+
try:
|
| 112 |
+
final_state = await active_pipeline.ainvoke(initial_state)
|
| 113 |
+
|
| 114 |
+
# Save chat history as FHIR Communication linked to session
|
| 115 |
+
new_msgs_for_fhir = []
|
| 116 |
+
for msg in final_state["messages"][len(initial_messages)-1:]:
|
| 117 |
+
role = "user" if isinstance(msg, HumanMessage) else "assistant"
|
| 118 |
+
new_msgs_for_fhir.append({"role": role, "content": msg.content})
|
| 119 |
+
|
| 120 |
+
save_chat_as_fhir.invoke({"patient_id": patient_id, "messages": new_msgs_for_fhir, "session_id": session_id})
|
| 121 |
+
|
| 122 |
+
# Format messages for response
|
| 123 |
+
resp_messages = []
|
| 124 |
+
for msg in final_state["messages"][len(initial_messages):]:
|
| 125 |
+
msg_type = "assistant" if isinstance(msg, AIMessage) else "tool" if isinstance(msg, ToolMessage) else "user"
|
| 126 |
+
resp_messages.append({
|
| 127 |
+
"role": msg_type,
|
| 128 |
+
"content": msg.content,
|
| 129 |
+
"type": msg.__class__.__name__
|
| 130 |
+
})
|
| 131 |
+
|
| 132 |
+
return PipelineResponse(
|
| 133 |
+
messages=resp_messages,
|
| 134 |
+
final_state={k: v for k, v in final_state.items() if k != "messages"},
|
| 135 |
+
session_id=session_id
|
| 136 |
+
)
|
| 137 |
+
except Exception as e:
|
| 138 |
+
logger.error(f"Pipeline error: {str(e)}")
|
| 139 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 140 |
+
|
| 141 |
+
@app.get("/sessions")
|
| 142 |
+
async def list_sessions(user_id: str = Depends(get_active_user)):
|
| 143 |
+
return get_sessions_by_patient.invoke({"patient_id": user_id})
|
| 144 |
+
|
| 145 |
+
@app.get("/sessions/{session_id}/history")
|
| 146 |
+
async def get_session_history(session_id: str, user_id: str = Depends(get_active_user)):
|
| 147 |
+
return get_chat_history_by_session.invoke({"session_id": session_id})
|
| 148 |
+
|
| 149 |
+
@app.get("/patient/summary")
|
| 150 |
+
async def get_patient_summary(user_id: str = Depends(get_active_user)):
|
| 151 |
+
try:
|
| 152 |
+
summary = get_patient_summary_fhir.invoke({"patient_id": user_id})
|
| 153 |
+
return summary
|
| 154 |
+
except Exception as e:
|
| 155 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 156 |
+
|
| 157 |
+
@app.post("/patient/seed")
|
| 158 |
+
async def seed_patient_data(user_id: str = Depends(get_active_user)):
|
| 159 |
+
try:
|
| 160 |
+
save_patient.invoke({"patient_id": user_id, "name": "Authenticated Patient"})
|
| 161 |
+
save_observation.invoke({"patient_id": user_id, "value": 110, "unit": "mg/dL", "display": "Glucose", "loinc_code": "2339-0"})
|
| 162 |
+
return {"status": "success", "message": "Data seeded for user"}
|
| 163 |
+
except Exception as e:
|
| 164 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 165 |
+
|
| 166 |
+
@app.post("/config/llm")
|
| 167 |
+
async def set_llm_provider(provider: str, user_id: str = Depends(get_current_user)):
|
| 168 |
+
try:
|
| 169 |
+
update_all_agents_llm(provider)
|
| 170 |
+
return {"status": "success", "provider": model_manager.provider}
|
| 171 |
+
except Exception as e:
|
| 172 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 173 |
+
|
| 174 |
+
if __name__ == "__main__":
|
| 175 |
+
import uvicorn
|
| 176 |
+
import datetime
|
| 177 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
data/Sources.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
https://www.nin.res.in/downloads/DietaryGuidelinesforNINwebsite.pdf
|
| 2 |
+
https://fdc.nal.usda.gov
|
| 3 |
+
https://www.fao.org/nutrition/education/food-dietary-guidelines/regions/countries/india/en/
|
| 4 |
+
https://timesofindia.indiatimes.com/life-style/health-fitness/diet/want-to-never-fall-sick-this-is-the-perfect-diet-according-to-the-indian-council-of-medical-research-icmr/articleshow/125132983.cms
|
| 5 |
+
https://www.who.int/news-room/fact-sheets/detail/healthy-diet
|
| 6 |
+
https://www.fao.org/nutrition/nutrition-education/food-dietary-guidelines/en/
|
| 7 |
+
https://www.dietaryguidelines.gov/sites/default/files/2020-12/Dietary_Guidelines_for_Americans_2020-2025.pdf
|
| 8 |
+
https://www.efsa.europa.eu/en/safe2eat/your-nutrition-needs
|
| 9 |
+
https://www.who.int/teams/nutrition-and-food-safety/databases
|
| 10 |
+
https://www.nal.usda.gov/human-nutrition-and-food-safety/food-composition
|
| 11 |
+
https://www.ncbi.nlm.nih.gov/books/NBK217716/
|
| 12 |
+
https://nutritionsource.hsph.harvard.edu/vitamins/
|
| 13 |
+
https://pmc.ncbi.nlm.nih.gov/articles/PMC12550444/
|
| 14 |
+
https://www.oncolink.org/blogs/web-sites-for-reliable-health-and-nutrition-information
|
data/full_test_set.json
ADDED
|
@@ -0,0 +1,1204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"questions": [
|
| 3 |
+
{
|
| 4 |
+
"id": 1,
|
| 5 |
+
"question": "I've been feeling really thirsty and urinating a lot lately, could that be a sign of diabetes?",
|
| 6 |
+
"intent": "general",
|
| 7 |
+
"role": "patient"
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"id": 2,
|
| 11 |
+
"question": "What is the optimal HbA1c target for a patient with Type 2 diabetes who has just started insulin therapy?",
|
| 12 |
+
"intent": "treatment",
|
| 13 |
+
"role": "clinician"
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"id": 3,
|
| 17 |
+
"question": "I've been taking metformin for my polycystic ovary syndrome (PCOS), but I'm experiencing some side effects - can you help me weigh the benefits and risks?",
|
| 18 |
+
"intent": "general",
|
| 19 |
+
"role": "patient"
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"id": 4,
|
| 23 |
+
"question": "What is the recommended diet for a patient with diabetes who has just started an intensive insulin regimen?",
|
| 24 |
+
"intent": "general",
|
| 25 |
+
"role": "dietitian"
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"id": 5,
|
| 29 |
+
"question": "I'm planning to start a new exercise program to manage my blood sugar levels - what types of exercises are recommended for patients with diabetes?",
|
| 30 |
+
"intent": "general",
|
| 31 |
+
"role": "patient"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"id": 6,
|
| 35 |
+
"question": "I've been experiencing frequent urination and my hands are always cold, but I haven't had any symptoms that would indicate a heart attack or stroke. Is this related to diabetes?",
|
| 36 |
+
"intent": "general",
|
| 37 |
+
"role": "patient"
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"id": 7,
|
| 41 |
+
"question": "My doctor just told me that my HbA1c levels are higher than normal and I need to start taking insulin every day. What are the different types of insulin and how do I know which one is right for me?",
|
| 42 |
+
"intent": "general",
|
| 43 |
+
"role": "patient"
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"id": 8,
|
| 47 |
+
"question": "I've been tracking my glucose levels using a continuous glucose monitor, but I'm not sure what the normal range is for me. Can you tell me what this information means and how often I should check it?",
|
| 48 |
+
"intent": "general",
|
| 49 |
+
"role": "patient"
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"id": 9,
|
| 53 |
+
"question": "I've been reading about different diets for people with diabetes, but I'm not sure which one is best. Can you recommend a low-carb diet and explain how it will help me manage my blood sugar levels?",
|
| 54 |
+
"intent": "general",
|
| 55 |
+
"role": "researcher"
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"id": 10,
|
| 59 |
+
"question": "My friend just got diagnosed with Type 2 diabetes, but she's not sure what the difference is between metformin and pioglitazone. Can you explain how these medications work and which one might be better for her?",
|
| 60 |
+
"intent": "treatment",
|
| 61 |
+
"role": "clinician"
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"id": 11,
|
| 65 |
+
"question": "I've been experiencing frequent urination and my hands feel numb. Is this related to my diabetes?",
|
| 66 |
+
"intent": "general",
|
| 67 |
+
"role": "patient"
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"id": 12,
|
| 71 |
+
"question": "What is the recommended daily intake of carbohydrates for someone with Type 1 diabetes who is trying to lose weight?",
|
| 72 |
+
"intent": "general",
|
| 73 |
+
"role": "dietitian"
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"id": 13,
|
| 77 |
+
"question": "My blood glucose levels have been consistently high since starting a new medication. Can you explain why this might be happening and what I can do about it?",
|
| 78 |
+
"intent": "general",
|
| 79 |
+
"role": "patient"
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"id": 14,
|
| 83 |
+
"question": "I've been prescribed insulin glargine for my Type 2 diabetes, but I'm having trouble injecting it correctly. Can you show me how to administer this type of insulin?",
|
| 84 |
+
"intent": "general",
|
| 85 |
+
"role": "patient"
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"id": 15,
|
| 89 |
+
"question": "A recent study suggests that incorporating more plant-based meals into your diet can help lower blood sugar levels in people with diabetes. Can you provide me with some examples of healthy, diabetic-friendly recipes?",
|
| 90 |
+
"intent": "general",
|
| 91 |
+
"role": "researcher"
|
| 92 |
+
},
|
| 93 |
+
{
|
| 94 |
+
"id": 16,
|
| 95 |
+
"question": "My mother was recently diagnosed with Type 2 diabetes, and I'm worried about her risk of complications. What are the main things she needs to watch out for?",
|
| 96 |
+
"intent": "general",
|
| 97 |
+
"role": "patient"
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
"id": 17,
|
| 101 |
+
"question": "I've been taking metformin as prescribed by my doctor, but I'm still experiencing high blood sugar levels. Can you explain why this is happening and what else my doctor might recommend?",
|
| 102 |
+
"intent": "general",
|
| 103 |
+
"role": "patient"
|
| 104 |
+
},
|
| 105 |
+
{
|
| 106 |
+
"id": 18,
|
| 107 |
+
"question": "I've noticed that I've been getting really thirsty and urinating a lot more than usual. Could this be a sign of diabetes, or is there another explanation?",
|
| 108 |
+
"intent": "general",
|
| 109 |
+
"role": "patient"
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"id": 19,
|
| 113 |
+
"question": "I'm planning to start a new diet that's high in sugar and low in fiber. Will this impact my risk of developing Type 2 diabetes, and are there any specific foods I should avoid?",
|
| 114 |
+
"intent": "general",
|
| 115 |
+
"role": "patient"
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"id": 20,
|
| 119 |
+
"question": "My doctor mentioned that I should monitor my blood sugar levels more closely. Can you explain why this is important and what tools or apps can help me do so accurately?",
|
| 120 |
+
"intent": "general",
|
| 121 |
+
"role": "patient"
|
| 122 |
+
},
|
| 123 |
+
{
|
| 124 |
+
"id": 21,
|
| 125 |
+
"question": "I've been experiencing excessive thirst and urination lately. What could be the possible cause, Doctor?",
|
| 126 |
+
"intent": "general",
|
| 127 |
+
"role": "patient"
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"id": 22,
|
| 131 |
+
"question": "My doctor has prescribed metformin for my Type 2 diabetes. Can you explain how this medication works and its potential side effects?",
|
| 132 |
+
"intent": "general",
|
| 133 |
+
"role": "patient"
|
| 134 |
+
},
|
| 135 |
+
{
|
| 136 |
+
"id": 23,
|
| 137 |
+
"question": "I'm planning to start a new exercise routine to manage my blood sugar levels better. What types of exercises are recommended for diabetics, and how often should I aim to work out?",
|
| 138 |
+
"intent": "general",
|
| 139 |
+
"role": "patient"
|
| 140 |
+
},
|
| 141 |
+
{
|
| 142 |
+
"id": 24,
|
| 143 |
+
"question": "I've been experiencing frequent episodes of hypoglycemia despite taking my insulin as prescribed. Can you suggest any lifestyle changes or adjustments to my medication regimen that might help prevent these episodes?",
|
| 144 |
+
"intent": "general",
|
| 145 |
+
"role": "patient"
|
| 146 |
+
},
|
| 147 |
+
{
|
| 148 |
+
"id": 25,
|
| 149 |
+
"question": "What are the most effective dietary habits for managing diabetes, and how can I ensure I'm getting enough nutrients while following a strict glycemic index diet?",
|
| 150 |
+
"intent": "general",
|
| 151 |
+
"role": "dietitian"
|
| 152 |
+
},
|
| 153 |
+
{
|
| 154 |
+
"id": 26,
|
| 155 |
+
"question": "I've been experiencing frequent urination and my hands are feeling numb sometimes, do you think I could have diabetes?",
|
| 156 |
+
"intent": "general",
|
| 157 |
+
"role": "patient"
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"id": 27,
|
| 161 |
+
"question": "My doctor has prescribed metformin for my Type 1 diabetes. How often should I check my blood glucose levels?",
|
| 162 |
+
"intent": "general",
|
| 163 |
+
"role": "patient"
|
| 164 |
+
},
|
| 165 |
+
{
|
| 166 |
+
"id": 28,
|
| 167 |
+
"question": "What is the ideal HbA1c target range for a patient with newly diagnosed type 2 diabetes, and how can we monitor it?",
|
| 168 |
+
"intent": "diagnosis",
|
| 169 |
+
"role": "clinician"
|
| 170 |
+
},
|
| 171 |
+
{
|
| 172 |
+
"id": 29,
|
| 173 |
+
"question": "I've been eating a lot of sweet dishes during festivals. How will this affect my blood sugar levels, and what can I do to manage them?",
|
| 174 |
+
"intent": "general",
|
| 175 |
+
"role": "patient"
|
| 176 |
+
},
|
| 177 |
+
{
|
| 178 |
+
"id": 30,
|
| 179 |
+
"question": "Are there any clinical trials or studies currently underway for new diabetes medications? Can you provide more information on DPP-4 inhibitors?",
|
| 180 |
+
"intent": "general",
|
| 181 |
+
"role": "researcher"
|
| 182 |
+
},
|
| 183 |
+
{
|
| 184 |
+
"id": 31,
|
| 185 |
+
"question": "I've been experiencing frequent urination and my hands are shaking a lot, what could be causing these symptoms?",
|
| 186 |
+
"intent": "general",
|
| 187 |
+
"role": "patient"
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"id": 32,
|
| 191 |
+
"question": "My HbA1c level is 8.5%, I'm currently on metformin and taking insulin twice a day, what are my next steps to better manage my blood sugar?",
|
| 192 |
+
"intent": "general",
|
| 193 |
+
"role": "patient"
|
| 194 |
+
},
|
| 195 |
+
{
|
| 196 |
+
"id": 33,
|
| 197 |
+
"question": "I've been told I have gestational diabetes, what dietary changes can I make to reduce my risk of complications during pregnancy?",
|
| 198 |
+
"intent": "general",
|
| 199 |
+
"role": "pregnant woman"
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"id": 34,
|
| 203 |
+
"question": "My doctor wants me to start monitoring my blood glucose levels more regularly, what type of meter and test strips should I use?",
|
| 204 |
+
"intent": "general",
|
| 205 |
+
"role": "patient"
|
| 206 |
+
},
|
| 207 |
+
{
|
| 208 |
+
"id": 35,
|
| 209 |
+
"question": "I've been reading about the benefits of a low-carb diet for managing diabetes, but I'm not sure if it's safe for me to follow a keto diet. Can you advise on how to incorporate this into my existing treatment plan?",
|
| 210 |
+
"intent": "general",
|
| 211 |
+
"role": "patient"
|
| 212 |
+
},
|
| 213 |
+
{
|
| 214 |
+
"id": 36,
|
| 215 |
+
"question": "I've been experiencing excessive thirst and urination lately, along with blurred vision. Could these be symptoms of diabetes? What's the first step I should take?",
|
| 216 |
+
"intent": "general",
|
| 217 |
+
"role": "patient"
|
| 218 |
+
},
|
| 219 |
+
{
|
| 220 |
+
"id": 37,
|
| 221 |
+
"question": "My doctor has prescribed metformin to help lower my HbA1c levels. Can you walk me through how this medication works and what I can expect from the treatment?",
|
| 222 |
+
"intent": "general",
|
| 223 |
+
"role": "patient"
|
| 224 |
+
},
|
| 225 |
+
{
|
| 226 |
+
"id": 38,
|
| 227 |
+
"question": "I've been tracking my blood glucose levels for a few weeks now, but I'm still struggling to maintain a consistent target range. Do you have any tips for improving insulin sensitivity?",
|
| 228 |
+
"intent": "general",
|
| 229 |
+
"role": "patient"
|
| 230 |
+
},
|
| 231 |
+
{
|
| 232 |
+
"id": 39,
|
| 233 |
+
"question": "I've recently started incorporating more plant-based meals into my diet, but I'm worried that it might not be suitable for someone with diabetes. Can you recommend some healthy Indian dishes that won't spike my blood sugar levels?",
|
| 234 |
+
"intent": "general",
|
| 235 |
+
"role": "patient"
|
| 236 |
+
},
|
| 237 |
+
{
|
| 238 |
+
"id": 40,
|
| 239 |
+
"question": "I've been diagnosed with diabetic ketoacidosis (DKA). What are the warning signs I should look out for, and how can I get immediate medical attention if I experience them?",
|
| 240 |
+
"intent": "general",
|
| 241 |
+
"role": "patient"
|
| 242 |
+
},
|
| 243 |
+
{
|
| 244 |
+
"id": 41,
|
| 245 |
+
"question": "I've been experiencing numbness in my hands for the past few days, could it be related to my diabetes?",
|
| 246 |
+
"intent": "general",
|
| 247 |
+
"role": "patient"
|
| 248 |
+
},
|
| 249 |
+
{
|
| 250 |
+
"id": 42,
|
| 251 |
+
"question": "What are the benefits of using a continuous glucose monitor (CGM) versus traditional blood glucose meters?",
|
| 252 |
+
"intent": "general",
|
| 253 |
+
"role": "researcher"
|
| 254 |
+
},
|
| 255 |
+
{
|
| 256 |
+
"id": 43,
|
| 257 |
+
"question": "Can you recommend some low-carb Indian recipes that I can easily prepare for my diabetes diet?",
|
| 258 |
+
"intent": "general",
|
| 259 |
+
"role": "patient"
|
| 260 |
+
},
|
| 261 |
+
{
|
| 262 |
+
"id": 44,
|
| 263 |
+
"question": "I've been diagnosed with gestational diabetes and am experiencing high blood sugar levels. What are the immediate steps I should take?",
|
| 264 |
+
"intent": "general",
|
| 265 |
+
"role": "pregnant woman"
|
| 266 |
+
},
|
| 267 |
+
{
|
| 268 |
+
"id": 45,
|
| 269 |
+
"question": "How does metformin work in treating type 2 diabetes, and what are its common side effects?",
|
| 270 |
+
"intent": "treatment",
|
| 271 |
+
"role": "clinician"
|
| 272 |
+
},
|
| 273 |
+
{
|
| 274 |
+
"id": 46,
|
| 275 |
+
"question": "I've been experiencing frequent urination and my hands are feeling all tingly, doctor can you tell me what's causing this?",
|
| 276 |
+
"intent": "general",
|
| 277 |
+
"role": "patient"
|
| 278 |
+
},
|
| 279 |
+
{
|
| 280 |
+
"id": 47,
|
| 281 |
+
"question": "What is the optimal HbA1c target for a patient with newly diagnosed Type 2 diabetes and I'm not taking any medications yet?",
|
| 282 |
+
"intent": "treatment",
|
| 283 |
+
"role": "clinician"
|
| 284 |
+
},
|
| 285 |
+
{
|
| 286 |
+
"id": 48,
|
| 287 |
+
"question": "I've been tracking my daily glucose levels using my insulin pump, can you help me understand what this trend graph is telling me?",
|
| 288 |
+
"intent": "general",
|
| 289 |
+
"role": "patient"
|
| 290 |
+
},
|
| 291 |
+
{
|
| 292 |
+
"id": 49,
|
| 293 |
+
"question": "What are the latest guidelines for carbohydrate counting in patients with diabetes and how does it differ from traditional meal planning?",
|
| 294 |
+
"intent": "general",
|
| 295 |
+
"role": "researcher"
|
| 296 |
+
},
|
| 297 |
+
{
|
| 298 |
+
"id": 50,
|
| 299 |
+
"question": "I've been experiencing extreme thirst and hunger, doctor I think I might be developing ketoacidosis can you tell me what to do?",
|
| 300 |
+
"intent": "general",
|
| 301 |
+
"role": "patient"
|
| 302 |
+
},
|
| 303 |
+
{
|
| 304 |
+
"id": 51,
|
| 305 |
+
"question": "My doctor says I need to monitor my blood sugar levels more closely, but what's the normal range for someone like me with Type 2 diabetes?",
|
| 306 |
+
"intent": "general",
|
| 307 |
+
"role": "patient"
|
| 308 |
+
},
|
| 309 |
+
{
|
| 310 |
+
"id": 52,
|
| 311 |
+
"question": "I've been prescribed metformin for my diabetes, but I'm having side effects - how can I minimize these while still taking the medication as directed?",
|
| 312 |
+
"intent": "general",
|
| 313 |
+
"role": "patient"
|
| 314 |
+
},
|
| 315 |
+
{
|
| 316 |
+
"id": 53,
|
| 317 |
+
"question": "My friend has just been diagnosed with Gestational Diabetes and is feeling really overwhelmed. What are some key lifestyle changes she can make to manage her condition during pregnancy?",
|
| 318 |
+
"intent": "diagnosis",
|
| 319 |
+
"role": "clinician"
|
| 320 |
+
},
|
| 321 |
+
{
|
| 322 |
+
"id": 54,
|
| 323 |
+
"question": "I've noticed I'm experiencing frequent urination at night, which is really disrupting my sleep. What could be causing this and are there any remedies or treatments available?",
|
| 324 |
+
"intent": "general",
|
| 325 |
+
"role": "patient"
|
| 326 |
+
},
|
| 327 |
+
{
|
| 328 |
+
"id": 55,
|
| 329 |
+
"question": "A recent study suggests that a specific dietary approach may help manage blood sugar levels in people with Type 1 diabetes. Can you tell me more about it and whether I should try it?",
|
| 330 |
+
"intent": "general",
|
| 331 |
+
"role": "researcher"
|
| 332 |
+
},
|
| 333 |
+
{
|
| 334 |
+
"id": 56,
|
| 335 |
+
"question": "Doc, I've been experiencing weird tingling sensations in my hands and feet since my diagnosis with Type 2 diabetes. Can you help me figure out if it's related to my insulin dosages?",
|
| 336 |
+
"intent": "general",
|
| 337 |
+
"role": "patient"
|
| 338 |
+
},
|
| 339 |
+
{
|
| 340 |
+
"id": 57,
|
| 341 |
+
"question": "How often should I check my blood glucose levels, and what are the normal ranges for a person with Type 1 diabetes on an insulin pump?",
|
| 342 |
+
"intent": "monitoring",
|
| 343 |
+
"role": "clinician"
|
| 344 |
+
},
|
| 345 |
+
{
|
| 346 |
+
"id": 58,
|
| 347 |
+
"question": "I've been prescribed metformin for my gestational diabetes. Can you explain how it works and what I can expect from the treatment?",
|
| 348 |
+
"intent": "general",
|
| 349 |
+
"role": "patient"
|
| 350 |
+
},
|
| 351 |
+
{
|
| 352 |
+
"id": 59,
|
| 353 |
+
"question": "If my HbA1c levels are consistently above 8%, does that mean I have diabetic neuropathy, or is it just a sign of poor blood sugar control?",
|
| 354 |
+
"intent": "general",
|
| 355 |
+
"role": "patient"
|
| 356 |
+
},
|
| 357 |
+
{
|
| 358 |
+
"id": 60,
|
| 359 |
+
"question": "What's the best way to incorporate more plant-based meals into my diet while managing Type 2 diabetes, and are there any specific foods to limit or avoid?",
|
| 360 |
+
"intent": "general",
|
| 361 |
+
"role": "researcher"
|
| 362 |
+
},
|
| 363 |
+
{
|
| 364 |
+
"id": 61,
|
| 365 |
+
"question": "I've been experiencing recurring chest pains when I eat, and my blood sugar levels have been spiking after meals. Is this a sign of diabetic cardiomyopathy?",
|
| 366 |
+
"intent": "general",
|
| 367 |
+
"role": "patient"
|
| 368 |
+
},
|
| 369 |
+
{
|
| 370 |
+
"id": 62,
|
| 371 |
+
"question": "My doctor prescribed metformin for my Type 2 diabetes, but I'm having trouble managing my side effects - bloating and gas. Can you suggest alternative medications or dosing strategies?",
|
| 372 |
+
"intent": "general",
|
| 373 |
+
"role": "patient"
|
| 374 |
+
},
|
| 375 |
+
{
|
| 376 |
+
"id": 63,
|
| 377 |
+
"question": "I've noticed that my blood glucose levels tend to drop significantly at night, even when I'm sleeping - is this a normal variation or could it be a sign of an underlying issue?",
|
| 378 |
+
"intent": "general",
|
| 379 |
+
"role": "patient"
|
| 380 |
+
},
|
| 381 |
+
{
|
| 382 |
+
"id": 64,
|
| 383 |
+
"question": "I've been reading about the benefits of a low-carb diet for diabetes management, but I'm not sure how to incorporate it into my daily meal planning - can you provide some tips?",
|
| 384 |
+
"intent": "general",
|
| 385 |
+
"role": "patient"
|
| 386 |
+
},
|
| 387 |
+
{
|
| 388 |
+
"id": 65,
|
| 389 |
+
"question": "I have a family history of Type 2 diabetes and am concerned about my risk - what are the most effective lifestyle modifications I can make to reduce my risk, and when should I consider genetic testing?",
|
| 390 |
+
"intent": "general",
|
| 391 |
+
"role": "patient"
|
| 392 |
+
},
|
| 393 |
+
{
|
| 394 |
+
"id": 66,
|
| 395 |
+
"question": "I've been experiencing frequent urination and blurred vision. Is this a sign of diabetes?",
|
| 396 |
+
"intent": "general",
|
| 397 |
+
"role": "patient"
|
| 398 |
+
},
|
| 399 |
+
{
|
| 400 |
+
"id": 67,
|
| 401 |
+
"question": "My HbA1c levels are consistently above 7%. What is the best course of action for me to take?",
|
| 402 |
+
"intent": "general",
|
| 403 |
+
"role": "patient"
|
| 404 |
+
},
|
| 405 |
+
{
|
| 406 |
+
"id": 68,
|
| 407 |
+
"question": "I've been taking insulin twice a day, but I'm still experiencing high blood sugar levels. Can you help me adjust my dosage?",
|
| 408 |
+
"intent": "general",
|
| 409 |
+
"role": "patient"
|
| 410 |
+
},
|
| 411 |
+
{
|
| 412 |
+
"id": 69,
|
| 413 |
+
"question": "Can you explain the benefits and risks of switching from metformin to sitagliptin for Type 2 diabetes management?",
|
| 414 |
+
"intent": "treatment",
|
| 415 |
+
"role": "clinician"
|
| 416 |
+
},
|
| 417 |
+
{
|
| 418 |
+
"id": 70,
|
| 419 |
+
"question": "I'm considering a low-carb diet to manage my blood sugar levels. Can you provide me with some recommendations on how much protein and healthy fats I should include in my daily meals?",
|
| 420 |
+
"intent": "general",
|
| 421 |
+
"role": "dietary"
|
| 422 |
+
},
|
| 423 |
+
{
|
| 424 |
+
"id": 71,
|
| 425 |
+
"question": "I've been experiencing weird tingling sensations in my feet, and I'm worried it might be a sign of nerve damage from diabetes. Can you tell me what's causing this?",
|
| 426 |
+
"intent": "general",
|
| 427 |
+
"role": "patient"
|
| 428 |
+
},
|
| 429 |
+
{
|
| 430 |
+
"id": 72,
|
| 431 |
+
"question": "I was recently diagnosed with Type 2 diabetes, and my doctor prescribed metformin. Can you explain how it works and what I can expect from the medication?",
|
| 432 |
+
"intent": "general",
|
| 433 |
+
"role": "patient"
|
| 434 |
+
},
|
| 435 |
+
{
|
| 436 |
+
"id": 73,
|
| 437 |
+
"question": "My fasting glucose levels have been consistently high, and I'm worried about the long-term effects on my health. What are some lifestyle changes I can make to improve my blood sugar control?",
|
| 438 |
+
"intent": "general",
|
| 439 |
+
"role": "patient"
|
| 440 |
+
},
|
| 441 |
+
{
|
| 442 |
+
"id": 74,
|
| 443 |
+
"question": "I've been reading about the benefits of a low-carb diet for people with diabetes. Can you recommend some specific foods and meal plans that I can follow?",
|
| 444 |
+
"intent": "general",
|
| 445 |
+
"role": "patient"
|
| 446 |
+
},
|
| 447 |
+
{
|
| 448 |
+
"id": 75,
|
| 449 |
+
"question": "I'm a researcher studying the effects of insulin pumps on glycemic control in patients with Type 1 diabetes. Can you provide me with some data on the current market trends and user experiences with different pump models?",
|
| 450 |
+
"intent": "general",
|
| 451 |
+
"role": "researcher"
|
| 452 |
+
},
|
| 453 |
+
{
|
| 454 |
+
"id": 76,
|
| 455 |
+
"question": "My blood sugar levels have been fluctuating a lot lately, and I've noticed numbness in my feet. What could be causing this?",
|
| 456 |
+
"intent": "general",
|
| 457 |
+
"role": "patient"
|
| 458 |
+
},
|
| 459 |
+
{
|
| 460 |
+
"id": 77,
|
| 461 |
+
"question": "I recently had an HbA1c test done and my levels are higher than expected. Can you help me understand what it means and how I can lower them?",
|
| 462 |
+
"intent": "general",
|
| 463 |
+
"role": "patient"
|
| 464 |
+
},
|
| 465 |
+
{
|
| 466 |
+
"id": 78,
|
| 467 |
+
"question": "I'm considering taking metformin to manage my blood sugar levels, but I've heard some concerns about its side effects. Can you weigh the pros and cons for me?",
|
| 468 |
+
"intent": "general",
|
| 469 |
+
"role": "patient"
|
| 470 |
+
},
|
| 471 |
+
{
|
| 472 |
+
"id": 79,
|
| 473 |
+
"question": "I'm planning a road trip with friends, but I'm worried about managing my blood sugar levels on the go. Do you have any tips or recommendations?",
|
| 474 |
+
"intent": "general",
|
| 475 |
+
"role": "patient"
|
| 476 |
+
},
|
| 477 |
+
{
|
| 478 |
+
"id": 80,
|
| 479 |
+
"question": "My doctor mentioned that I may be at risk for diabetic retinopathy, but I don't understand what it means or how to prevent it. Can you explain it in simple terms?",
|
| 480 |
+
"intent": "general",
|
| 481 |
+
"role": "patient"
|
| 482 |
+
},
|
| 483 |
+
{
|
| 484 |
+
"id": 81,
|
| 485 |
+
"question": "I've been feeling really thirsty and hungry lately, even though I eat a full meal three times a day. Is this normal for someone with diabetes?",
|
| 486 |
+
"intent": "general",
|
| 487 |
+
"role": "patient"
|
| 488 |
+
},
|
| 489 |
+
{
|
| 490 |
+
"id": 82,
|
| 491 |
+
"question": "My HbA1c levels are consistently above 7%, and my doctor prescribed metformin. Can you explain how the medication works, and what kind of diet would be best with it?",
|
| 492 |
+
"intent": "general",
|
| 493 |
+
"role": "patient"
|
| 494 |
+
},
|
| 495 |
+
{
|
| 496 |
+
"id": 83,
|
| 497 |
+
"question": "I have type 2 diabetes, and my doctor recommended an A1C test. What does this test measure, and how can I prepare for it?",
|
| 498 |
+
"intent": "general",
|
| 499 |
+
"role": "patient"
|
| 500 |
+
},
|
| 501 |
+
{
|
| 502 |
+
"id": 84,
|
| 503 |
+
"question": "My blood glucose levels are fluctuating wildly throughout the day. How often should I check my levels, and what's the optimal range to aim for?",
|
| 504 |
+
"intent": "monitoring",
|
| 505 |
+
"role": "clinician"
|
| 506 |
+
},
|
| 507 |
+
{
|
| 508 |
+
"id": 85,
|
| 509 |
+
"question": "I've been hearing about a new type of insulin pump that can automatically adjust dosages based on food intake. Can you tell me more about its benefits and potential risks, and how I would use it?",
|
| 510 |
+
"intent": "general",
|
| 511 |
+
"role": "researcher"
|
| 512 |
+
},
|
| 513 |
+
{
|
| 514 |
+
"id": 86,
|
| 515 |
+
"question": "I've been experiencing extreme thirst and frequent urination since starting insulin therapy. Is this a common side effect?",
|
| 516 |
+
"intent": "general",
|
| 517 |
+
"role": "patient"
|
| 518 |
+
},
|
| 519 |
+
{
|
| 520 |
+
"id": 87,
|
| 521 |
+
"question": "What is the recommended HbA1c target for a patient with Type 2 diabetes who also has kidney disease?",
|
| 522 |
+
"intent": "management",
|
| 523 |
+
"role": "clinician"
|
| 524 |
+
},
|
| 525 |
+
{
|
| 526 |
+
"id": 88,
|
| 527 |
+
"question": "I'm trying to follow a low-carb diet, but I keep running out of healthy options. Can you suggest some quick and easy recipes for diabetic meals?",
|
| 528 |
+
"intent": "general",
|
| 529 |
+
"role": "dietary"
|
| 530 |
+
},
|
| 531 |
+
{
|
| 532 |
+
"id": 89,
|
| 533 |
+
"question": "I've been feeling dizzy during physical activity. Could this be related to my diabetes, or is it something else?",
|
| 534 |
+
"intent": "general",
|
| 535 |
+
"role": "patient"
|
| 536 |
+
},
|
| 537 |
+
{
|
| 538 |
+
"id": 90,
|
| 539 |
+
"question": "What are the latest guidelines for foot care in patients with diabetic neuropathy?",
|
| 540 |
+
"intent": "management",
|
| 541 |
+
"role": "clinician"
|
| 542 |
+
},
|
| 543 |
+
{
|
| 544 |
+
"id": 91,
|
| 545 |
+
"question": "I've been experiencing frequent urination and my hands are feeling numb, what could be causing this?",
|
| 546 |
+
"intent": "general",
|
| 547 |
+
"role": "patient"
|
| 548 |
+
},
|
| 549 |
+
{
|
| 550 |
+
"id": 92,
|
| 551 |
+
"question": "What is the difference between a glucometer and a continuous glucose monitor, and which one should I use for my Type 1 diabetes?",
|
| 552 |
+
"intent": "general",
|
| 553 |
+
"role": "patient"
|
| 554 |
+
},
|
| 555 |
+
{
|
| 556 |
+
"id": 93,
|
| 557 |
+
"question": "I've been taking metformin to control my blood sugar levels, but I'm experiencing some side effects like nausea and diarrhea. Can you recommend a different medication or dosage?",
|
| 558 |
+
"intent": "general",
|
| 559 |
+
"role": "patient"
|
| 560 |
+
},
|
| 561 |
+
{
|
| 562 |
+
"id": 94,
|
| 563 |
+
"question": "I've been diagnosed with diabetic retinopathy, what are the next steps for managing my condition and preventing further vision loss?",
|
| 564 |
+
"intent": "general",
|
| 565 |
+
"role": "patient"
|
| 566 |
+
},
|
| 567 |
+
{
|
| 568 |
+
"id": 95,
|
| 569 |
+
"question": "What is the recommended carb count for a person with diabetes following a low-carb diet, and how can I adjust my meal plan to achieve this goal?",
|
| 570 |
+
"intent": "general",
|
| 571 |
+
"role": "dietitian"
|
| 572 |
+
},
|
| 573 |
+
{
|
| 574 |
+
"id": 96,
|
| 575 |
+
"question": "I've been experiencing frequent urination and blurred vision since my diagnosis. What could be the cause and when should I see my doctor?",
|
| 576 |
+
"intent": "general",
|
| 577 |
+
"role": "patient"
|
| 578 |
+
},
|
| 579 |
+
{
|
| 580 |
+
"id": 97,
|
| 581 |
+
"question": "What is the optimal HbA1c target for a patient with Type 2 diabetes, and how does it relate to cardiovascular risk?",
|
| 582 |
+
"intent": "treatment",
|
| 583 |
+
"role": "clinician"
|
| 584 |
+
},
|
| 585 |
+
{
|
| 586 |
+
"id": 98,
|
| 587 |
+
"question": "I've been trying various low-carb diets but still struggle with blood sugar control. Are there any specific dietary recommendations for Indian patients with diabetes?",
|
| 588 |
+
"intent": "general",
|
| 589 |
+
"role": "patient"
|
| 590 |
+
},
|
| 591 |
+
{
|
| 592 |
+
"id": 99,
|
| 593 |
+
"question": "My doctor has prescribed metformin, but I'm experiencing digestive issues. Can you tell me more about the common side effects of this medication and what alternatives are available?",
|
| 594 |
+
"intent": "general",
|
| 595 |
+
"role": "patient"
|
| 596 |
+
},
|
| 597 |
+
{
|
| 598 |
+
"id": 100,
|
| 599 |
+
"question": "I've noticed my feet swelling after meals. Is this a symptom of diabetes, and can I take any over-the-counter medications to reduce it?",
|
| 600 |
+
"intent": "general",
|
| 601 |
+
"role": "patient"
|
| 602 |
+
},
|
| 603 |
+
{
|
| 604 |
+
"id": 101,
|
| 605 |
+
"question": "I've been experiencing frequent urination and blurred vision, could these be symptoms of diabetes? My blood sugar levels have been consistently high for the past few weeks.",
|
| 606 |
+
"intent": "general",
|
| 607 |
+
"role": "patient"
|
| 608 |
+
},
|
| 609 |
+
{
|
| 610 |
+
"id": 102,
|
| 611 |
+
"question": "What are some effective ways to manage blood sugar levels through dietary changes?",
|
| 612 |
+
"intent": "general",
|
| 613 |
+
"role": "researcher"
|
| 614 |
+
},
|
| 615 |
+
{
|
| 616 |
+
"id": 103,
|
| 617 |
+
"question": "I'm scheduled for a flu shot, but I have diabetes. Can I still get vaccinated without increasing my risk of complications?",
|
| 618 |
+
"intent": "general",
|
| 619 |
+
"role": "patient"
|
| 620 |
+
},
|
| 621 |
+
{
|
| 622 |
+
"id": 104,
|
| 623 |
+
"question": "What is the recommended HbA1c target range for people with Type 2 diabetes, and what are the consequences of not meeting this target?",
|
| 624 |
+
"intent": "treatment",
|
| 625 |
+
"role": "clinician"
|
| 626 |
+
},
|
| 627 |
+
{
|
| 628 |
+
"id": 105,
|
| 629 |
+
"question": "Can you recommend a low-carb diet plan that suits my lifestyle as a busy working professional with diabetes? I'd like to know the macronutrient breakdown and meal ideas.",
|
| 630 |
+
"intent": "general",
|
| 631 |
+
"role": "dietary"
|
| 632 |
+
},
|
| 633 |
+
{
|
| 634 |
+
"id": 106,
|
| 635 |
+
"question": "I've been experiencing frequent urination and my hands feel cold all the time, I'm worried I might have diabetes. What should I do?",
|
| 636 |
+
"intent": "general",
|
| 637 |
+
"role": "patient"
|
| 638 |
+
},
|
| 639 |
+
{
|
| 640 |
+
"id": 107,
|
| 641 |
+
"question": "My doctor just prescribed me metformin to control my blood sugar levels. Can you explain how it works and what kind of diet would be best with this medication?",
|
| 642 |
+
"intent": "general",
|
| 643 |
+
"role": "patient"
|
| 644 |
+
},
|
| 645 |
+
{
|
| 646 |
+
"id": 108,
|
| 647 |
+
"question": "I'm a type 2 diabetic patient, I've been monitoring my HbA1c levels regularly. What is the target range for HbA1c in patients with diabetes, and how often should I check it?",
|
| 648 |
+
"intent": "general",
|
| 649 |
+
"role": "patient"
|
| 650 |
+
},
|
| 651 |
+
{
|
| 652 |
+
"id": 109,
|
| 653 |
+
"question": "I've been reading about the benefits of a ketogenic diet for type 2 diabetes. Can you provide me with some resources or studies that support this claim?",
|
| 654 |
+
"intent": "general",
|
| 655 |
+
"role": "researcher"
|
| 656 |
+
},
|
| 657 |
+
{
|
| 658 |
+
"id": 110,
|
| 659 |
+
"question": "I have gestational diabetes and I'm due to give birth soon. What are the most common complications of gestational diabetes in newborns, and what should I do to minimize them?",
|
| 660 |
+
"intent": "general",
|
| 661 |
+
"role": "patient"
|
| 662 |
+
},
|
| 663 |
+
{
|
| 664 |
+
"id": 111,
|
| 665 |
+
"question": "I've been experiencing blurred vision and frequent urination lately, but my blood sugar levels are usually okay. What could be causing these symptoms?",
|
| 666 |
+
"intent": "general",
|
| 667 |
+
"role": "patient"
|
| 668 |
+
},
|
| 669 |
+
{
|
| 670 |
+
"id": 112,
|
| 671 |
+
"question": "My doctor prescribed me metformin to control my blood sugar levels. How often should I take it and what should I expect from the medication?",
|
| 672 |
+
"intent": "general",
|
| 673 |
+
"role": "patient"
|
| 674 |
+
},
|
| 675 |
+
{
|
| 676 |
+
"id": 113,
|
| 677 |
+
"question": "I've been tracking my glucose levels using a continuous glucose monitor, but I'm having trouble understanding how to interpret the data. Can you explain how HbA1c is calculated?",
|
| 678 |
+
"intent": "general",
|
| 679 |
+
"role": "patient"
|
| 680 |
+
},
|
| 681 |
+
{
|
| 682 |
+
"id": 114,
|
| 683 |
+
"question": "I've been reading about the importance of a balanced diet in managing diabetes. What are some examples of healthy carbohydrates and protein sources that I can incorporate into my daily meals?",
|
| 684 |
+
"intent": "general",
|
| 685 |
+
"role": "dietary"
|
| 686 |
+
},
|
| 687 |
+
{
|
| 688 |
+
"id": 115,
|
| 689 |
+
"question": "I'm planning to participate in a clinical trial for a new diabetes medication. What are the potential benefits and risks of participating, and how will I be monitored throughout the trial?",
|
| 690 |
+
"intent": "general",
|
| 691 |
+
"role": "researcher"
|
| 692 |
+
},
|
| 693 |
+
{
|
| 694 |
+
"id": 116,
|
| 695 |
+
"question": "I've been experiencing frequent urination and blurred vision. Could these be symptoms of diabetes, and if so, what's the next step?",
|
| 696 |
+
"intent": "general",
|
| 697 |
+
"role": "patient"
|
| 698 |
+
},
|
| 699 |
+
{
|
| 700 |
+
"id": 117,
|
| 701 |
+
"question": "What is the ideal HbA1c target for someone with Type 2 diabetes, and how often should I get my levels checked?",
|
| 702 |
+
"intent": "general",
|
| 703 |
+
"role": "patient"
|
| 704 |
+
},
|
| 705 |
+
{
|
| 706 |
+
"id": 118,
|
| 707 |
+
"question": "I recently underwent a kidney biopsy due to suspected diabetic nephropathy. What are the possible complications of this procedure, and what's the expected recovery time?",
|
| 708 |
+
"intent": "general",
|
| 709 |
+
"role": "researcher"
|
| 710 |
+
},
|
| 711 |
+
{
|
| 712 |
+
"id": 119,
|
| 713 |
+
"question": "My doctor has prescribed metformin for my Type 2 diabetes. Can you explain how it works, and are there any potential side effects I should be aware of?",
|
| 714 |
+
"intent": "general",
|
| 715 |
+
"role": "patient"
|
| 716 |
+
},
|
| 717 |
+
{
|
| 718 |
+
"id": 120,
|
| 719 |
+
"question": "I've been following a low-carb diet to manage my blood sugar levels. Can you recommend some specific Indian dishes that are low in carbs and rich in fiber, such as dal makhani or vegetable biryani?",
|
| 720 |
+
"intent": "general",
|
| 721 |
+
"role": "dietitian"
|
| 722 |
+
},
|
| 723 |
+
{
|
| 724 |
+
"id": 121,
|
| 725 |
+
"question": "I've been experiencing constant fatigue and blurred vision, and my blood sugar levels have been consistently high lately. Is this a sign of diabetic complications?",
|
| 726 |
+
"intent": "general",
|
| 727 |
+
"role": "patient"
|
| 728 |
+
},
|
| 729 |
+
{
|
| 730 |
+
"id": 122,
|
| 731 |
+
"question": "What is the difference between metformin and sulfonylureas in terms of how they affect insulin levels, and which one would you recommend for a patient with a body mass index (BMI) of 35?",
|
| 732 |
+
"intent": "treatment",
|
| 733 |
+
"role": "clinician"
|
| 734 |
+
},
|
| 735 |
+
{
|
| 736 |
+
"id": 123,
|
| 737 |
+
"question": "I've been tracking my blood glucose levels daily, but I'm having trouble predicting when to take insulin. Can you help me understand the relationship between carbohydrate intake and blood glucose spikes?",
|
| 738 |
+
"intent": "general",
|
| 739 |
+
"role": "patient"
|
| 740 |
+
},
|
| 741 |
+
{
|
| 742 |
+
"id": 124,
|
| 743 |
+
"question": "I recently underwent a low-carb diet for two months, but my HbA1c levels didn't decrease as expected. Is it normal to experience weight loss without improved glycemic control?",
|
| 744 |
+
"intent": "general",
|
| 745 |
+
"role": "researcher"
|
| 746 |
+
},
|
| 747 |
+
{
|
| 748 |
+
"id": 125,
|
| 749 |
+
"question": "What are the best foods to include in a meal plan for someone with type 2 diabetes, and how can I calculate the glycemic index of different ingredients?",
|
| 750 |
+
"intent": "general",
|
| 751 |
+
"role": "dietitian"
|
| 752 |
+
},
|
| 753 |
+
{
|
| 754 |
+
"id": 126,
|
| 755 |
+
"question": "I've been experiencing frequent urination and my hands are feeling really cold, is this a sign of diabetes?",
|
| 756 |
+
"intent": "general",
|
| 757 |
+
"role": "patient"
|
| 758 |
+
},
|
| 759 |
+
{
|
| 760 |
+
"id": 127,
|
| 761 |
+
"question": "What are the short-term effects of not taking metformin as prescribed by my doctor?",
|
| 762 |
+
"intent": "general",
|
| 763 |
+
"role": "patient"
|
| 764 |
+
},
|
| 765 |
+
{
|
| 766 |
+
"id": 128,
|
| 767 |
+
"question": "How often should I check my blood glucose levels and what's a normal range for me?",
|
| 768 |
+
"intent": "general",
|
| 769 |
+
"role": "patient"
|
| 770 |
+
},
|
| 771 |
+
{
|
| 772 |
+
"id": 129,
|
| 773 |
+
"question": "I've been trying the keto diet to manage my blood sugar, but I'm not seeing any improvements. Is it working for everyone with type 2 diabetes?",
|
| 774 |
+
"intent": "general",
|
| 775 |
+
"role": "researcher"
|
| 776 |
+
},
|
| 777 |
+
{
|
| 778 |
+
"id": 130,
|
| 779 |
+
"question": "My doctor has prescribed insulin therapy for my diabetic neuropathy. Can you explain how this will help me manage my nerve pain?",
|
| 780 |
+
"intent": "general",
|
| 781 |
+
"role": "patient"
|
| 782 |
+
},
|
| 783 |
+
{
|
| 784 |
+
"id": 131,
|
| 785 |
+
"question": "I've been experiencing frequent urination and blurry vision. Could these be symptoms of diabetes? How do I know for sure?",
|
| 786 |
+
"intent": "general",
|
| 787 |
+
"role": "patient"
|
| 788 |
+
},
|
| 789 |
+
{
|
| 790 |
+
"id": 132,
|
| 791 |
+
"question": "My doctor has prescribed metformin to help with my blood sugar levels. Can you explain how this medication works and what I can expect in terms of dosage and side effects?",
|
| 792 |
+
"intent": "general",
|
| 793 |
+
"role": "patient"
|
| 794 |
+
},
|
| 795 |
+
{
|
| 796 |
+
"id": 133,
|
| 797 |
+
"question": "I'm planning a road trip to India and want to know if it's safe for me to travel with insulin. Are there any specific precautions I should take or foods I should avoid?",
|
| 798 |
+
"intent": "general",
|
| 799 |
+
"role": "patient"
|
| 800 |
+
},
|
| 801 |
+
{
|
| 802 |
+
"id": 134,
|
| 803 |
+
"question": "I've been having trouble controlling my blood sugar levels lately. Is it possible that I have a new onset of diabetes and what are the next steps to take?",
|
| 804 |
+
"intent": "general",
|
| 805 |
+
"role": "patient"
|
| 806 |
+
},
|
| 807 |
+
{
|
| 808 |
+
"id": 135,
|
| 809 |
+
"question": "I'm considering switching from a basal insulin to an insulin glargine regimen. What are the potential benefits and drawbacks of this change, and how will it impact my daily routine?",
|
| 810 |
+
"intent": "general",
|
| 811 |
+
"role": "patient"
|
| 812 |
+
},
|
| 813 |
+
{
|
| 814 |
+
"id": 136,
|
| 815 |
+
"question": "I've been experiencing extreme thirst and frequent urination since starting a new medication for my high blood pressure. Could this be a sign of diabetes?",
|
| 816 |
+
"intent": "general",
|
| 817 |
+
"role": "patient"
|
| 818 |
+
},
|
| 819 |
+
{
|
| 820 |
+
"id": 137,
|
| 821 |
+
"question": "What is the optimal target HbA1c level for a patient with newly diagnosed Type 2 diabetes, and how should I adjust their insulin regimen accordingly?",
|
| 822 |
+
"intent": "treatment",
|
| 823 |
+
"role": "clinician"
|
| 824 |
+
},
|
| 825 |
+
{
|
| 826 |
+
"id": 138,
|
| 827 |
+
"question": "I've noticed that my feet are feeling numb and tingling lately. Could this be related to my blood sugar levels, and what can I do to manage it?",
|
| 828 |
+
"intent": "general",
|
| 829 |
+
"role": "patient"
|
| 830 |
+
},
|
| 831 |
+
{
|
| 832 |
+
"id": 139,
|
| 833 |
+
"question": "What are the potential risks associated with taking metformin as a monotherapy for Type 2 diabetes, and how does it interact with other medications?",
|
| 834 |
+
"intent": "general",
|
| 835 |
+
"role": "researcher"
|
| 836 |
+
},
|
| 837 |
+
{
|
| 838 |
+
"id": 140,
|
| 839 |
+
"question": "I'm planning to start a new diet that's low in carbohydrates and high in protein. Will this help me better manage my blood sugar levels, and are there any specific foods I should avoid?",
|
| 840 |
+
"intent": "general",
|
| 841 |
+
"role": "dietitian"
|
| 842 |
+
},
|
| 843 |
+
{
|
| 844 |
+
"id": 141,
|
| 845 |
+
"question": "I've been experiencing fatigue and blurred vision lately. Is this a sign of diabetes?",
|
| 846 |
+
"intent": "general",
|
| 847 |
+
"role": "patient"
|
| 848 |
+
},
|
| 849 |
+
{
|
| 850 |
+
"id": 142,
|
| 851 |
+
"question": "What is the difference between basal and background insulin doses, and how often should I adjust them?",
|
| 852 |
+
"intent": "treatment",
|
| 853 |
+
"role": "clinician"
|
| 854 |
+
},
|
| 855 |
+
{
|
| 856 |
+
"id": 143,
|
| 857 |
+
"question": "I've been tracking my blood glucose levels using a glucometer. How do I interpret the readings to prevent complications?",
|
| 858 |
+
"intent": "general",
|
| 859 |
+
"role": "patient"
|
| 860 |
+
},
|
| 861 |
+
{
|
| 862 |
+
"id": 144,
|
| 863 |
+
"question": "Is it true that following a low-carb diet can help manage blood sugar levels? What are some tips for incorporating it into my daily meals?",
|
| 864 |
+
"intent": "general",
|
| 865 |
+
"role": "researcher"
|
| 866 |
+
},
|
| 867 |
+
{
|
| 868 |
+
"id": 145,
|
| 869 |
+
"question": "I've been experiencing frequent urination and feeling thirsty all the time. Could this be a sign of diabetic nephropathy? What are my treatment options?",
|
| 870 |
+
"intent": "general",
|
| 871 |
+
"role": "patient"
|
| 872 |
+
},
|
| 873 |
+
{
|
| 874 |
+
"id": 146,
|
| 875 |
+
"question": "I've been experiencing excessive thirst and urination for weeks. Is this a sign of diabetes?",
|
| 876 |
+
"intent": "general",
|
| 877 |
+
"role": "patient"
|
| 878 |
+
},
|
| 879 |
+
{
|
| 880 |
+
"id": 147,
|
| 881 |
+
"question": "What is the recommended HbA1c target range for patients with Type 1 diabetes, and why is it important?",
|
| 882 |
+
"intent": "treatment",
|
| 883 |
+
"role": "clinician"
|
| 884 |
+
},
|
| 885 |
+
{
|
| 886 |
+
"id": 148,
|
| 887 |
+
"question": "I've noticed my feet are really cold all the time. Could this be related to diabetes?",
|
| 888 |
+
"intent": "general",
|
| 889 |
+
"role": "patient"
|
| 890 |
+
},
|
| 891 |
+
{
|
| 892 |
+
"id": 149,
|
| 893 |
+
"question": "How does a low-carb diet affect blood sugar levels in people with type 2 diabetes, and what are some potential benefits?",
|
| 894 |
+
"intent": "general",
|
| 895 |
+
"role": "dietitian"
|
| 896 |
+
},
|
| 897 |
+
{
|
| 898 |
+
"id": 150,
|
| 899 |
+
"question": "I've had an episode of diabetic ketoacidosis (DKA). How often should I check my blood sugar levels while recovering at home, and what are the warning signs of DKA?",
|
| 900 |
+
"intent": "general",
|
| 901 |
+
"role": "researcher"
|
| 902 |
+
},
|
| 903 |
+
{
|
| 904 |
+
"id": 151,
|
| 905 |
+
"question": "Doc, I've been experiencing frequent urination and my hands are always sweating even when I'm not hot. Could this be related to diabetes? What's the best course of action?",
|
| 906 |
+
"intent": "general",
|
| 907 |
+
"role": "patient"
|
| 908 |
+
},
|
| 909 |
+
{
|
| 910 |
+
"id": 152,
|
| 911 |
+
"question": "I've been prescribed metformin for my type 2 diabetes, but I'm still experiencing high blood sugar readings. Can you explain how this medication works and what adjustments I need to make to my diet?",
|
| 912 |
+
"intent": "general",
|
| 913 |
+
"role": "patient"
|
| 914 |
+
},
|
| 915 |
+
{
|
| 916 |
+
"id": 153,
|
| 917 |
+
"question": "I've been tracking my glucose levels for a week, and I notice that my HbA1c has increased from 6.5% to 7.2%. What does this mean for my treatment plan, and are there any lifestyle changes I can make to bring it back under control?",
|
| 918 |
+
"intent": "general",
|
| 919 |
+
"role": "patient"
|
| 920 |
+
},
|
| 921 |
+
{
|
| 922 |
+
"id": 154,
|
| 923 |
+
"question": "Can you explain the difference between carbohydrate counting and glycemic index? Which one is more effective for managing my diabetes, especially when it comes to planning meals for a social event?",
|
| 924 |
+
"intent": "general",
|
| 925 |
+
"role": "patient"
|
| 926 |
+
},
|
| 927 |
+
{
|
| 928 |
+
"id": 155,
|
| 929 |
+
"question": "I've been experiencing severe dehydration due to excessive urination. Can you recommend any additional fluids I can drink in addition to my usual water intake to help manage this side effect?",
|
| 930 |
+
"intent": "general",
|
| 931 |
+
"role": "patient"
|
| 932 |
+
},
|
| 933 |
+
{
|
| 934 |
+
"id": 156,
|
| 935 |
+
"question": "I've been experiencing frequent urination and thirst since my diagnosis, is this a normal side effect of taking insulin?",
|
| 936 |
+
"intent": "general",
|
| 937 |
+
"role": "patient"
|
| 938 |
+
},
|
| 939 |
+
{
|
| 940 |
+
"id": 157,
|
| 941 |
+
"question": "What are the differences between metformin and pioglitazone in terms of efficacy for Type 2 diabetes management, and which one is more suitable for patients with renal impairment?",
|
| 942 |
+
"intent": "treatment",
|
| 943 |
+
"role": "clinician"
|
| 944 |
+
},
|
| 945 |
+
{
|
| 946 |
+
"id": 158,
|
| 947 |
+
"question": "I've noticed that my blood sugar levels are higher after eating a meal high in sugar. Can you recommend any diet adjustments or supplements to help manage post-meal spikes?",
|
| 948 |
+
"intent": "general",
|
| 949 |
+
"role": "patient"
|
| 950 |
+
},
|
| 951 |
+
{
|
| 952 |
+
"id": 159,
|
| 953 |
+
"question": "What is the significance of HbA1c levels in monitoring diabetic control, and what are the implications for adjusting insulin dosages?",
|
| 954 |
+
"intent": "general",
|
| 955 |
+
"role": "researcher"
|
| 956 |
+
},
|
| 957 |
+
{
|
| 958 |
+
"id": 160,
|
| 959 |
+
"question": "I'm planning to start a low-carb diet. Can you provide some guidance on how many grams of carbs I should aim for daily, and what are the potential risks of drastically reducing my carb intake?",
|
| 960 |
+
"intent": "general",
|
| 961 |
+
"role": "dietitian"
|
| 962 |
+
},
|
| 963 |
+
{
|
| 964 |
+
"id": 161,
|
| 965 |
+
"question": "I've been experiencing recurring fatigue and blurred vision, can you help me figure out if it's related to my diabetes?",
|
| 966 |
+
"intent": "general",
|
| 967 |
+
"role": "patient"
|
| 968 |
+
},
|
| 969 |
+
{
|
| 970 |
+
"id": 162,
|
| 971 |
+
"question": "How often should I check my blood sugar levels, and what's the ideal range for a normal reading?",
|
| 972 |
+
"intent": "general",
|
| 973 |
+
"role": "patient"
|
| 974 |
+
},
|
| 975 |
+
{
|
| 976 |
+
"id": 163,
|
| 977 |
+
"question": "I've been prescribed metformin to help with my insulin resistance. Can you explain how it works and when I can expect to see results?",
|
| 978 |
+
"intent": "general",
|
| 979 |
+
"role": "patient"
|
| 980 |
+
},
|
| 981 |
+
{
|
| 982 |
+
"id": 164,
|
| 983 |
+
"question": "Can you recommend a healthy meal plan for someone with diabetes, focusing on Indian cuisine as my family's food preferences are traditional?",
|
| 984 |
+
"intent": "general",
|
| 985 |
+
"role": "dietitian"
|
| 986 |
+
},
|
| 987 |
+
{
|
| 988 |
+
"id": 165,
|
| 989 |
+
"question": "What's the difference between HbA1c and glucose monitoring, and how often should I have both done to ensure accurate diabetes management?",
|
| 990 |
+
"intent": "general",
|
| 991 |
+
"role": "researcher"
|
| 992 |
+
},
|
| 993 |
+
{
|
| 994 |
+
"id": 166,
|
| 995 |
+
"question": "I've been experiencing excessive thirst and urination since my diagnosis with type 2 diabetes. Is this a symptom of a more serious condition?",
|
| 996 |
+
"intent": "general",
|
| 997 |
+
"role": "patient"
|
| 998 |
+
},
|
| 999 |
+
{
|
| 1000 |
+
"id": 167,
|
| 1001 |
+
"question": "What is the optimal HbA1c target for someone with Type 1 diabetes, and how does it impact long-term complications?",
|
| 1002 |
+
"intent": "treatment",
|
| 1003 |
+
"role": "clinician"
|
| 1004 |
+
},
|
| 1005 |
+
{
|
| 1006 |
+
"id": 168,
|
| 1007 |
+
"question": "I've been noticing numbness in my feet, which I suspect might be related to my diabetes. Can you recommend any exercises or stretches to alleviate this discomfort?",
|
| 1008 |
+
"intent": "general",
|
| 1009 |
+
"role": "patient"
|
| 1010 |
+
},
|
| 1011 |
+
{
|
| 1012 |
+
"id": 169,
|
| 1013 |
+
"question": "My doctor recently started me on metformin for my gestational diabetes. How does this medication work, and what are the potential side effects?",
|
| 1014 |
+
"intent": "general",
|
| 1015 |
+
"role": "pregnant patient"
|
| 1016 |
+
},
|
| 1017 |
+
{
|
| 1018 |
+
"id": 170,
|
| 1019 |
+
"question": "I've been tracking my glucose levels using a continuous glucometer. Can you help me understand how to interpret these readings, and what the normal ranges are for someone with diabetes?",
|
| 1020 |
+
"intent": "general",
|
| 1021 |
+
"role": "patient"
|
| 1022 |
+
},
|
| 1023 |
+
{
|
| 1024 |
+
"id": 171,
|
| 1025 |
+
"question": "I've been experiencing frequent urination and blurred vision since starting my insulin regimen. What could be causing this, and are these symptoms reversible?",
|
| 1026 |
+
"intent": "general",
|
| 1027 |
+
"role": "patient"
|
| 1028 |
+
},
|
| 1029 |
+
{
|
| 1030 |
+
"id": 172,
|
| 1031 |
+
"question": "What is the recommended HbA1c target range for a patient with newly diagnosed Type 2 diabetes, and how often should we check it?",
|
| 1032 |
+
"intent": "diagnosis",
|
| 1033 |
+
"role": "clinician"
|
| 1034 |
+
},
|
| 1035 |
+
{
|
| 1036 |
+
"id": 173,
|
| 1037 |
+
"question": "I've been following a keto diet to manage my blood sugar levels. Can you tell me if this type of diet is suitable for someone with diabetes, and are there any specific concerns I should be aware of?",
|
| 1038 |
+
"intent": "general",
|
| 1039 |
+
"role": "patient"
|
| 1040 |
+
},
|
| 1041 |
+
{
|
| 1042 |
+
"id": 174,
|
| 1043 |
+
"question": "I've been experiencing severe headaches and fatigue since taking my insulin medication. Are these side effects common with this type of medication, and are there any alternatives I can try?",
|
| 1044 |
+
"intent": "general",
|
| 1045 |
+
"role": "patient"
|
| 1046 |
+
},
|
| 1047 |
+
{
|
| 1048 |
+
"id": 175,
|
| 1049 |
+
"question": "I've been reading about the potential benefits of using continuous glucose monitoring systems (CGMS) for diabetes management. Can you tell me more about how they work, and are they suitable for patients with Type 1 diabetes?",
|
| 1050 |
+
"intent": "general",
|
| 1051 |
+
"role": "researcher"
|
| 1052 |
+
},
|
| 1053 |
+
{
|
| 1054 |
+
"id": 176,
|
| 1055 |
+
"question": "I keep experiencing sudden episodes of blurry vision, and my legs feel like they're on fire. What could be causing this?",
|
| 1056 |
+
"intent": "general",
|
| 1057 |
+
"role": "patient"
|
| 1058 |
+
},
|
| 1059 |
+
{
|
| 1060 |
+
"id": 177,
|
| 1061 |
+
"question": "What's the difference between basal and bolus insulin dosages, and how often should I adjust them based on my blood glucose levels?",
|
| 1062 |
+
"intent": "general",
|
| 1063 |
+
"role": "patient"
|
| 1064 |
+
},
|
| 1065 |
+
{
|
| 1066 |
+
"id": 178,
|
| 1067 |
+
"question": "I've been following a low-carb diet for the past week, but my blood sugar levels are still spiking after meals. Can you help me identify any potential issues with this approach?",
|
| 1068 |
+
"intent": "general",
|
| 1069 |
+
"role": "dietitian"
|
| 1070 |
+
},
|
| 1071 |
+
{
|
| 1072 |
+
"id": 179,
|
| 1073 |
+
"question": "My doctor recently told me I have high HbA1c levels, which means my long-term blood sugar control is poor. What are the potential risks and complications of this condition?",
|
| 1074 |
+
"intent": "general",
|
| 1075 |
+
"role": "patient"
|
| 1076 |
+
},
|
| 1077 |
+
{
|
| 1078 |
+
"id": 180,
|
| 1079 |
+
"question": "I've been researching different types of diabetes medications online and came across a new oral medication that seems promising for my condition. Can you verify its efficacy and safety in clinical trials?",
|
| 1080 |
+
"intent": "general",
|
| 1081 |
+
"role": "researcher"
|
| 1082 |
+
},
|
| 1083 |
+
{
|
| 1084 |
+
"id": 181,
|
| 1085 |
+
"question": "I've been experiencing frequent urination and my hands are always cold to the touch. Could this be a sign of diabetes? My blood sugar levels have been okay, but I've noticed some fluctuations lately.",
|
| 1086 |
+
"intent": "general",
|
| 1087 |
+
"role": "patient"
|
| 1088 |
+
},
|
| 1089 |
+
{
|
| 1090 |
+
"id": 182,
|
| 1091 |
+
"question": "I'm trying to lose weight and was wondering if it's okay to cut out carbohydrates completely for a week. Can you recommend any low-carb diets for diabetes management?",
|
| 1092 |
+
"intent": "general",
|
| 1093 |
+
"role": "patient"
|
| 1094 |
+
},
|
| 1095 |
+
{
|
| 1096 |
+
"id": 183,
|
| 1097 |
+
"question": "My HbA1c test result came back at 7.5%. Is that within the normal range? What can I do to get it lower?",
|
| 1098 |
+
"intent": "general",
|
| 1099 |
+
"role": "patient"
|
| 1100 |
+
},
|
| 1101 |
+
{
|
| 1102 |
+
"id": 184,
|
| 1103 |
+
"question": "I've been prescribed metformin for my type 2 diabetes, but I'm having trouble swallowing the pills. Are there any alternative medications or formulations that might be easier to take?",
|
| 1104 |
+
"intent": "general",
|
| 1105 |
+
"role": "patient"
|
| 1106 |
+
},
|
| 1107 |
+
{
|
| 1108 |
+
"id": 185,
|
| 1109 |
+
"question": "I've noticed some numbness in my fingers and toes, and I'm worried it might be related to diabetes. Can you tell me more about diabetic neuropathy and what treatment options are available?",
|
| 1110 |
+
"intent": "general",
|
| 1111 |
+
"role": "patient"
|
| 1112 |
+
},
|
| 1113 |
+
{
|
| 1114 |
+
"id": 186,
|
| 1115 |
+
"question": "I've been experiencing frequent urination and my hands are shaking while walking, do you think these symptoms could be related to diabetes?",
|
| 1116 |
+
"intent": "general",
|
| 1117 |
+
"role": "patient"
|
| 1118 |
+
},
|
| 1119 |
+
{
|
| 1120 |
+
"id": 187,
|
| 1121 |
+
"question": "What are the recommended daily carb limits for a type 1 diabetic on insulin therapy, and how does this impact blood sugar control?",
|
| 1122 |
+
"intent": "general",
|
| 1123 |
+
"role": "researcher"
|
| 1124 |
+
},
|
| 1125 |
+
{
|
| 1126 |
+
"id": 188,
|
| 1127 |
+
"question": "I've been tracking my glucose levels and noticed that they tend to spike after meals high in refined carbs. Can you suggest some low-GI food options for breakfast?",
|
| 1128 |
+
"intent": "general",
|
| 1129 |
+
"role": "dietary"
|
| 1130 |
+
},
|
| 1131 |
+
{
|
| 1132 |
+
"id": 189,
|
| 1133 |
+
"question": "My doctor just diagnosed me with diabetic retinopathy, what are the immediate steps I should take to slow its progression and potentially prevent vision loss?",
|
| 1134 |
+
"intent": "general",
|
| 1135 |
+
"role": "patient"
|
| 1136 |
+
},
|
| 1137 |
+
{
|
| 1138 |
+
"id": 190,
|
| 1139 |
+
"question": "I've been taking metformin for my type 2 diabetes, but I'm not sure what it does or how to adjust my dosage based on changes in my blood sugar levels. Can you explain the mechanism of action and provide guidance?",
|
| 1140 |
+
"intent": "general",
|
| 1141 |
+
"role": "patient"
|
| 1142 |
+
},
|
| 1143 |
+
{
|
| 1144 |
+
"id": 191,
|
| 1145 |
+
"question": "I've been experiencing frequent urination and feeling thirsty all the time. Could this be a sign of diabetes?",
|
| 1146 |
+
"intent": "general",
|
| 1147 |
+
"role": "patient"
|
| 1148 |
+
},
|
| 1149 |
+
{
|
| 1150 |
+
"id": 192,
|
| 1151 |
+
"question": "What is the difference between basal insulin and bolus insulin, and when should I use each?",
|
| 1152 |
+
"intent": "treatment",
|
| 1153 |
+
"role": "clinician"
|
| 1154 |
+
},
|
| 1155 |
+
{
|
| 1156 |
+
"id": 193,
|
| 1157 |
+
"question": "I've had high blood sugar levels for a while, but my HbA1c is still relatively normal. Is it safe to continue with my current diet and exercise plan?",
|
| 1158 |
+
"intent": "general",
|
| 1159 |
+
"role": "patient"
|
| 1160 |
+
},
|
| 1161 |
+
{
|
| 1162 |
+
"id": 194,
|
| 1163 |
+
"question": "How does the glycemic index of different foods affect blood sugar levels in people with diabetes?",
|
| 1164 |
+
"intent": "general",
|
| 1165 |
+
"role": "researcher"
|
| 1166 |
+
},
|
| 1167 |
+
{
|
| 1168 |
+
"id": 195,
|
| 1169 |
+
"question": "I've been experiencing numbness and tingling in my hands and feet. Could this be a side effect of my diabetes medication?",
|
| 1170 |
+
"intent": "general",
|
| 1171 |
+
"role": "patient"
|
| 1172 |
+
},
|
| 1173 |
+
{
|
| 1174 |
+
"id": 196,
|
| 1175 |
+
"question": "I've been experiencing frequent urination and blurry vision - could these be signs of diabetes? Are there any early symptoms I can look out for?",
|
| 1176 |
+
"intent": "general",
|
| 1177 |
+
"role": "patient"
|
| 1178 |
+
},
|
| 1179 |
+
{
|
| 1180 |
+
"id": 197,
|
| 1181 |
+
"question": "How does metformin affect my blood sugar levels during the first few months of treatment?",
|
| 1182 |
+
"intent": "general",
|
| 1183 |
+
"role": "patient"
|
| 1184 |
+
},
|
| 1185 |
+
{
|
| 1186 |
+
"id": 198,
|
| 1187 |
+
"question": "I've been tracking my glucose levels using a Continuous Glucose Monitor (CGM). What's the normal range for my HbA1c test results, and how often should I aim to check it?",
|
| 1188 |
+
"intent": "general",
|
| 1189 |
+
"role": "patient"
|
| 1190 |
+
},
|
| 1191 |
+
{
|
| 1192 |
+
"id": 199,
|
| 1193 |
+
"question": "I've been advised to follow a low-carb diet to manage my blood sugar levels. Can you provide some examples of keto-friendly foods and snacks?",
|
| 1194 |
+
"intent": "general",
|
| 1195 |
+
"role": "dietary"
|
| 1196 |
+
},
|
| 1197 |
+
{
|
| 1198 |
+
"id": 200,
|
| 1199 |
+
"question": "What are the potential risks associated with taking insulin without medical supervision, and how can I safely manage my insulin dosage?",
|
| 1200 |
+
"intent": "general",
|
| 1201 |
+
"role": "patient"
|
| 1202 |
+
}
|
| 1203 |
+
]
|
| 1204 |
+
}
|
data/small_test_set.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"questions": [
|
| 3 |
+
{
|
| 4 |
+
"id": 1,
|
| 5 |
+
"question": "I've been feeling increasingly tired and my blood sugar readings often spike in the afternoon. I also noticed my hair is growing thinner. Should I change my insulin dose or is this a sign of something else?",
|
| 6 |
+
"role": "patient",
|
| 7 |
+
"intent": "general"
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"id": 2,
|
| 11 |
+
"question": "I've been diagnosed with type 2 diabetes and noticed that my blood sugar spikes whenever I eat pizza. I love pizza but want to keep my sugars stable. What are some practical menu modifications or alternative toppings that could lower the glycemic impact without making it taste too bad?",
|
| 12 |
+
"role": "dietary",
|
| 13 |
+
"intent": "general"
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"id": 3,
|
| 17 |
+
"question": "I'm studying the impact of continuous glucose monitoring (CGM) data on the development of diabetic retinopathy in type 1 diabetes patients. In a retrospective cohort, I need to calculate the adjusted hazard ratio for retinopathy progression among patients who had \u226510% of their glucose readings in the hypoglycaemic range (<70 mg/dL) versus those with <10%. What statistical model would you recommend, how should I handle missing CGM timestamps, and what key covariates should I adjust for?",
|
| 18 |
+
"role": "researcher",
|
| 19 |
+
"intent": "general"
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"id": 4,
|
| 23 |
+
"question": "I've noticed my urine has been consistently darker than usual and for the past week I've been feeling unusually thirsty even though I've been drinking a lot of water. A few days ago I also realized that my vision is slightly blurry. My glucose monitor has shown readings around 210 mg/dL most days and I've had a single fasting plasma glucose of 110 mg/dL yesterday. I'm 45, have a BMI of 29, and I'm a non-smoker. How should I interpret these symptoms and current readings?",
|
| 24 |
+
"role": "clinician",
|
| 25 |
+
"intent": "diagnosis"
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"id": 5,
|
| 29 |
+
"question": "I have type 2 diabetes and have a BMI of 32. She recently started taking metformin 500mg twice daily, but her A1c is still 8.3% after 3 months. She also works long hours and has mild hypertension. What adjustments can I make to her medication regimen and lifestyle to reduce her A1c to below 7% within the next 6 months?",
|
| 30 |
+
"role": "clinician",
|
| 31 |
+
"intent": "treatment"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"id": 6,
|
| 35 |
+
"question": "I'm 58, type 2 diabetes, on metformin and basal insulin. Over the last month my fasting glucose has slipped from 110\u2013120 mg/dL to 130\u2013140 mg/dL, and my HbA1c just rose from 6.4% to 6.6%. I'm not changing my diet or exercise, but I feel more tired lately. Should I adjust the insulin dose, add a rapid\u2011acting mealtime insulin or consider a GLP\u20111 agent?",
|
| 36 |
+
"role": "clinician",
|
| 37 |
+
"intent": "monitoring"
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"id": 7,
|
| 41 |
+
"question": "I have a 56\u2011year\u2011old male patient who used to have normal fasting glucose but now his fasting glucose is 8.2 mmol/L. He's on metformin 1\u202fg twice daily, but his HbA1c is still 8.4%. He reports occasional tingling in his feet and his weight has dropped 4\u202fkg in the last month. He also complains of increased thirst. What next steps should I consider in his management?",
|
| 42 |
+
"role": "clinician",
|
| 43 |
+
"intent": "general"
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"id": 8,
|
| 47 |
+
"question": "I've been noticing my blood sugar stays a bit high in the evenings even after eating less. Is there anything I can adjust in my routine or diet that might help bring it down?",
|
| 48 |
+
"role": "patient",
|
| 49 |
+
"intent": "general"
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"id": 9,
|
| 53 |
+
"question": "I have type 2 diabetes and my HbA1c has been creeping up. I'm a vegetarian and try to eat mostly whole foods, but I occasionally indulge in pastries. How can I adjust my diet for better blood glucose control, and are there specific carbohydrate counts I should aim for with each meal?",
|
| 54 |
+
"role": "dietary",
|
| 55 |
+
"intent": "general"
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"id": 10,
|
| 59 |
+
"question": "What are the most recent findings on the role of gut microbiota metabolites in the development of type 2 diabetes, and how might these insights influence potential therapeutic strategies such as dietary interventions or microbiome-modulating drugs?",
|
| 60 |
+
"role": "researcher",
|
| 61 |
+
"intent": "general"
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"id": 11,
|
| 65 |
+
"question": "I have a 58\u2011year\u2011old man with type\u202f2 diabetes who recently started a new antihypertensive that appears to be lowering his blood pressure but his HbA1c remains at 9.2%. He reports increased thirst, urination, and a mild, intermittent pain when urinating. Could you suggest a possible diagnosis and what next steps I should take?",
|
| 66 |
+
"role": "clinician",
|
| 67 |
+
"intent": "diagnosis"
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"id": 12,
|
| 71 |
+
"question": "I recently started my 67\u2011year\u2011old patient on insulin glargine 20 units at bedtime. She has both type 2 diabetes and mild chronic kidney disease stage 3 (eGFR 45\u201155 mL/min). Over the last two weeks she has had two episodes of severe hypoglycemia (BGL <50 mg/dL) when she was eating dinner late and forgetting to take her pre\u2011meal carbohydrate correction. Her HbA1c has improved from 9.2% to 8.4% but she still has post\u2011prandial spikes. How can I adjust her insulin regimen or add adjunctive therapy while minimizing future hypoglycemia risk and taking her kidney function into account?",
|
| 72 |
+
"role": "clinician",
|
| 73 |
+
"intent": "treatment"
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"id": 13,
|
| 77 |
+
"question": "My patient with type 2 diabetes has been on a new GLP\u20111 agonist for six months. His latest HbA1c is 7.2%, fasting glucose 110 mg/dL, and weight down 3 kg. However, he reports increased urinary frequency and mild nausea, and his serum creatinine went up from 0.9 to 1.1 mg/dL. Should I continue the medication, adjust the dose, or switch therapy?",
|
| 78 |
+
"role": "clinician",
|
| 79 |
+
"intent": "monitoring"
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"id": 14,
|
| 83 |
+
"question": "I've been noticing that my blood sugar levels rise significantly after eating late dinners, but I still can't keep them under 180 mg/dL even when I cut carbs. What are some lifestyle adjustments I could make to better manage post-meal spikes? Also, should I consider changing my medication regimen, or would dietary tweaks be enough?",
|
| 84 |
+
"role": "clinician",
|
| 85 |
+
"intent": "general"
|
| 86 |
+
}
|
| 87 |
+
]
|
| 88 |
+
}
|
main.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
+
from typing import List, Dict, Any, Optional
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
from langchain_core.messages import HumanMessage, AIMessage, ToolMessage
|
| 9 |
+
from src.utils.logger import setup_logger
|
| 10 |
+
|
| 11 |
+
# Absolute import management
|
| 12 |
+
project_root = os.path.dirname(os.path.abspath(__file__))
|
| 13 |
+
if project_root not in sys.path:
|
| 14 |
+
sys.path.append(project_root)
|
| 15 |
+
|
| 16 |
+
from src.core.graph import medical_pipeline
|
| 17 |
+
from src.core.graph_cdm import cdm_pipeline
|
| 18 |
+
from src.core.model_manager import model_manager
|
| 19 |
+
from src.agents.agent_instances import update_all_agents_llm
|
| 20 |
+
from src.tools.fhir_memory import get_patient_summary_fhir, save_observation, save_patient
|
| 21 |
+
|
| 22 |
+
load_dotenv()
|
| 23 |
+
logger = setup_logger("FastAPI")
|
| 24 |
+
|
| 25 |
+
app = FastAPI(title="Medical AI Backend")
|
| 26 |
+
|
| 27 |
+
app.add_middleware(
|
| 28 |
+
CORSMiddleware,
|
| 29 |
+
allow_origins=["*"], # Allows all origins for local development
|
| 30 |
+
allow_credentials=True,
|
| 31 |
+
allow_methods=["*"], # Allows all methods
|
| 32 |
+
allow_headers=["*"], # Allows all headers
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
@app.get("/")
|
| 36 |
+
async def root():
|
| 37 |
+
return {"status": "healthy", "message": "Medical AI Backend is running"}
|
| 38 |
+
|
| 39 |
+
class ChatMessage(BaseModel):
|
| 40 |
+
role: str
|
| 41 |
+
content: str
|
| 42 |
+
|
| 43 |
+
class PipelineRequest(BaseModel):
|
| 44 |
+
prompt: str
|
| 45 |
+
patient_id: Optional[str] = None
|
| 46 |
+
mode: str = "Standard Triage" # "Standard Triage" or "CDM Proactive"
|
| 47 |
+
history: List[Dict[str, Any]] = []
|
| 48 |
+
|
| 49 |
+
class PipelineResponse(BaseModel):
|
| 50 |
+
messages: List[Dict[str, Any]]
|
| 51 |
+
final_state: Dict[str, Any]
|
| 52 |
+
|
| 53 |
+
def convert_to_langchain_messages(history):
|
| 54 |
+
messages = []
|
| 55 |
+
for msg in history:
|
| 56 |
+
if msg["role"] == "user":
|
| 57 |
+
messages.append(HumanMessage(content=msg["content"]))
|
| 58 |
+
elif msg["role"] == "assistant":
|
| 59 |
+
# For now, simplifying. Full implementation would handle tool calls.
|
| 60 |
+
messages.append(AIMessage(content=msg["content"]))
|
| 61 |
+
return messages
|
| 62 |
+
|
| 63 |
+
import json
|
| 64 |
+
from fastapi.responses import StreamingResponse
|
| 65 |
+
|
| 66 |
+
@app.post("/process_stream")
|
| 67 |
+
async def process_pipeline_stream(request: PipelineRequest):
|
| 68 |
+
logger.info(f"Streaming request for mode: {request.mode}")
|
| 69 |
+
|
| 70 |
+
# Select pipeline
|
| 71 |
+
active_pipeline = cdm_pipeline if request.mode == "CDM Proactive" else medical_pipeline
|
| 72 |
+
|
| 73 |
+
# Prepare initial state
|
| 74 |
+
enhanced_prompt = request.prompt
|
| 75 |
+
if request.patient_id:
|
| 76 |
+
enhanced_prompt = f"[System: User's Patient ID is {request.patient_id}]\n\n{request.prompt}"
|
| 77 |
+
|
| 78 |
+
initial_messages = convert_to_langchain_messages(request.history)
|
| 79 |
+
initial_messages.append(HumanMessage(content=enhanced_prompt))
|
| 80 |
+
|
| 81 |
+
initial_state = {
|
| 82 |
+
"messages": initial_messages,
|
| 83 |
+
"user_role": "unknown",
|
| 84 |
+
"intent_type": "unknown",
|
| 85 |
+
"is_valid": False,
|
| 86 |
+
"is_safe": False,
|
| 87 |
+
"attempts": 0,
|
| 88 |
+
"clinician_outputs": [],
|
| 89 |
+
"patient_response": "",
|
| 90 |
+
"research_output": "",
|
| 91 |
+
"sources": [],
|
| 92 |
+
"logs": [],
|
| 93 |
+
"metrics": []
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
if request.patient_id:
|
| 97 |
+
initial_state["patient_id"] = request.patient_id
|
| 98 |
+
|
| 99 |
+
async def event_generator():
|
| 100 |
+
try:
|
| 101 |
+
# Using astream_events v2 for more granular control
|
| 102 |
+
async for event in active_pipeline.astream_events(initial_state, version="v2"):
|
| 103 |
+
kind = event["event"]
|
| 104 |
+
|
| 105 |
+
# Progress Update: Node start
|
| 106 |
+
if kind == "on_chain_start" and event.get("name") in [
|
| 107 |
+
"Role Classifier", "Patient LLM", "Safety Check", "Response Validator",
|
| 108 |
+
"Intent Classifier", "FHIR Persistence", "Tools Agent"
|
| 109 |
+
]:
|
| 110 |
+
yield f"data: {json.dumps({'type': 'node', 'node': event['name']})}\n\n"
|
| 111 |
+
|
| 112 |
+
# Progress Update: Graph Nodes
|
| 113 |
+
elif kind == "on_chain_end" and "node" in event.get("metadata", {}):
|
| 114 |
+
node_name = event["metadata"]["node"]
|
| 115 |
+
yield f"data: {json.dumps({'type': 'node_complete', 'node': node_name})}\n\n"
|
| 116 |
+
|
| 117 |
+
# Token Streaming: Chat Model stream
|
| 118 |
+
elif kind == "on_chat_model_stream":
|
| 119 |
+
content = event["data"]["chunk"].content
|
| 120 |
+
if content:
|
| 121 |
+
yield f"data: {json.dumps({'type': 'token', 'content': content})}\n\n"
|
| 122 |
+
|
| 123 |
+
# Final State: End of graph
|
| 124 |
+
elif kind == "on_chain_end" and event["name"] == "LangGraph":
|
| 125 |
+
final_state = event["data"]["output"]
|
| 126 |
+
# Format state for frontend
|
| 127 |
+
clean_state = {k: v for k, v in final_state.items() if k != "messages"}
|
| 128 |
+
yield f"data: {json.dumps({'type': 'end', 'final_state': clean_state})}\n\n"
|
| 129 |
+
|
| 130 |
+
except Exception as e:
|
| 131 |
+
logger.error(f"Streaming error: {str(e)}")
|
| 132 |
+
yield f"data: {json.dumps({'type': 'error', 'detail': str(e)})}\n\n"
|
| 133 |
+
|
| 134 |
+
return StreamingResponse(event_generator(), media_type="text/event-stream")
|
| 135 |
+
|
| 136 |
+
@app.post("/process", response_model=PipelineResponse)
|
| 137 |
+
async def process_pipeline(request: PipelineRequest):
|
| 138 |
+
logger.info(f"Processing request for mode: {request.mode}")
|
| 139 |
+
|
| 140 |
+
# Select pipeline
|
| 141 |
+
active_pipeline = cdm_pipeline if request.mode == "CDM Proactive" else medical_pipeline
|
| 142 |
+
|
| 143 |
+
# Prepare initial state
|
| 144 |
+
enhanced_prompt = request.prompt
|
| 145 |
+
if request.patient_id:
|
| 146 |
+
enhanced_prompt = f"[System: User's Patient ID is {request.patient_id}]\n\n{request.prompt}"
|
| 147 |
+
|
| 148 |
+
initial_messages = convert_to_langchain_messages(request.history)
|
| 149 |
+
initial_messages.append(HumanMessage(content=enhanced_prompt))
|
| 150 |
+
|
| 151 |
+
initial_state = {
|
| 152 |
+
"messages": initial_messages,
|
| 153 |
+
"user_role": "unknown",
|
| 154 |
+
"intent_type": "unknown",
|
| 155 |
+
"is_valid": False,
|
| 156 |
+
"is_safe": False,
|
| 157 |
+
"attempts": 0,
|
| 158 |
+
"clinician_outputs": [],
|
| 159 |
+
"patient_response": "",
|
| 160 |
+
"research_output": "",
|
| 161 |
+
"sources": [],
|
| 162 |
+
"logs": [],
|
| 163 |
+
"metrics": []
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
if request.patient_id:
|
| 167 |
+
initial_state["patient_id"] = request.patient_id
|
| 168 |
+
|
| 169 |
+
try:
|
| 170 |
+
# Run the pipeline
|
| 171 |
+
final_state = await active_pipeline.ainvoke(initial_state)
|
| 172 |
+
|
| 173 |
+
# Format messages for response
|
| 174 |
+
resp_messages = []
|
| 175 |
+
for msg in final_state["messages"][len(initial_messages):]:
|
| 176 |
+
from langchain_core.messages import AIMessage, ToolMessage
|
| 177 |
+
msg_type = "assistant" if isinstance(msg, AIMessage) else "tool" if isinstance(msg, ToolMessage) else "user"
|
| 178 |
+
resp_messages.append({
|
| 179 |
+
"role": msg_type,
|
| 180 |
+
"content": msg.content,
|
| 181 |
+
"type": msg.__class__.__name__
|
| 182 |
+
})
|
| 183 |
+
|
| 184 |
+
return PipelineResponse(
|
| 185 |
+
messages=resp_messages,
|
| 186 |
+
final_state={k: v for k, v in final_state.items() if k != "messages"}
|
| 187 |
+
)
|
| 188 |
+
except Exception as e:
|
| 189 |
+
logger.error(f"Pipeline error: {str(e)}")
|
| 190 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 191 |
+
|
| 192 |
+
@app.get("/patient/{patient_id}")
|
| 193 |
+
async def get_patient_summary(patient_id: str):
|
| 194 |
+
try:
|
| 195 |
+
summary = get_patient_summary_fhir.invoke({"patient_id": patient_id})
|
| 196 |
+
return summary
|
| 197 |
+
except Exception as e:
|
| 198 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 199 |
+
|
| 200 |
+
@app.post("/patient/seed")
|
| 201 |
+
async def seed_patient_data(patient_id: str):
|
| 202 |
+
try:
|
| 203 |
+
save_patient.invoke({"patient_id": patient_id, "name": "Demo Patient"})
|
| 204 |
+
save_observation.invoke({"patient_id": patient_id, "value": 110, "unit": "mg/dL", "display": "Glucose", "loinc_code": "2339-0"})
|
| 205 |
+
save_observation.invoke({"patient_id": patient_id, "value": 125, "unit": "mg/dL", "display": "Glucose", "loinc_code": "2339-0"})
|
| 206 |
+
save_observation.invoke({"patient_id": patient_id, "value": 138, "unit": "mg/dL", "display": "Glucose", "loinc_code": "2339-0"})
|
| 207 |
+
return {"status": "success", "message": "Data seeded"}
|
| 208 |
+
except Exception as e:
|
| 209 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 210 |
+
|
| 211 |
+
@app.post("/config/llm")
|
| 212 |
+
async def set_llm_provider(provider: str):
|
| 213 |
+
try:
|
| 214 |
+
update_all_agents_llm(provider)
|
| 215 |
+
return {"status": "success", "provider": model_manager.provider}
|
| 216 |
+
except Exception as e:
|
| 217 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 218 |
+
|
| 219 |
+
if __name__ == "__main__":
|
| 220 |
+
import uvicorn
|
| 221 |
+
import os
|
| 222 |
+
port = int(os.environ.get("PORT", 10000))
|
| 223 |
+
logger.info(f"Starting server on port {port}")
|
| 224 |
+
uvicorn.run("main:app", host="0.0.0.0", port=port, reload=False)
|
performance_reports/initial baseline openrouter_gpt_oss_20b.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Performance Report
|
| 2 |
+
|
| 3 |
+
## Summary
|
| 4 |
+
|
| 5 |
+
**Timestamp**: 2026-04-28_11-21-18
|
| 6 |
+
**Provider**: openrouter
|
| 7 |
+
**Model**: openai/gpt-oss-20b:free
|
| 8 |
+
**Total Requests Sent**: 818
|
| 9 |
+
**Total Tokens Used**: 869K
|
| 10 |
+
|
| 11 |
+
**Total Tests Run**: 200
|
| 12 |
+
**Total Execution Time**: 7118.06s
|
| 13 |
+
**Average Time per Test**: 35.59s
|
| 14 |
+
**Role Match Rate**: 102/200 (51.0%)
|
| 15 |
+
**Intent Match Rate**: 22/200 (11.0%)
|
| 16 |
+
|
| 17 |
+
## Detailed Results
|
| 18 |
+
|
| 19 |
+
| ID | Question | Expected Role | Detected Role | Expected Intent | Detected Intent | Time (s) | Requests | Tokens |
|
| 20 |
+
| --- | ----------------------------------------------------- | ---------------- | ------------- | -------------------- | --------------- | -------- | --- | --- |
|
| 21 |
+
| 1 | I've been feeling really thirsty and urinating a l... | patient | patient ✅ | diagnosis | unknown ❌ | 17.6 |
|
| 22 |
+
| 2 | What is the optimal HbA1c target for a patient wit... | clinician | clinician ✅ | treatment | general ❌ | 59.44 |
|
| 23 |
+
| 3 | I've been taking metformin for my polycystic ovary... | patient | patient ✅ | treatment | unknown ❌ | 32.06 |
|
| 24 |
+
| 4 | What is the recommended diet for a patient with di... | dietitian | unknown ❌ | general | unknown ❌ | 28.93 |
|
| 25 |
+
| 5 | I'm planning to start a new exercise program to ma... | patient | patient ✅ | monitoring | unknown ❌ | 33.6 |
|
| 26 |
+
| 6 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 29.04 |
|
| 27 |
+
| 7 | My doctor just told me that my HbA1c levels are hi... | patient | clinician ❌ | treatment | treatment ✅ | 104.45 |
|
| 28 |
+
| 8 | I've been tracking my glucose levels using a conti... | patient | patient ✅ | monitoring | unknown ❌ | 33.73 |
|
| 29 |
+
| 9 | I've been reading about different diets for people... | researcher | unknown ❌ | general | unknown ❌ | 6.31 |
|
| 30 |
+
| 10 | My friend just got diagnosed with Type 2 diabetes,... | clinician | clinician ✅ | treatment | treatment ✅ | 70.01 |
|
| 31 |
+
| 11 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 25.17 |
|
| 32 |
+
| 12 | What is the recommended daily intake of carbohydra... | dietitian | dietary ❌ | treatment | unknown ❌ | 40.18 |
|
| 33 |
+
| 13 | My blood glucose levels have been consistently hig... | patient | patient ✅ | monitoring | unknown ❌ | 31.23 |
|
| 34 |
+
| 14 | I've been prescribed insulin glargine for my Type ... | patient | patient ✅ | treatment | unknown ❌ | 35.85 |
|
| 35 |
+
| 15 | A recent study suggests that incorporating more pl... | researcher | unknown ❌ | general | unknown ❌ | 5.95 |
|
| 36 |
+
| 16 | My mother was recently diagnosed with Type 2 diabe... | patient | patient ✅ | diagnosis | unknown ❌ | 36.36 |
|
| 37 |
+
| 17 | I've been taking metformin as prescribed by my doc... | patient | clinician ❌ | treatment | treatment ✅ | 68.94 |
|
| 38 |
+
| 18 | I've noticed that I've been getting really thirsty... | patient | patient ✅ | diagnosis | unknown ❌ | 19.98 |
|
| 39 |
+
| 19 | I'm planning to start a new diet that's high in su... | patient | dietary ❌ | general | unknown ❌ | 24.75 |
|
| 40 |
+
| 20 | My doctor mentioned that I should monitor my blood... | patient | patient ✅ | monitoring | unknown ❌ | 33.95 |
|
| 41 |
+
| 21 | I've been experiencing excessive thirst and urinat... | patient | patient ✅ | symptoms | unknown ❌ | 24.3 |
|
| 42 |
+
| 22 | My doctor has prescribed metformin for my Type 2 d... | patient | patient ✅ | treatment | unknown ❌ | 29.76 |
|
| 43 |
+
| 23 | I'm planning to start a new exercise routine to ma... | patient | patient ✅ | lifestyle | unknown ❌ | 36.97 |
|
| 44 |
+
| 24 | I've been experiencing frequent episodes of hypogl... | patient | patient ✅ | complication | unknown ❌ | 45.06 |
|
| 45 |
+
| 25 | What are the most effective dietary habits for man... | dietitian | dietary ❌ | lifestyle | unknown ❌ | 77.33 |
|
| 46 |
+
| 26 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 17.65 |
|
| 47 |
+
| 27 | My doctor has prescribed metformin for my Type 1 d... | patient | patient ✅ | treatment | unknown ❌ | 20.47 |
|
| 48 |
+
| 28 | What is the ideal HbA1c target range for a patient... | clinician | clinician ✅ | diagnosis | monitoring ❌ | 71.16 |
|
| 49 |
+
| 29 | I've been eating a lot of sweet dishes during fest... | patient | dietary ❌ | treatment | unknown ❌ | 52.01 |
|
| 50 |
+
| 30 | Are there any clinical trials or studies currently... | researcher | researcher ✅ | general | unknown ❌ | 46.71 |
|
| 51 |
+
| 31 | I've been experiencing frequent urination and my h... | patient | patient ✅ | symptoms | unknown ❌ | 24.22 |
|
| 52 |
+
| 32 | My HbA1c level is 8.5%, I'm currently on metformin... | patient | patient ✅ | treatment | unknown ❌ | 35.41 |
|
| 53 |
+
| 33 | I've been told I have gestational diabetes, what d... | pregnant woman | dietary ❌ | prevention | unknown ❌ | 46.01 |
|
| 54 |
+
| 34 | My doctor wants me to start monitoring my blood gl... | patient | clinician ❌ | monitoring | monitoring ✅ | 54.59 |
|
| 55 |
+
| 35 | I've been reading about the benefits of a low-carb... | patient | unknown ❌ | lifestyle management | unknown ❌ | 4.69 |
|
| 56 |
+
| 36 | I've been experiencing excessive thirst and urinat... | patient | patient ✅ | diagnosis | unknown ❌ | 21.1 |
|
| 57 |
+
| 37 | My doctor has prescribed metformin to help lower m... | patient | clinician ❌ | treatment | treatment ✅ | 64.82 |
|
| 58 |
+
| 38 | I've been tracking my blood glucose levels for a f... | patient | patient ✅ | monitoring | unknown ❌ | 34.36 |
|
| 59 |
+
| 39 | I've recently started incorporating more plant-bas... | patient | dietary ❌ | general | unknown ❌ | 64.24 |
|
| 60 |
+
| 40 | I've been diagnosed with diabetic ketoacidosis (DK... | patient | patient ✅ | diagnosis | unknown ❌ | 35.22 |
|
| 61 |
+
| 41 | I've been experiencing numbness in my hands for th... | patient | patient ✅ | symptoms | unknown ❌ | 20.86 |
|
| 62 |
+
| 42 | What are the benefits of using a continuous glucos... | researcher | patient ❌ | treatment | unknown ❌ | 32.47 |
|
| 63 |
+
| 43 | Can you recommend some low-carb Indian recipes tha... | patient | unknown ❌ | lifestyle | unknown ❌ | 6.58 |
|
| 64 |
+
| 44 | I've been diagnosed with gestational diabetes and ... | pregnant woman | patient ❌ | diagnosis | unknown ❌ | 31.91 |
|
| 65 |
+
| 45 | How does metformin work in treating type 2 diabete... | clinician | clinician ✅ | treatment | treatment ✅ | 66.0 |
|
| 66 |
+
| 46 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 35.07 |
|
| 67 |
+
| 47 | What is the optimal HbA1c target for a patient wit... | clinician | clinician ✅ | treatment | general ❌ | 67.21 |
|
| 68 |
+
| 48 | I've been tracking my daily glucose levels using m... | patient | patient ✅ | monitoring | unknown ❌ | 14.0 |
|
| 69 |
+
| 49 | What are the latest guidelines for carbohydrate co... | researcher | clinician ❌ | treatment | general ❌ | 96.8 |
|
| 70 |
+
| 50 | I've been experiencing extreme thirst and hunger, ... | patient | patient ✅ | diagnosis | unknown ❌ | 19.02 |
|
| 71 |
+
| 51 | My doctor says I need to monitor my blood sugar le... | patient | patient ✅ | monitoring | unknown ❌ | 20.57 |
|
| 72 |
+
| 52 | I've been prescribed metformin for my diabetes, bu... | patient | patient ✅ | treatment | unknown ❌ | 29.15 |
|
| 73 |
+
| 53 | My friend has just been diagnosed with Gestational... | clinician | patient ❌ | diagnosis | unknown ❌ | 41.17 |
|
| 74 |
+
| 54 | I've noticed I'm experiencing frequent urination a... | patient | patient ✅ | symptoms | unknown ❌ | 33.75 |
|
| 75 |
+
| 55 | A recent study suggests that a specific dietary ap... | researcher | dietary ❌ | general | unknown ❌ | 36.16 |
|
| 76 |
+
| 56 | Doc, I've been experiencing weird tingling sensati... | patient | patient ✅ | symptoms | unknown ❌ | 30.34 |
|
| 77 |
+
| 57 | How often should I check my blood glucose levels, ... | clinician | patient ❌ | monitoring | unknown ❌ | 39.9 |
|
| 78 |
+
| 58 | I've been prescribed metformin for my gestational ... | patient | patient ✅ | treatment | unknown ❌ | 31.22 |
|
| 79 |
+
| 59 | If my HbA1c levels are consistently above 8%, does... | patient | patient ✅ | diagnosis | unknown ❌ | 22.6 |
|
| 80 |
+
| 60 | What's the best way to incorporate more plant-base... | researcher | unknown ❌ | dietary | unknown ❌ | 8.33 |
|
| 81 |
+
| 61 | I've been experiencing recurring chest pains when ... | patient | clinician ❌ | diagnosis | diagnosis ✅ | 85.43 |
|
| 82 |
+
| 62 | My doctor prescribed metformin for my Type 2 diabe... | patient | clinician �� | treatment | treatment ✅ | 202.22 |
|
| 83 |
+
| 63 | I've noticed that my blood glucose levels tend to ... | patient | patient ✅ | monitoring | unknown ❌ | 34.17 |
|
| 84 |
+
| 64 | I've been reading about the benefits of a low-carb... | patient | unknown ❌ | general | unknown ❌ | 4.97 |
|
| 85 |
+
| 65 | I have a family history of Type 2 diabetes and am ... | patient | patient ✅ | prevention | unknown ❌ | 27.09 |
|
| 86 |
+
| 66 | I've been experiencing frequent urination and blur... | patient | patient ✅ | diagnosis | unknown ❌ | 17.73 |
|
| 87 |
+
| 67 | My HbA1c levels are consistently above 7%. What is... | patient | clinician ❌ | treatment | treatment ✅ | 77.22 |
|
| 88 |
+
| 68 | I've been taking insulin twice a day, but I'm stil... | patient | clinician ❌ | treatment | treatment ✅ | 78.67 |
|
| 89 |
+
| 69 | Can you explain the benefits and risks of switchin... | clinician | clinician ✅ | treatment | treatment ✅ | 71.22 |
|
| 90 |
+
| 70 | I'm considering a low-carb diet to manage my blood... | dietary | unknown ❌ | general | unknown ❌ | 4.19 |
|
| 91 |
+
| 71 | I've been experiencing weird tingling sensations i... | patient | patient ✅ | diagnosis | unknown ❌ | 35.42 |
|
| 92 |
+
| 72 | I was recently diagnosed with Type 2 diabetes, and... | patient | clinician ❌ | treatment | treatment ✅ | 71.57 |
|
| 93 |
+
| 73 | My fasting glucose levels have been consistently h... | patient | patient ✅ | monitoring | unknown ❌ | 41.01 |
|
| 94 |
+
| 74 | I've been reading about the benefits of a low-carb... | patient | unknown ❌ | general | unknown ❌ | 5.84 |
|
| 95 |
+
| 75 | I'm a researcher studying the effects of insulin p... | researcher | researcher ✅ | general | unknown ❌ | 26.85 |
|
| 96 |
+
| 76 | My blood sugar levels have been fluctuating a lot ... | patient | patient ✅ | diagnosis | unknown ❌ | 26.57 |
|
| 97 |
+
| 77 | I recently had an HbA1c test done and my levels ar... | patient | patient ✅ | diagnosis | unknown ❌ | 26.72 |
|
| 98 |
+
| 78 | I'm considering taking metformin to manage my bloo... | patient | patient ✅ | treatment | unknown ❌ | 25.71 |
|
| 99 |
+
| 79 | I'm planning a road trip with friends, but I'm wor... | patient | patient ✅ | general | unknown ❌ | 36.88 |
|
| 100 |
+
| 80 | My doctor mentioned that I may be at risk for diab... | patient | patient ✅ | diagnosis | unknown ❌ | 24.55 |
|
| 101 |
+
| 81 | I've been feeling really thirsty and hungry lately... | patient | patient ✅ | symptoms | unknown ❌ | 29.55 |
|
| 102 |
+
| 82 | My HbA1c levels are consistently above 7%, and my ... | patient | dietary ❌ | treatment | unknown ❌ | 57.07 |
|
| 103 |
+
| 83 | I have type 2 diabetes, and my doctor recommended ... | patient | patient ✅ | diagnosis | unknown ❌ | 20.41 |
|
| 104 |
+
| 84 | My blood glucose levels are fluctuating wildly thr... | clinician | patient ❌ | monitoring | unknown ❌ | 33.21 |
|
| 105 |
+
| 85 | I've been hearing about a new type of insulin pump... | researcher | patient ❌ | treatment | unknown ❌ | 34.63 |
|
| 106 |
+
| 86 | I've been experiencing extreme thirst and frequent... | patient | patient ✅ | treatment | unknown ❌ | 22.4 |
|
| 107 |
+
| 87 | What is the recommended HbA1c target for a patient... | clinician | clinician ✅ | management | general ❌ | 45.83 |
|
| 108 |
+
| 88 | I'm trying to follow a low-carb diet, but I keep r... | dietary | unknown ❌ | general | unknown ❌ | 5.02 |
|
| 109 |
+
| 89 | I've been feeling dizzy during physical activity. ... | patient | patient ✅ | diagnosis | unknown ❌ | 30.96 |
|
| 110 |
+
| 90 | What are the latest guidelines for foot care in pa... | clinician | clinician ✅ | management | general ❌ | 87.05 |
|
| 111 |
+
| 91 | I've been experiencing frequent urination and my h... | patient | patient ✅ | symptoms | unknown ❌ | 33.59 |
|
| 112 |
+
| 92 | What is the difference between a glucometer and a ... | patient | patient ✅ | diagnosis | unknown ❌ | 31.53 |
|
| 113 |
+
| 93 | I've been taking metformin to control my blood sug... | patient | clinician ❌ | treatment | treatment ✅ | 85.76 |
|
| 114 |
+
| 94 | I've been diagnosed with diabetic retinopathy, wha... | patient | patient ✅ | complications | unknown ❌ | 46.87 |
|
| 115 |
+
| 95 | What is the recommended carb count for a person wi... | dietitian | unknown ❌ | lifestyle management | unknown �� | 4.54 |
|
| 116 |
+
| 96 | I've been experiencing frequent urination and blur... | patient | patient ✅ | symptoms | unknown ❌ | 24.28 |
|
| 117 |
+
| 97 | What is the optimal HbA1c target for a patient wit... | clinician | clinician ✅ | treatment | general ❌ | 97.59 |
|
| 118 |
+
| 98 | I've been trying various low-carb diets but still ... | patient | dietary ❌ | general | unknown ❌ | 52.82 |
|
| 119 |
+
| 99 | My doctor has prescribed metformin, but I'm experi... | patient | patient ✅ | treatment | unknown ❌ | 30.77 |
|
| 120 |
+
| 100 | I've noticed my feet swelling after meals. Is this... | patient | patient ✅ | symptoms | unknown ❌ | 33.51 |
|
| 121 |
+
| 101 | I've been experiencing frequent urination and blur... | patient | patient ✅ | diagnosis | unknown ❌ | 20.66 |
|
| 122 |
+
| 102 | What are some effective ways to manage blood sugar... | researcher | dietary ❌ | general | unknown ❌ | 39.4 |
|
| 123 |
+
| 103 | I'm scheduled for a flu shot, but I have diabetes.... | patient | patient ✅ | monitoring | unknown ❌ | 21.41 |
|
| 124 |
+
| 104 | What is the recommended HbA1c target range for peo... | clinician | clinician ✅ | treatment | general ❌ | 61.16 |
|
| 125 |
+
| 105 | Can you recommend a low-carb diet plan that suits ... | dietary | unknown ❌ | general | unknown ❌ | 6.57 |
|
| 126 |
+
| 106 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 26.23 |
|
| 127 |
+
| 107 | My doctor just prescribed me metformin to control ... | patient | patient ✅ | treatment | unknown ❌ | 42.55 |
|
| 128 |
+
| 108 | I'm a type 2 diabetic patient, I've been monitorin... | patient | patient ✅ | monitoring | unknown ❌ | 21.22 |
|
| 129 |
+
| 109 | I've been reading about the benefits of a ketogeni... | researcher | researcher ✅ | general | unknown ❌ | 59.21 |
|
| 130 |
+
| 110 | I have gestational diabetes and I'm due to give bi... | patient | patient ✅ | diagnosis | unknown ❌ | 33.82 |
|
| 131 |
+
| 111 | I've been experiencing blurred vision and frequent... | patient | patient ✅ | diagnosis | unknown ❌ | 23.87 |
|
| 132 |
+
| 112 | My doctor prescribed me metformin to control my bl... | patient | patient ✅ | treatment | unknown ❌ | 24.84 |
|
| 133 |
+
| 113 | I've been tracking my glucose levels using a conti... | patient | patient ✅ | monitoring | unknown ❌ | 25.12 |
|
| 134 |
+
| 114 | I've been reading about the importance of a balanc... | dietary | dietary ✅ | general | unknown ❌ | 64.95 |
|
| 135 |
+
| 115 | I'm planning to participate in a clinical trial fo... | researcher | clinician ❌ | general | treatment ❌ | 53.89 |
|
| 136 |
+
| 116 | I've been experiencing frequent urination and blur... | patient | patient ✅ | diagnosis | unknown ❌ | 22.13 |
|
| 137 |
+
| 117 | What is the ideal HbA1c target for someone with Ty... | patient | clinician ❌ | treatment | monitoring ❌ | 69.83 |
|
| 138 |
+
| 118 | I recently underwent a kidney biopsy due to suspec... | researcher | clinician ❌ | diagnosis | general ❌ | 51.12 |
|
| 139 |
+
| 119 | My doctor has prescribed metformin for my Type 2 d... | patient | clinician ❌ | treatment | treatment ✅ | 59.3 |
|
| 140 |
+
| 120 | I've been following a low-carb diet to manage my b... | dietitian | dietary ❌ | general | unknown ❌ | 60.6 |
|
| 141 |
+
| 121 | I've been experiencing constant fatigue and blurre... | patient | patient ✅ | diagnosis | unknown ❌ | 27.31 |
|
| 142 |
+
| 122 | What is the difference between metformin and sulfo... | clinician | clinician ✅ | treatment | treatment ✅ | 60.2 |
|
| 143 |
+
| 123 | I've been tracking my blood glucose levels daily, ... | patient | patient ✅ | monitoring | unknown ❌ | 39.94 |
|
| 144 |
+
| 124 | I recently underwent a low-carb diet for two month... | researcher | patient ❌ | general | unknown ❌ | 28.96 |
|
| 145 |
+
| 125 | What are the best foods to include in a meal plan ... | dietitian | dietary ❌ | dietary | unknown ❌ | 57.35 |
|
| 146 |
+
| 126 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 17.46 |
|
| 147 |
+
| 127 | What are the short-term effects of not taking metf... | patient | patient ✅ | treatment | unknown ❌ | 21.13 |
|
| 148 |
+
| 128 | How often should I check my blood glucose levels a... | patient | patient ✅ | monitoring | unknown ❌ | 26.36 |
|
| 149 |
+
| 129 | I've been trying the keto diet to manage my blood ... | researcher | dietary ❌ | general | unknown ❌ | 45.99 |
|
| 150 |
+
| 130 | My doctor has prescribed insulin therapy for my di... | patient | clinician ❌ | treatment | treatment ✅ | 53.69 |
|
| 151 |
+
| 131 | I've been experiencing frequent urination and blur... | patient | patient ✅ | diagnosis | unknown ❌ | 23.12 |
|
| 152 |
+
| 132 | My doctor has prescribed metformin to help with my... | patient | patient ✅ | treatment | unknown ❌ | 30.32 |
|
| 153 |
+
| 133 | I'm planning a road trip to India and want to know... | patient | dietary ❌ | general | unknown ❌ | 39.11 |
|
| 154 |
+
| 134 | I've been having trouble controlling my blood suga... | patient | patient ✅ | monitoring | unknown ❌ | 28.68 |
|
| 155 |
+
| 135 | I'm considering switching from a basal insulin to ... | patient | clinician ❌ | treatment | treatment ✅ | 91.46 |
|
| 156 |
+
| 136 | I've been experiencing extreme thirst and frequent... | patient | patient ✅ | diagnosis | unknown ❌ | 24.33 |
|
| 157 |
+
| 137 | What is the optimal target HbA1c level for a patie... | clinician | clinician ✅ | treatment | treatment ✅ | 86.05 |
|
| 158 |
+
| 138 | I've noticed that my feet are feeling numb and tin... | patient | patient ✅ | monitoring | unknown ❌ | 32.37 |
|
| 159 |
+
| 139 | What are the potential risks associated with takin... | researcher | clinician ❌ | treatment | treatment ✅ | 86.96 |
|
| 160 |
+
| 140 | I'm planning to start a new diet that's low in car... | dietitian | dietary ❌ | general | unknown ❌ | 54.03 |
|
| 161 |
+
| 141 | I've been experiencing fatigue and blurred vision ... | patient | patient ✅ | diagnosis | unknown ❌ | 24.96 |
|
| 162 |
+
| 142 | What is the difference between basal and backgroun... | clinician | patient ❌ | treatment | unknown ❌ | 33.59 |
|
| 163 |
+
| 143 | I've been tracking my blood glucose levels using a... | patient | patient ✅ | monitoring | unknown ❌ | 45.19 |
|
| 164 |
+
| 144 | Is it true that following a low-carb diet can help... | researcher | unknown ❌ | general | unknown ❌ | 4.23 |
|
| 165 |
+
| 145 | I've been experiencing frequent urination and feel... | patient | patient ✅ | diagnosis | unknown ❌ | 31.1 |
|
| 166 |
+
| 146 | I've been experiencing excessive thirst and urinat... | patient | patient ✅ | diagnosis | unknown ❌ | 27.64 |
|
| 167 |
+
| 147 | What is the recommended HbA1c target range for pat... | clinician | clinician ✅ | treatment | general ❌ | 48.56 |
|
| 168 |
+
| 148 | I've noticed my feet are really cold all the time.... | patient | patient ✅ | diagnosis | unknown ❌ | 23.38 |
|
| 169 |
+
| 149 | How does a low-carb diet affect blood sugar levels... | dietitian | unknown ❌ | treatment | unknown ❌ | 6.22 |
|
| 170 |
+
| 150 | I've had an episode of diabetic ketoacidosis (DKA)... | researcher | patient ❌ | monitoring | unknown ❌ | 37.93 |
|
| 171 |
+
| 151 | Doc, I've been experiencing frequent urination and... | patient | patient ✅ | diagnosis | unknown ❌ | 21.2 |
|
| 172 |
+
| 152 | I've been prescribed metformin for my type 2 diabe... | patient | dietary ❌ | treatment | unknown ❌ | 20.31 |
|
| 173 |
+
| 153 | I've been tracking my glucose levels for a week, a... | patient | patient ✅ | monitoring | unknown ❌ | 50.09 |
|
| 174 |
+
| 154 | Can you explain the difference between carbohydrat... | patient | dietary ❌ | general | unknown ❌ | 78.89 |
|
| 175 |
+
| 155 | I've been experiencing severe dehydration due to e... | patient | patient ✅ | general | unknown ❌ | 33.45 |
|
| 176 |
+
| 156 | I've been experiencing frequent urination and thir... | patient | patient ✅ | symptoms | unknown ❌ | 26.74 |
|
| 177 |
+
| 157 | What are the differences between metformin and pio... | clinician | clinician ✅ | treatment | treatment ✅ | 115.94 |
|
| 178 |
+
| 158 | I've noticed that my blood sugar levels are higher... | patient | dietary ❌ | general | unknown ❌ | 68.19 |
|
| 179 |
+
| 159 | What is the significance of HbA1c levels in monito... | researcher | clinician ❌ | monitoring | monitoring ✅ | 79.7 |
|
| 180 |
+
| 160 | I'm planning to start a low-carb diet. Can you pro... | dietitian | unknown ❌ | general | unknown ❌ | 5.61 |
|
| 181 |
+
| 161 | I've been experiencing recurring fatigue and blurr... | patient | patient ✅ | diagnosis | unknown ❌ | 40.05 |
|
| 182 |
+
| 162 | How often should I check my blood sugar levels, an... | patient | patient ✅ | monitoring | unknown ❌ | 21.81 |
|
| 183 |
+
| 163 | I've been prescribed metformin to help with my ins... | patient | clinician ❌ | treatment | treatment ✅ | 67.94 |
|
| 184 |
+
| 164 | Can you recommend a healthy meal plan for someone ... | dietitian | dietary ❌ | general | unknown ❌ | 62.82 |
|
| 185 |
+
| 165 | What's the difference between HbA1c and glucose mo... | researcher | patient ❌ | diagnosis | unknown ❌ | 24.5 |
|
| 186 |
+
| 166 | I've been experiencing excessive thirst and urinat... | patient | patient ✅ | diagnosis | unknown ❌ | 35.17 |
|
| 187 |
+
| 167 | What is the optimal HbA1c target for someone with ... | clinician | unknown ❌ | treatment | unknown ❌ | 383.6 |
|
| 188 |
+
| 168 | I've been noticing numbness in my feet, which I su... | patient | unknown ❌ | general | unknown ❌ | 13.29 |
|
| 189 |
+
| 169 | My doctor recently started me on metformin for my ... | pregnant patient | unknown ❌ | treatment | unknown ❌ | 1.37 |
|
| 190 |
+
| 170 | I've been tracking my glucose levels using a conti... | patient | unknown ❌ | monitoring | unknown ❌ | 1.42 |
|
| 191 |
+
| 171 | I've been experiencing frequent urination and blur... | patient | unknown ❌ | symptoms | unknown ❌ | 1.46 |
|
| 192 |
+
| 172 | What is the recommended HbA1c target range for a p... | clinician | unknown ❌ | diagnosis | unknown ❌ | 1.26 |
|
| 193 |
+
| 173 | I've been following a keto diet to manage my blood... | patient | unknown ❌ | dietary | unknown ❌ | 1.47 |
|
| 194 |
+
| 174 | I've been experiencing severe headaches and fatigu... | patient | unknown ❌ | treatment | unknown ❌ | 1.26 |
|
| 195 |
+
| 175 | I've been reading about the potential benefits of ... | researcher | unknown ❌ | monitoring | unknown ❌ | 1.32 |
|
| 196 |
+
| 176 | I keep experiencing sudden episodes of blurry visi... | patient | unknown ❌ | diagnosis | unknown ❌ | 1.4 |
|
| 197 |
+
| 177 | What's the difference between basal and bolus insu... | patient | unknown ❌ | treatment | unknown ❌ | 1.4 |
|
| 198 |
+
| 178 | I've been following a low-carb diet for the past w... | dietitian | unknown ❌ | general | unknown ❌ | 1.42 |
|
| 199 |
+
| 179 | My doctor recently told me I have high HbA1c level... | patient | unknown ❌ | diagnosis | unknown ❌ | 1.4 |
|
| 200 |
+
| 180 | I've been researching different types of diabetes ... | researcher | unknown ❌ | general | unknown ❌ | 8.29 |
|
| 201 |
+
| 181 | I've been experiencing frequent urination and my h... | patient | unknown ❌ | diagnosis | unknown ❌ | 1.34 |
|
| 202 |
+
| 182 | I'm trying to lose weight and was wondering if it'... | patient | unknown ❌ | treatment | unknown ❌ | 1.26 |
|
| 203 |
+
| 183 | My HbA1c test result came back at 7.5%. Is that wi... | patient | unknown ❌ | monitoring | unknown ❌ | 1.44 |
|
| 204 |
+
| 184 | I've been prescribed metformin for my type 2 diabe... | patient | unknown ❌ | treatment | unknown ❌ | 8.01 |
|
| 205 |
+
| 185 | I've noticed some numbness in my fingers and toes,... | patient | unknown ❌ | diagnosis | unknown ❌ | 1.25 |
|
| 206 |
+
| 186 | I've been experiencing frequent urination and my h... | patient | unknown ❌ | diagnosis | unknown ❌ | 1.49 |
|
| 207 |
+
| 187 | What are the recommended daily carb limits for a t... | researcher | unknown ❌ | treatment | unknown ❌ | 1.39 |
|
| 208 |
+
| 188 | I've been tracking my glucose levels and noticed t... | dietary | unknown ❌ | general | unknown ❌ | 1.32 |
|
| 209 |
+
| 189 | My doctor just diagnosed me with diabetic retinopa... | patient | unknown ❌ | treatment | unknown ❌ | 1.26 |
|
| 210 |
+
| 190 | I've been taking metformin for my type 2 diabetes,... | patient | unknown ❌ | treatment | unknown ❌ | 1.32 |
|
| 211 |
+
| 191 | I've been experiencing frequent urination and feel... | patient | unknown ❌ | diagnosis | unknown ❌ | 1.25 |
|
| 212 |
+
| 192 | What is the difference between basal insulin and b... | clinician | unknown ❌ | treatment | unknown ❌ | 2.76 |
|
| 213 |
+
| 193 | I've had high blood sugar levels for a while, but ... | patient | unknown ❌ | monitoring | unknown ❌ | 1.25 |
|
| 214 |
+
| 194 | How does the glycemic index of different foods aff... | researcher | unknown ❌ | general | unknown ❌ | 1.34 |
|
| 215 |
+
| 195 | I've been experiencing numbness and tingling in my... | patient | unknown �� | diagnosis | unknown ❌ | 1.35 |
|
| 216 |
+
| 196 | I've been experiencing frequent urination and blur... | patient | unknown ❌ | diagnosis | unknown ❌ | 8.11 |
|
| 217 |
+
| 197 | How does metformin affect my blood sugar levels du... | patient | unknown ❌ | treatment | unknown ❌ | 1.37 |
|
| 218 |
+
| 198 | I've been tracking my glucose levels using a Conti... | patient | unknown ❌ | monitoring | unknown ❌ | 1.39 |
|
| 219 |
+
| 199 | I've been advised to follow a low-carb diet to man... | dietary | unknown ❌ | treatment | unknown ❌ | 1.42 |
|
| 220 |
+
| 200 | What are the potential risks associated with takin... | patient | unknown ❌ | diagnosis | unknown ❌ | 1.33 |
|
performance_reports/master_performance_report.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Complete System Execution Master Summary
|
| 2 |
+
|
| 3 |
+
| **S. No.** | **Timestamp** | **Provider** | **Model** | **Total Requests** | **Total Tokens (M)** | **Total Execution Time (s)** | **Average Time per Test (s)** | **Role Match Rate (%)** | **Intents Match Rate (%)** |
|
| 4 |
+
| :--------: | ------------------- | -----------: | ----------------------: | -----------------: | -------------------: | ---------------------------: | ----------------------------: | ----------------------- | -------------------------- |
|
| 5 |
+
| 1. | 2026-04-28_11-21-18 | openrouter | openai/gpt-oss-20b:free | 818 | 0.869 | 7,118.06 | 35.59 | 51.0 | 11.0 |
|
| 6 |
+
| 2. | 2026-04-28_15-06-07 | openrouter | openai/gpt-oss-20b:free | 1048 | 1.401 | 13,233.32 | 66.17 | 63.0 | 13.5 |
|
performance_reports/report_openrouter_llama3.2_latest_2026-05-08_00-09-10.md
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Performance Report
|
| 2 |
+
|
| 3 |
+
## Summary
|
| 4 |
+
|
| 5 |
+
**Timestamp**: 2026-05-08_00-09-10
|
| 6 |
+
**Provider**: openrouter
|
| 7 |
+
**Model**: llama3.2:latest
|
| 8 |
+
**Total Requests Sent**: 569
|
| 9 |
+
**Total Tokens Used**: 559.2K
|
| 10 |
+
|
| 11 |
+
**Total Tests Run**: 200
|
| 12 |
+
**Total Execution Time**: 11582.63s
|
| 13 |
+
**Average Time per Test**: 57.91s
|
| 14 |
+
**Role Match Rate**: 125/200 (62.5%)
|
| 15 |
+
**Intent Match Rate**: 25/200 (12.5%)
|
| 16 |
+
|
| 17 |
+
| ID | Question | Expected Role | Detected Role | Expected Intent | Detected Intent | Time (s) | Agent Breakdown (Tokens/Time) |
|
| 18 |
+
|---|---|---|---|---|---|---|---|
|
| 19 |
+
| 1 | I've been feeling really thirsty and urinating a l... | patient | patient ✅ | diagnosis | unknown ❌ | 28.42 | RoleClassifier: 302t/1.982s, ResponseValidator: 789t/6.685s, SafetyCheck: 771t/2.749s, PersistenceNode: 0t/0.024s |
|
| 20 |
+
| 2 | What is the optimal HbA1c target for a patient wit... | clinician | clinician ✅ | treatment | treatment ✅ | 69.33 | RoleClassifier: 323t/9.753s, IntentClassifier: 214t/2.544s, ClinicalSpecialist: 1083t/23.265s, OutputMerger: 2298t/33.757s |
|
| 21 |
+
| 3 | I've been taking metformin for my polycystic ovary... | patient | patient ✅ | treatment | unknown ❌ | 50.56 | RoleClassifier: 327t/4.926s, ResponseValidator: 1529t/2.424s, SafetyCheck: 1567t/2.707s, PersistenceNode: 0t/0.007s |
|
| 22 |
+
| 4 | What is the recommended diet for a patient with di... | dietitian | dietary ❌ | general | unknown ❌ | 87.59 | RoleClassifier: 308t/2.983s, ToolsNode: 0t/0.003s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.003s, ToolsNode: 0t/0.002s, ResponseValidator: 1261t/11.823s, SafetyCheck: 1177t/8.369s |
|
| 23 |
+
| 5 | I'm planning to start a new exercise program to ma... | patient | patient ✅ | monitoring | unknown ❌ | 79.32 | RoleClassifier: 316t/7.085s, ResponseValidator: 1621t/10.581s, SafetyCheck: 1581t/2.44s, PersistenceNode: 0t/0.021s |
|
| 24 |
+
| 6 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 77.54 | RoleClassifier: 319t/9.751s, ResponseValidator: 960t/12.513s, SafetyCheck: 990t/12.981s, PersistenceNode: 0t/0.02s |
|
| 25 |
+
| 7 | My doctor just told me that my HbA1c levels are hi... | patient | clinician ❌ | treatment | treatment ✅ | 164.58 | RoleClassifier: 334t/8.287s, IntentClassifier: 231t/22.627s, ClinicalSpecialist: 2751t/75.951s, OutputMerger: 4628t/57.707s |
|
| 26 |
+
| 8 | I've been tracking my glucose levels using a conti... | patient | patient ✅ | monitoring | unknown ❌ | 102.76 | RoleClassifier: 339t/16.271s, ResponseValidator: 1601t/22.3s, SafetyCheck: 1398t/28.713s, PersistenceNode: 0t/0.043s |
|
| 27 |
+
| 9 | I've been reading about different diets for people... | researcher | unknown ❌ | general | unknown ❌ | 23.72 | |
|
| 28 |
+
| 10 | My friend just got diagnosed with Type 2 diabetes,... | clinician | clinician ✅ | treatment | treatment ✅ | 144.76 | RoleClassifier: 331t/7.165s, IntentClassifier: 233t/13.184s, ClinicalSpecialist: 1696t/63.556s, OutputMerger: 3270t/60.848s |
|
| 29 |
+
| 11 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 72.4 | RoleClassifier: 305t/24.875s, ResponseValidator: 826t/7.476s, SafetyCheck: 865t/8.01s, PersistenceNode: 0t/0.026s |
|
| 30 |
+
| 12 | What is the recommended daily intake of carbohydra... | dietitian | dietary ❌ | treatment | unknown ❌ | 70.49 | RoleClassifier: 322t/11.713s, ToolsNode: 0t/0.003s, ResponseValidator: 207t/10.357s, SafetyCheck: 327t/19.518s |
|
| 31 |
+
| 13 | My blood glucose levels have been consistently hig... | patient | patient ✅ | monitoring | unknown ❌ | 61.34 | RoleClassifier: 319t/4.155s, ResponseValidator: 1406t/5.047s, SafetyCheck: 1376t/17.543s, PersistenceNode: 0t/0.029s |
|
| 32 |
+
| 14 | I've been prescribed insulin glargine for my Type ... | patient | patient ✅ | treatment | unknown ❌ | 75.83 | RoleClassifier: 327t/5.069s, ResponseValidator: 1604t/13.042s, SafetyCheck: 1606t/4.042s, PersistenceNode: 0t/0.021s |
|
| 33 |
+
| 15 | A recent study suggests that incorporating more pl... | researcher | unknown ❌ | general | unknown ❌ | 16.7 | |
|
| 34 |
+
| 16 | My mother was recently diagnosed with Type 2 diabe... | patient | patient ✅ | diagnosis | unknown ❌ | 72.76 | RoleClassifier: 317t/3.053s, ResponseValidator: 1657t/4.277s, SafetyCheck: 1706t/2.149s, PersistenceNode: 0t/0.037s |
|
| 35 |
+
| 17 | I've been taking metformin as prescribed by my doc... | patient | clinician ❌ | treatment | treatment ✅ | 120.13 | RoleClassifier: 327t/2.569s, IntentClassifier: 236t/2.098s, ClinicalSpecialist: 1919t/54.58s, OutputMerger: 3803t/60.874s |
|
| 36 |
+
| 18 | I've noticed that I've been getting really thirsty... | patient | patient ✅ | diagnosis | unknown ❌ | 31.06 | RoleClassifier: 310t/4.137s, ResponseValidator: 838t/3.462s, SafetyCheck: 844t/2.523s, PersistenceNode: 0t/0.031s |
|
| 37 |
+
| 19 | I'm planning to start a new diet that's high in su... | patient | dietary ❌ | general | unknown ❌ | 53.29 | RoleClassifier: 329t/2.443s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.02s, ToolsNode: 0t/0.002s, ResponseValidator: 1312t/12.087s, SafetyCheck: 1162t/1.906s |
|
| 38 |
+
| 20 | My doctor mentioned that I should monitor my blood... | patient | patient ✅ | monitoring | unknown ❌ | 43.82 | RoleClassifier: 324t/2.642s, ResponseValidator: 1324t/2.719s, SafetyCheck: 1358t/2.331s, PersistenceNode: 0t/0.03s |
|
| 39 |
+
| 21 | I've been experiencing excessive thirst and urinat... | patient | patient ✅ | symptoms | unknown ❌ | 30.98 | RoleClassifier: 300t/2.17s, ResponseValidator: 977t/2.707s, SafetyCheck: 1025t/2.323s, PersistenceNode: 0t/0.019s |
|
| 40 |
+
| 22 | My doctor has prescribed metformin for my Type 2 d... | patient | clinician ❌ | treatment | treatment ✅ | 84.46 | RoleClassifier: 320t/5.067s, IntentClassifier: 234t/2.885s, ClinicalSpecialist: 1554t/41.009s, OutputMerger: 2888t/35.485s |
|
| 41 |
+
| 23 | I'm planning to start a new exercise routine to ma... | patient | patient ✅ | lifestyle | unknown ❌ | 54.28 | RoleClassifier: 321t/2.653s, ResponseValidator: 1725t/2.554s, SafetyCheck: 1779t/2.18s, PersistenceNode: 0t/0.029s |
|
| 42 |
+
| 24 | I've been experiencing frequent episodes of hypogl... | patient | patient ✅ | complication | unknown ❌ | 42.1 | RoleClassifier: 326t/5.251s, ResponseValidator: 1361t/2.56s, SafetyCheck: 1408t/2.317s, PersistenceNode: 0t/0.023s |
|
| 43 |
+
| 25 | What are the most effective dietary habits for man... | dietitian | dietary ❌ | lifestyle | unknown ❌ | 69.06 | RoleClassifier: 321t/4.278s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.003s, ToolsNode: 0t/0.003s, ResponseValidator: 1741t/7.044s, SafetyCheck: 1701t/1.701s |
|
| 44 |
+
| 26 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 33.17 | RoleClassifier: 308t/3.17s, ResponseValidator: 924t/4.785s, SafetyCheck: 956t/1.765s, PersistenceNode: 0t/0.019s |
|
| 45 |
+
| 27 | My doctor has prescribed metformin for my Type 1 d... | patient | patient ✅ | treatment | unknown ❌ | 40.24 | RoleClassifier: 308t/3.672s, ResponseValidator: 1112t/4.851s, SafetyCheck: 1070t/1.785s, PersistenceNode: 0t/0.029s |
|
| 46 |
+
| 28 | What is the ideal HbA1c target range for a patient... | clinician | clinician ✅ | diagnosis | monitoring ❌ | 89.0 | RoleClassifier: 324t/3.467s, IntentClassifier: 279t/3.933s, ClinicalSpecialist: 1362t/42.71s, OutputMerger: 2576t/38.885s |
|
| 47 |
+
| 29 | I've been eating a lot of sweet dishes during fest... | patient | dietary ❌ | treatment | unknown ❌ | 91.6 | RoleClassifier: 329t/3.281s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.007s, ToolsNode: 0t/0.002s, ResponseValidator: 1096t/5.965s, SafetyCheck: 1054t/3.968s |
|
| 48 |
+
| 30 | Are there any clinical trials or studies currently... | researcher | researcher ✅ | general | unknown ❌ | 71.41 | RoleClassifier: 324t/2.763s, ResearchAgent: 496t/3.347s, ToolsNode: 0t/3.782s, ResearchAgent: 785t/4.412s, ToolsNode: 0t/0.007s, ResearchAgent: 866t/3.53s, ToolsNode: 0t/0.046s, ResearchAgent: 945t/4.604s, ToolsNode: 0t/1.179s, ResearchAgent: 2713t/47.716s |
|
| 49 |
+
| 31 | I've been experiencing frequent urination and my h... | patient | patient ✅ | symptoms | unknown ❌ | 60.09 | RoleClassifier: 320t/10.496s, ResponseValidator: 970t/4.209s, SafetyCheck: 1047t/14.407s, PersistenceNode: 0t/0.028s |
|
| 50 |
+
| 32 | My HbA1c level is 8.5%, I'm currently on metformin... | patient | clinician ❌ | treatment | treatment ✅ | 138.68 | RoleClassifier: 331t/6.54s, IntentClassifier: 221t/5.196s, ClinicalSpecialist: 2049t/66.905s, OutputMerger: 3860t/60.026s |
|
| 51 |
+
| 33 | I've been told I have gestational diabetes, what d... | pregnant woman | dietary ❌ | prevention | unknown ❌ | 42.94 | RoleClassifier: 312t/5.381s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.007s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.007s, ResponseValidator: 290t/8.237s, SafetyCheck: 315t/3.139s |
|
| 52 |
+
| 34 | My doctor wants me to start monitoring my blood gl... | patient | patient ✅ | monitoring | unknown ❌ | 79.3 | RoleClassifier: 318t/8.724s, ResponseValidator: 1890t/17.046s, SafetyCheck: 1612t/4.726s, PersistenceNode: 0t/0.006s |
|
| 53 |
+
| 35 | I've been reading about the benefits of a low-carb... | patient | unknown ❌ | lifestyle management | unknown ❌ | 11.5 | |
|
| 54 |
+
| 36 | I've been experiencing excessive thirst and urinat... | patient | patient ✅ | diagnosis | unknown ❌ | 37.45 | RoleClassifier: 315t/3.214s, ResponseValidator: 897t/3.362s, SafetyCheck: 921t/3.995s, PersistenceNode: 0t/0.03s |
|
| 55 |
+
| 37 | My doctor has prescribed metformin to help lower m... | patient | patient ✅ | treatment | unknown ❌ | 39.99 | RoleClassifier: 319t/2.688s, ResponseValidator: 1181t/4.349s, SafetyCheck: 1200t/5.272s, PersistenceNode: 0t/0.006s |
|
| 56 |
+
| 38 | I've been tracking my blood glucose levels for a f... | patient | patient ✅ | monitoring | unknown ❌ | 45.45 | RoleClassifier: 328t/3.035s, ResponseValidator: 1297t/2.582s, SafetyCheck: 1335t/2.562s, PersistenceNode: 0t/0.023s |
|
| 57 |
+
| 39 | I've recently started incorporating more plant-bas... | patient | dietary ❌ | general | unknown ❌ | 57.55 | RoleClassifier: 328t/2.811s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.025s, ToolsNode: 0t/0.001s, ResponseValidator: 1392t/4.994s, SafetyCheck: 1346t/2.023s |
|
| 58 |
+
| 40 | I've been diagnosed with diabetic ketoacidosis (DK... | patient | patient ✅ | diagnosis | unknown ❌ | 59.09 | RoleClassifier: 330t/6.986s, ResponseValidator: 1340t/12.18s, SafetyCheck: 1353t/2.101s, PersistenceNode: 0t/0.006s |
|
| 59 |
+
| 41 | I've been experiencing numbness in my hands for th... | patient | patient ✅ | symptoms | unknown ❌ | 26.95 | RoleClassifier: 302t/2.222s, ResponseValidator: 828t/3.65s, SafetyCheck: 860t/1.686s, PersistenceNode: 0t/0.032s |
|
| 60 |
+
| 42 | What are the benefits of using a continuous glucos... | researcher | patient ❌ | treatment | unknown ❌ | 50.32 | RoleClassifier: 319t/2.964s, ResponseValidator: 1446t/5.173s, SafetyCheck: 1382t/4.431s, PersistenceNode: 0t/0.021s |
|
| 61 |
+
| 43 | Can you recommend some low-carb Indian recipes tha... | patient | unknown ❌ | lifestyle | unknown ❌ | 4.48 | |
|
| 62 |
+
| 44 | I've been diagnosed with gestational diabetes and ... | pregnant woman | patient ❌ | diagnosis | unknown ❌ | 32.34 | RoleClassifier: 314t/2.542s, ResponseValidator: 1022t/3.646s, SafetyCheck: 1040t/2.193s, PersistenceNode: 0t/0.006s |
|
| 63 |
+
| 45 | How does metformin work in treating type 2 diabete... | clinician | clinician ✅ | treatment | general ❌ | 61.13 | RoleClassifier: 317t/2.719s, IntentClassifier: 205t/2.098s, ClinicalSpecialist: 1262t/30.372s, OutputMerger: 2415t/25.934s |
|
| 64 |
+
| 46 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 35.74 | RoleClassifier: 315t/2.41s, ResponseValidator: 1032t/5.598s, SafetyCheck: 1035t/2.659s, PersistenceNode: 0t/0.006s |
|
| 65 |
+
| 47 | What is the optimal HbA1c target for a patient wit... | clinician | clinician ✅ | treatment | treatment ✅ | 60.46 | RoleClassifier: 334t/3.508s, IntentClassifier: 221t/2.319s, ClinicalSpecialist: 905t/26.109s, OutputMerger: 1943t/28.517s |
|
| 66 |
+
| 48 | I've been tracking my daily glucose levels using m... | patient | patient ✅ | monitoring | unknown ❌ | 23.61 | RoleClassifier: 312t/4.158s, ResponseValidator: 404t/2.665s, SafetyCheck: 470t/8.001s, PersistenceNode: 0t/0.006s |
|
| 67 |
+
| 49 | What are the latest guidelines for carbohydrate co... | researcher | clinician ❌ | treatment | general ❌ | 89.94 | RoleClassifier: 340t/3.643s, IntentClassifier: 201t/2.1s, ClinicalSpecialist: 1620t/52.143s, OutputMerger: 2723t/32.041s |
|
| 68 |
+
| 50 | I've been experiencing extreme thirst and hunger, ... | patient | patient ✅ | diagnosis | unknown ❌ | 35.8 | RoleClassifier: 309t/2.773s, ResponseValidator: 1061t/3.675s, SafetyCheck: 1109t/2.987s, PersistenceNode: 0t/0.007s |
|
| 69 |
+
| 51 | My doctor says I need to monitor my blood sugar le... | patient | patient ✅ | monitoring | unknown ❌ | 47.98 | RoleClassifier: 324t/5.966s, ResponseValidator: 1122t/5.512s, SafetyCheck: 1065t/1.699s, PersistenceNode: 0t/0.026s |
|
| 70 |
+
| 52 | I've been prescribed metformin for my diabetes, bu... | patient | patient ✅ | treatment | unknown ❌ | 30.11 | RoleClassifier: 333t/3.416s, ResponseValidator: 970t/4.911s, SafetyCheck: 1012t/1.745s, PersistenceNode: 0t/0.007s |
|
| 71 |
+
| 53 | My friend has just been diagnosed with Gestational... | clinician | patient ❌ | diagnosis | unknown ❌ | 54.29 | RoleClassifier: 319t/2.835s, ResponseValidator: 1644t/2.577s, SafetyCheck: 1689t/2.075s, PersistenceNode: 0t/0.006s |
|
| 72 |
+
| 54 | I've noticed I'm experiencing frequent urination a... | patient | patient ✅ | symptoms | unknown ❌ | 59.61 | RoleClassifier: 317t/4.724s, ResponseValidator: 1315t/4.093s, SafetyCheck: 1362t/2.072s, PersistenceNode: 0t/0.006s |
|
| 73 |
+
| 55 | A recent study suggests that a specific dietary ap... | researcher | dietary ❌ | general | unknown ❌ | 86.59 | RoleClassifier: 325t/5.207s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.006s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ResponseValidator: 462t/7.736s, SafetyCheck: 369t/3.7s |
|
| 74 |
+
| 56 | Doc, I've been experiencing weird tingling sensati... | patient | patient ✅ | symptoms | unknown ❌ | 53.03 | RoleClassifier: 327t/7.762s, ResponseValidator: 1228t/6.6s, SafetyCheck: 1270t/2.007s, PersistenceNode: 0t/0.006s |
|
| 75 |
+
| 57 | How often should I check my blood glucose levels, ... | clinician | patient ❌ | monitoring | unknown ❌ | 51.62 | RoleClassifier: 319t/2.404s, ToolsNode: 0t/1.786s, ResponseValidator: 1383t/10.636s, SafetyCheck: 1143t/2.108s, PersistenceNode: 0t/0.006s |
|
| 76 |
+
| 58 | I've been prescribed metformin for my gestational ... | patient | patient ✅ | treatment | unknown ❌ | 64.47 | RoleClassifier: 322t/2.834s, ResponseValidator: 1321t/16.856s, SafetyCheck: 1233t/14.32s, PersistenceNode: 0t/0.007s |
|
| 77 |
+
| 59 | If my HbA1c levels are consistently above 8%, does... | patient | patient ✅ | diagnosis | unknown ❌ | 39.0 | RoleClassifier: 328t/6.988s, ResponseValidator: 753t/2.924s, SafetyCheck: 788t/1.601s, PersistenceNode: 0t/0.006s |
|
| 78 |
+
| 60 | What's the best way to incorporate more plant-base... | researcher | unknown ❌ | dietary | unknown ❌ | 6.28 | |
|
| 79 |
+
| 61 | I've been experiencing recurring chest pains when ... | patient | clinician ❌ | diagnosis | diagnosis ✅ | 82.57 | RoleClassifier: 340t/4.621s, IntentClassifier: 236t/2.425s, ClinicalSpecialist: 1474t/37.622s, OutputMerger: 2828t/37.895s |
|
| 80 |
+
| 62 | My doctor prescribed metformin for my Type 2 diabe... | patient | clinician ❌ | treatment | treatment ✅ | 106.02 | RoleClassifier: 330t/2.561s, IntentClassifier: 212t/1.802s, ClinicalSpecialist: 1903t/50.234s, OutputMerger: 3735t/51.42s |
|
| 81 |
+
| 63 | I've noticed that my blood glucose levels tend to ... | patient | patient ✅ | monitoring | unknown ❌ | 61.68 | RoleClassifier: 327t/5.018s, ResponseValidator: 1399t/12.46s, SafetyCheck: 1437t/5.095s, PersistenceNode: 0t/0.02s |
|
| 82 |
+
| 64 | I've been reading about the benefits of a low-carb... | patient | unknown ❌ | general | unknown ❌ | 13.55 | |
|
| 83 |
+
| 65 | I have a family history of Type 2 diabetes and am ... | patient | patient ✅ | prevention | unknown ❌ | 88.24 | RoleClassifier: 328t/3.2s, ResponseValidator: 1635t/28.665s, SafetyCheck: 1684t/9.544s, PersistenceNode: 0t/0.007s |
|
| 84 |
+
| 66 | I've been experiencing frequent urination and blur... | patient | patient ✅ | diagnosis | unknown ❌ | 70.63 | RoleClassifier: 296t/11.555s, ResponseValidator: 1004t/6.583s, SafetyCheck: 1038t/7.636s, PersistenceNode: 0t/0.006s |
|
| 85 |
+
| 67 | My HbA1c levels are consistently above 7%. What is... | patient | clinician ❌ | treatment | treatment ✅ | 166.09 | RoleClassifier: 311t/4.944s, IntentClassifier: 236t/14.549s, ClinicalSpecialist: 2295t/80.159s, OutputMerger: 4259t/66.427s |
|
| 86 |
+
| 68 | I've been taking insulin twice a day, but I'm stil... | patient | clinician ❌ | treatment | treatment ✅ | 118.37 | RoleClassifier: 308t/6.844s, IntentClassifier: 210t/2.886s, ClinicalSpecialist: 1712t/55.243s, OutputMerger: 3242t/53.389s |
|
| 87 |
+
| 69 | Can you explain the benefits and risks of switchin... | clinician | clinician ✅ | treatment | treatment ✅ | 122.14 | RoleClassifier: 319t/4.684s, IntentClassifier: 209t/2.738s, ClinicalSpecialist: 1771t/55.52s, OutputMerger: 3456t/59.186s |
|
| 88 |
+
| 70 | I'm considering a low-carb diet to manage my blood... | dietary | unknown ❌ | general | unknown ❌ | 8.84 | |
|
| 89 |
+
| 71 | I've been experiencing weird tingling sensations i... | patient | patient ✅ | diagnosis | unknown ❌ | 73.38 | RoleClassifier: 325t/17.35s, ResponseValidator: 1143t/13.038s, SafetyCheck: 1178t/10.681s, PersistenceNode: 0t/0.018s |
|
| 90 |
+
| 72 | I was recently diagnosed with Type 2 diabetes, and... | patient | clinician ❌ | treatment | treatment ✅ | 101.16 | RoleClassifier: 318t/8.087s, IntentClassifier: 217t/9.433s, ClinicalSpecialist: 1269t/42.44s, OutputMerger: 2431t/41.194s |
|
| 91 |
+
| 73 | My fasting glucose levels have been consistently h... | patient | patient ✅ | monitoring | unknown ❌ | 39.11 | RoleClassifier: 324t/4.761s, ResponseValidator: 1313t/2.514s, SafetyCheck: 1346t/1.806s, PersistenceNode: 0t/0.006s |
|
| 92 |
+
| 74 | I've been reading about the benefits of a low-carb... | patient | unknown ❌ | general | unknown ❌ | 5.55 | |
|
| 93 |
+
| 75 | I'm a researcher studying the effects of insulin p... | researcher | researcher ✅ | general | unknown ❌ | 67.83 | RoleClassifier: 320t/2.23s, ResearchAgent: 502t/2.866s, ToolsNode: 0t/1.073s, ResearchAgent: 797t/4.234s, ToolsNode: 0t/3.066s, ResearchAgent: 2599t/54.351s |
|
| 94 |
+
| 76 | My blood sugar levels have been fluctuating a lot ... | patient | patient ✅ | diagnosis | unknown ❌ | 66.52 | RoleClassifier: 316t/11.503s, ResponseValidator: 1228t/8.064s, SafetyCheck: 1291t/9.017s, PersistenceNode: 0t/0.02s |
|
| 95 |
+
| 77 | I recently had an HbA1c test done and my levels ar... | patient | patient ✅ | diagnosis | unknown ❌ | 75.18 | RoleClassifier: 327t/13.897s, ResponseValidator: 1037t/11.955s, SafetyCheck: 1083t/7.638s, PersistenceNode: 0t/0.02s |
|
| 96 |
+
| 78 | I'm considering taking metformin to manage my bloo... | patient | patient ✅ | treatment | unknown ❌ | 67.24 | RoleClassifier: 328t/15.31s, ResponseValidator: 1221t/5.675s, SafetyCheck: 1268t/13.141s, PersistenceNode: 0t/0.006s |
|
| 97 |
+
| 79 | I'm planning a road trip with friends, but I'm wor... | patient | patient ✅ | general | unknown ❌ | 69.02 | RoleClassifier: 318t/4.47s, ResponseValidator: 1759t/11.241s, SafetyCheck: 1717t/4.75s, PersistenceNode: 0t/0.006s |
|
| 98 |
+
| 80 | My doctor mentioned that I may be at risk for diab... | patient | patient ✅ | diagnosis | unknown ❌ | 52.16 | RoleClassifier: 328t/3.377s, ResponseValidator: 1182t/9.679s, SafetyCheck: 1163t/5.169s, PersistenceNode: 0t/0.006s |
|
| 99 |
+
| 81 | I've been feeling really thirsty and hungry lately... | patient | patient ✅ | symptoms | unknown ❌ | 59.82 | RoleClassifier: 311t/5.092s, ResponseValidator: 974t/10.914s, SafetyCheck: 1002t/10.447s, PersistenceNode: 0t/0.006s |
|
| 100 |
+
| 82 | My HbA1c levels are consistently above 7%, and my ... | patient | dietary ❌ | treatment | unknown ❌ | 71.94 | RoleClassifier: 375t/8.848s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.027s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ResponseValidator: 202t/6.602s, SafetyCheck: 337t/4.05s |
|
| 101 |
+
| 83 | I have type 2 diabetes, and my doctor recommended ... | patient | patient ✅ | diagnosis | unknown ❌ | 58.45 | RoleClassifier: 326t/2.832s, ResponseValidator: 807t/25.606s, SafetyCheck: 832t/9.92s, PersistenceNode: 0t/0.006s |
|
| 102 |
+
| 84 | My blood glucose levels are fluctuating wildly thr... | clinician | patient ❌ | monitoring | unknown ❌ | 61.6 | RoleClassifier: 321t/5.268s, ResponseValidator: 1359t/7.298s, SafetyCheck: 1292t/3.702s, PersistenceNode: 0t/0.006s |
|
| 103 |
+
| 85 | I've been hearing about a new type of insulin pump... | researcher | patient ❌ | treatment | unknown ❌ | 55.81 | RoleClassifier: 335t/7.037s, ResponseValidator: 1577t/6.321s, SafetyCheck: 1503t/4.592s, PersistenceNode: 0t/0.006s |
|
| 104 |
+
| 86 | I've been experiencing extreme thirst and frequent... | patient | patient ✅ | treatment | unknown ❌ | 42.98 | RoleClassifier: 307t/2.567s, ResponseValidator: 1343t/8.838s, SafetyCheck: 1212t/2.476s, PersistenceNode: 0t/0.038s |
|
| 105 |
+
| 87 | What is the recommended HbA1c target for a patient... | clinician | clinician ✅ | management | treatment ❌ | 86.38 | RoleClassifier: 325t/3.122s, IntentClassifier: 213t/5.534s, ClinicalSpecialist: 1594t/38.519s, OutputMerger: 3025t/39.194s |
|
| 106 |
+
| 88 | I'm trying to follow a low-carb diet, but I keep r... | dietary | unknown ❌ | general | unknown ❌ | 5.05 | |
|
| 107 |
+
| 89 | I've been feeling dizzy during physical activity. ... | patient | patient ✅ | diagnosis | unknown ❌ | 34.85 | RoleClassifier: 310t/2.675s, ResponseValidator: 1003t/2.533s, SafetyCheck: 1039t/5.085s, PersistenceNode: 0t/0.016s |
|
| 108 |
+
| 90 | What are the latest guidelines for foot care in pa... | clinician | clinician ✅ | management | general ❌ | 112.08 | RoleClassifier: 312t/2.77s, IntentClassifier: 201t/2.473s, ClinicalSpecialist: 2243t/52.789s, OutputMerger: 4030t/54.041s |
|
| 109 |
+
| 91 | I've been experiencing frequent urination and my h... | patient | patient ✅ | symptoms | unknown ❌ | 34.45 | RoleClassifier: 318t/3.548s, ResponseValidator: 880t/4.038s, SafetyCheck: 924t/2.872s, PersistenceNode: 0t/0.006s |
|
| 110 |
+
| 92 | What is the difference between a glucometer and a ... | patient | patient ✅ | diagnosis | unknown ❌ | 59.89 | RoleClassifier: 318t/3.266s, ResponseValidator: 1620t/16.038s, SafetyCheck: 1432t/5.686s, PersistenceNode: 0t/0.029s |
|
| 111 |
+
| 93 | I've been taking metformin to control my blood sug... | patient | clinician ❌ | treatment | treatment ✅ | 113.87 | RoleClassifier: 316t/18.086s, IntentClassifier: 216t/2.317s, ClinicalSpecialist: 1959t/56.6s, OutputMerger: 3297t/36.855s |
|
| 112 |
+
| 94 | I've been diagnosed with diabetic retinopathy, wha... | patient | patient ✅ | complications | unknown ❌ | 57.37 | RoleClassifier: 321t/2.667s, ResponseValidator: 1655t/5.448s, SafetyCheck: 1693t/4.106s, PersistenceNode: 0t/0.006s |
|
| 113 |
+
| 95 | What is the recommended carb count for a person wi... | dietitian | unknown ❌ | lifestyle management | unknown ❌ | 12.11 | |
|
| 114 |
+
| 96 | I've been experiencing frequent urination and blur... | patient | patient ✅ | symptoms | unknown ❌ | 47.81 | RoleClassifier: 312t/2.606s, ResponseValidator: 1070t/3.061s, SafetyCheck: 1104t/8.593s, PersistenceNode: 0t/0.006s |
|
| 115 |
+
| 97 | What is the optimal HbA1c target for a patient wit... | clinician | clinician ✅ | treatment | treatment ✅ | 85.84 | RoleClassifier: 326t/2.817s, IntentClassifier: 215t/2.169s, ClinicalSpecialist: 1416t/42.137s, OutputMerger: 2672t/38.704s |
|
| 116 |
+
| 98 | I've been trying various low-carb diets but still ... | patient | dietary ❌ | general | unknown ❌ | 134.13 | RoleClassifier: 312t/4.262s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.021s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.006s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ResponseValidator: 2030t/8.83s, SafetyCheck: 1880t/2.567s |
|
| 117 |
+
| 99 | My doctor has prescribed metformin, but I'm experi... | patient | patient ✅ | treatment | unknown ❌ | 59.87 | RoleClassifier: 323t/5.644s, ResponseValidator: 1673t/3.838s, SafetyCheck: 1712t/1.589s, PersistenceNode: 0t/0.022s |
|
| 118 |
+
| 100 | I've noticed my feet swelling after meals. Is this... | patient | patient ✅ | symptoms | unknown ❌ | 36.37 | RoleClassifier: 325t/5.954s, ResponseValidator: 988t/3.501s, SafetyCheck: 1014t/3.198s, PersistenceNode: 0t/0.015s |
|
| 119 |
+
| 101 | I've been experiencing frequent urination and blur... | patient | patient ✅ | diagnosis | unknown ❌ | 33.05 | RoleClassifier: 317t/2.377s, ResponseValidator: 794t/5.71s, SafetyCheck: 804t/5.778s, PersistenceNode: 0t/0.025s |
|
| 120 |
+
| 102 | What are some effective ways to manage blood sugar... | researcher | dietary ❌ | general | unknown ❌ | 60.26 | RoleClassifier: 302t/3.744s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ResponseValidator: 1524t/3.862s, SafetyCheck: 1510t/3.1s |
|
| 121 |
+
| 103 | I'm scheduled for a flu shot, but I have diabetes.... | patient | patient ✅ | monitoring | unknown ❌ | 26.38 | RoleClassifier: 315t/2.313s, ResponseValidator: 748t/5.534s, SafetyCheck: 773t/1.562s, PersistenceNode: 0t/0.006s |
|
| 122 |
+
| 104 | What is the recommended HbA1c target range for peo... | clinician | clinician ✅ | treatment | general ❌ | 74.78 | RoleClassifier: 325t/3.651s, IntentClassifier: 221t/5.536s, ClinicalSpecialist: 1334t/31.831s, OutputMerger: 2465t/33.758s |
|
| 123 |
+
| 105 | Can you recommend a low-carb diet plan that suits ... | dietary | unknown ❌ | general | unknown ❌ | 13.89 | |
|
| 124 |
+
| 106 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 24.16 | RoleClassifier: 316t/4.912s, ResponseValidator: 631t/3.449s, SafetyCheck: 658t/1.502s, PersistenceNode: 0t/0.006s |
|
| 125 |
+
| 107 | My doctor just prescribed me metformin to control ... | patient | dietary ❌ | treatment | unknown ❌ | 84.42 | RoleClassifier: 318t/3.233s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.017s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ResponseValidator: 1216t/6.603s, SafetyCheck: 1128t/1.747s |
|
| 126 |
+
| 108 | I'm a type 2 diabetic patient, I've been monitorin... | patient | patient ✅ | monitoring | unknown ❌ | 32.92 | RoleClassifier: 331t/2.415s, ResponseValidator: 1035t/3.663s, SafetyCheck: 1039t/1.878s, PersistenceNode: 0t/0.006s |
|
| 127 |
+
| 109 | I've been reading about the benefits of a ketogeni... | researcher | researcher ✅ | general | unknown ❌ | 70.75 | RoleClassifier: 328t/3.492s, ResearchAgent: 506t/4.762s, ToolsNode: 0t/0.007s, ResearchAgent: 553t/3.378s, ToolsNode: 0t/1.369s, ResearchAgent: 899t/6.223s, ToolsNode: 0t/0.007s, ResearchAgent: 944t/3.222s, ToolsNode: 0t/1.749s, ResearchAgent: 2802t/46.524s |
|
| 128 |
+
| 110 | I have gestational diabetes and I'm due to give bi... | patient | patient ✅ | diagnosis | unknown ❌ | 43.25 | RoleClassifier: 334t/6.205s, ResponseValidator: 1280t/4.405s, SafetyCheck: 1291t/2.225s, PersistenceNode: 0t/0.006s |
|
| 129 |
+
| 111 | I've been experiencing blurred vision and frequent... | patient | patient ✅ | diagnosis | unknown ❌ | 41.27 | RoleClassifier: 326t/10.161s, ResponseValidator: 1092t/3.12s, SafetyCheck: 1134t/2.14s, PersistenceNode: 0t/0.006s |
|
| 130 |
+
| 112 | My doctor prescribed me metformin to control my bl... | patient | patient ✅ | treatment | unknown ❌ | 51.63 | RoleClassifier: 313t/8.461s, ResponseValidator: 1568t/5.178s, SafetyCheck: 1510t/1.655s, PersistenceNode: 0t/0.006s |
|
| 131 |
+
| 113 | I've been tracking my glucose levels using a conti... | patient | patient ✅ | monitoring | unknown ❌ | 45.99 | RoleClassifier: 342t/3.015s, ResponseValidator: 1441t/3.675s, SafetyCheck: 1481t/1.808s, PersistenceNode: 0t/0.006s |
|
| 132 |
+
| 114 | I've been reading about the importance of a balanc... | dietary | unknown ❌ | general | unknown ❌ | 19.47 | |
|
| 133 |
+
| 115 | I'm planning to participate in a clinical trial fo... | researcher | clinician ❌ | general | treatment ❌ | 78.36 | RoleClassifier: 327t/9.791s, IntentClassifier: 254t/3.978s, ClinicalSpecialist: 1487t/46.508s, OutputMerger: 2168t/18.074s |
|
| 134 |
+
| 116 | I've been experiencing frequent urination and blur... | patient | patient ✅ | diagnosis | unknown ❌ | 31.88 | RoleClassifier: 311t/2.445s, ResponseValidator: 1018t/3.1s, SafetyCheck: 1054t/2.062s, PersistenceNode: 0t/0.006s |
|
| 135 |
+
| 117 | What is the ideal HbA1c target for someone with Ty... | patient | clinician ❌ | treatment | monitoring ❌ | 79.81 | RoleClassifier: 322t/5.396s, IntentClassifier: 214t/1.956s, ClinicalSpecialist: 1262t/39.808s, OutputMerger: 2462t/32.644s |
|
| 136 |
+
| 118 | I recently underwent a kidney biopsy due to suspec... | researcher | clinician ❌ | diagnosis | general ❌ | 95.69 | RoleClassifier: 333t/5.923s, IntentClassifier: 263t/3.194s, ClinicalSpecialist: 1457t/41.487s, OutputMerger: 2884t/45.081s |
|
| 137 |
+
| 119 | My doctor has prescribed metformin for my Type 2 d... | patient | clinician ❌ | treatment | treatment ✅ | 85.0 | RoleClassifier: 330t/3.258s, IntentClassifier: 227t/2.235s, ClinicalSpecialist: 1444t/37.538s, OutputMerger: 2774t/41.96s |
|
| 138 |
+
| 120 | I've been following a low-carb diet to manage my b... | dietitian | dietary ❌ | general | unknown ❌ | 67.77 | RoleClassifier: 334t/2.489s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.006s, ToolsNode: 0t/0.001s, ResponseValidator: 1293t/5.421s, SafetyCheck: 1240t/5.838s |
|
| 139 |
+
| 121 | I've been experiencing constant fatigue and blurre... | patient | patient ✅ | diagnosis | unknown ❌ | 37.84 | RoleClassifier: 315t/2.46s, ResponseValidator: 1219t/2.916s, SafetyCheck: 1279t/2.085s, PersistenceNode: 0t/0.006s |
|
| 140 |
+
| 122 | What is the difference between metformin and sulfo... | clinician | clinician ✅ | treatment | treatment ✅ | 80.22 | RoleClassifier: 329t/2.47s, IntentClassifier: 238t/2.2s, ClinicalSpecialist: 1275t/35.184s, OutputMerger: 2473t/40.36s |
|
| 141 |
+
| 123 | I've been tracking my blood glucose levels daily, ... | patient | patient ✅ | monitoring | unknown ❌ | 95.52 | RoleClassifier: 327t/6.147s, ResponseValidator: 1798t/10.903s, SafetyCheck: 1848t/15.337s, PersistenceNode: 0t/0.029s |
|
| 142 |
+
| 124 | I recently underwent a low-carb diet for two month... | researcher | patient ❌ | general | unknown ❌ | 52.1 | RoleClassifier: 326t/9.206s, ResponseValidator: 983t/10.184s, SafetyCheck: 1018t/1.849s, PersistenceNode: 0t/0.023s |
|
| 143 |
+
| 125 | What are the best foods to include in a meal plan ... | dietitian | dietary ❌ | dietary | unknown ❌ | 159.23 | RoleClassifier: 324t/4.007s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.002s, ResponseValidator: 256t/9.053s, SafetyCheck: 309t/6.66s |
|
| 144 |
+
| 126 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 23.52 | RoleClassifier: 303t/2.61s, ResponseValidator: 693t/2.887s, SafetyCheck: 722t/2.666s, PersistenceNode: 0t/0.006s |
|
| 145 |
+
| 127 | What are the short-term effects of not taking metf... | patient | patient ✅ | treatment | unknown ❌ | 30.36 | RoleClassifier: 314t/2.767s, ResponseValidator: 1030t/5.149s, SafetyCheck: 1011t/2.387s, PersistenceNode: 0t/0.006s |
|
| 146 |
+
| 128 | How often should I check my blood glucose levels a... | patient | patient ✅ | monitoring | unknown ❌ | 36.55 | RoleClassifier: 309t/3.972s, ResponseValidator: 1137t/7.813s, SafetyCheck: 1002t/1.741s, PersistenceNode: 0t/0.04s |
|
| 147 |
+
| 129 | I've been trying the keto diet to manage my blood ... | researcher | dietary ❌ | general | unknown ❌ | 97.04 | RoleClassifier: 328t/10.32s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.036s, ToolsNode: 0t/0.001s, ResponseValidator: 1496t/3.26s, SafetyCheck: 1538t/1.795s |
|
| 148 |
+
| 130 | My doctor has prescribed insulin therapy for my di... | patient | clinician ❌ | treatment | treatment ✅ | 96.8 | RoleClassifier: 319t/4.709s, IntentClassifier: 224t/2.729s, ClinicalSpecialist: 1530t/44.431s, OutputMerger: 2909t/44.926s |
|
| 149 |
+
| 131 | I've been experiencing frequent urination and blur... | patient | patient ✅ | diagnosis | unknown ❌ | 29.7 | RoleClassifier: 310t/2.419s, ResponseValidator: 930t/3.48s, SafetyCheck: 956t/1.61s, PersistenceNode: 0t/0.02s |
|
| 150 |
+
| 132 | My doctor has prescribed metformin to help with my... | patient | clinician ❌ | treatment | treatment ✅ | 84.16 | RoleClassifier: 323t/3.12s, IntentClassifier: 220t/4.602s, ClinicalSpecialist: 1425t/40.435s, OutputMerger: 2200t/35.999s |
|
| 151 |
+
| 133 | I'm planning a road trip to India and want to know... | patient | patient ✅ | general | unknown ❌ | 45.12 | RoleClassifier: 348t/6.215s, ResponseValidator: 1093t/4.487s, SafetyCheck: 1141t/2.08s, PersistenceNode: 0t/0.029s |
|
| 152 |
+
| 134 | I've been having trouble controlling my blood suga... | patient | patient ✅ | monitoring | unknown ❌ | 48.74 | RoleClassifier: 322t/3.558s, ResponseValidator: 1381t/2.843s, SafetyCheck: 1417t/3.65s, PersistenceNode: 0t/0.006s |
|
| 153 |
+
| 135 | I'm considering switching from a basal insulin to ... | patient | patient ✅ | treatment | unknown ❌ | 55.14 | RoleClassifier: 336t/4.036s, ResponseValidator: 1642t/2.399s, SafetyCheck: 1696t/1.827s, PersistenceNode: 0t/0.007s |
|
| 154 |
+
| 136 | I've been experiencing extreme thirst and frequent... | patient | patient ✅ | diagnosis | unknown ❌ | 36.4 | RoleClassifier: 312t/2.981s, ResponseValidator: 888t/4.001s, SafetyCheck: 909t/2.854s, PersistenceNode: 0t/0.006s |
|
| 155 |
+
| 137 | What is the optimal target HbA1c level for a patie... | clinician | clinician ✅ | treatment | treatment ✅ | 105.64 | RoleClassifier: 329t/5.209s, IntentClassifier: 217t/2.187s, ClinicalSpecialist: 1561t/44.753s, OutputMerger: 3104t/53.479s |
|
| 156 |
+
| 138 | I've noticed that my feet are feeling numb and tin... | patient | patient ✅ | monitoring | unknown ❌ | 47.56 | RoleClassifier: 318t/5.239s, ResponseValidator: 1046t/3.542s, SafetyCheck: 1094t/9.272s, PersistenceNode: 0t/0.029s |
|
| 157 |
+
| 139 | What are the potential risks associated with takin... | researcher | clinician ❌ | treatment | treatment ✅ | 117.34 | RoleClassifier: 325t/2.673s, IntentClassifier: 223t/6.854s, ClinicalSpecialist: 1749t/56.344s, OutputMerger: 3397t/51.459s |
|
| 158 |
+
| 140 | I'm planning to start a new diet that's low in car... | dietitian | dietary ❌ | general | unknown ❌ | 87.78 | RoleClassifier: 323t/6.257s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.018s, ToolsNode: 0t/0.001s, ResponseValidator: 1671t/3.619s, SafetyCheck: 1705t/2.323s |
|
| 159 |
+
| 141 | I've been experiencing fatigue and blurred vision ... | patient | patient ✅ | diagnosis | unknown ❌ | 57.52 | RoleClassifier: 295t/11.983s, ResponseValidator: 981t/8.563s, SafetyCheck: 1000t/8.198s, PersistenceNode: 0t/0.006s |
|
| 160 |
+
| 142 | What is the difference between basal and backgroun... | clinician | patient ❌ | treatment | unknown ❌ | 39.73 | RoleClassifier: 310t/5.928s, ResponseValidator: 1174t/4.262s, SafetyCheck: 1166t/2.499s, PersistenceNode: 0t/0.04s |
|
| 161 |
+
| 143 | I've been tracking my blood glucose levels using a... | patient | patient ✅ | monitoring | unknown ❌ | 39.75 | RoleClassifier: 319t/3.511s, ResponseValidator: 1301t/4.697s, SafetyCheck: 1275t/1.809s, PersistenceNode: 0t/0.006s |
|
| 162 |
+
| 144 | Is it true that following a low-carb diet can help... | researcher | unknown ❌ | general | unknown ❌ | 7.54 | |
|
| 163 |
+
| 145 | I've been experiencing frequent urination and feel... | patient | patient ✅ | diagnosis | unknown ❌ | 40.88 | RoleClassifier: 316t/2.877s, ResponseValidator: 1460t/4.07s, SafetyCheck: 1494t/2.068s, PersistenceNode: 0t/0.006s |
|
| 164 |
+
| 146 | I've been experiencing excessive thirst and urinat... | patient | patient ✅ | diagnosis | unknown ❌ | 32.26 | RoleClassifier: 300t/2.245s, ResponseValidator: 731t/8.728s, SafetyCheck: 733t/1.728s, PersistenceNode: 0t/0.03s |
|
| 165 |
+
| 147 | What is the recommended HbA1c target range for pat... | clinician | clinician ✅ | treatment | general ❌ | 64.76 | RoleClassifier: 332t/2.977s, IntentClassifier: 214t/3.109s, ClinicalSpecialist: 1198t/31.592s, OutputMerger: 2337t/27.073s |
|
| 166 |
+
| 148 | I've noticed my feet are really cold all the time.... | patient | patient ✅ | diagnosis | unknown ❌ | 32.67 | RoleClassifier: 307t/3.039s, ResponseValidator: 864t/7.303s, SafetyCheck: 896t/1.644s, PersistenceNode: 0t/0.019s |
|
| 167 |
+
| 149 | How does a low-carb diet affect blood sugar levels... | dietitian | unknown ❌ | treatment | unknown ❌ | 8.59 | |
|
| 168 |
+
| 150 | I've had an episode of diabetic ketoacidosis (DKA)... | researcher | patient ❌ | monitoring | unknown ❌ | 54.63 | RoleClassifier: 325t/2.967s, ResponseValidator: 1626t/5.285s, SafetyCheck: 1594t/2.384s, PersistenceNode: 0t/0.024s |
|
| 169 |
+
| 151 | Doc, I've been experiencing frequent urination and... | patient | patient ✅ | diagnosis | unknown ❌ | 38.96 | RoleClassifier: 320t/2.302s, ResponseValidator: 1134t/6.148s, SafetyCheck: 1173t/1.745s, PersistenceNode: 0t/0.006s |
|
| 170 |
+
| 152 | I've been prescribed metformin for my type 2 diabe... | patient | patient ✅ | treatment | unknown ❌ | 48.14 | RoleClassifier: 325t/7.752s, ResponseValidator: 1292t/5.882s, SafetyCheck: 1254t/2.111s, PersistenceNode: 0t/0.006s |
|
| 171 |
+
| 153 | I've been tracking my glucose levels for a week, a... | patient | patient ✅ | monitoring | unknown ❌ | 67.63 | RoleClassifier: 350t/3.246s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.0s, ResponseValidator: 1390t/6.765s, SafetyCheck: 1268t/5.244s, PersistenceNode: 0t/0.006s |
|
| 172 |
+
| 154 | Can you explain the difference between carbohydrat... | patient | dietary ❌ | general | unknown ❌ | 87.09 | RoleClassifier: 343t/3.123s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.0s, ToolsNode: 0t/0.026s, ToolsNode: 0t/0.006s, ToolsNode: 0t/0.0s, ResponseValidator: 819t/8.714s, SafetyCheck: 811t/5.492s |
|
| 173 |
+
| 155 | I've been experiencing severe dehydration due to e... | patient | patient ✅ | general | unknown ❌ | 50.79 | RoleClassifier: 335t/10.434s, ResponseValidator: 1074t/3.496s, SafetyCheck: 1112t/2.762s, PersistenceNode: 0t/0.006s |
|
| 174 |
+
| 156 | I've been experiencing frequent urination and thir... | patient | patient ✅ | symptoms | unknown ❌ | 37.75 | RoleClassifier: 308t/4.267s, ResponseValidator: 745t/5.958s, SafetyCheck: 783t/6.424s, PersistenceNode: 0t/0.007s |
|
| 175 |
+
| 157 | What are the differences between metformin and pio... | clinician | clinician ✅ | treatment | treatment ✅ | 114.73 | RoleClassifier: 330t/10.567s, IntentClassifier: 240t/6.982s, ClinicalSpecialist: 1613t/51.087s, OutputMerger: 3145t/46.089s |
|
| 176 |
+
| 158 | I've noticed that my blood sugar levels are higher... | patient | dietary ❌ | general | unknown ❌ | 57.21 | RoleClassifier: 325t/8.5s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.023s, ToolsNode: 0t/0.001s, ResponseValidator: 207t/5.523s, SafetyCheck: 291t/9.205s |
|
| 177 |
+
| 159 | What is the significance of HbA1c levels in monito... | researcher | clinician ❌ | monitoring | monitoring ✅ | 91.07 | RoleClassifier: 317t/2.387s, IntentClassifier: 211t/8.891s, ClinicalSpecialist: 1383t/41.021s, OutputMerger: 2706t/38.768s |
|
| 178 |
+
| 160 | I'm planning to start a low-carb diet. Can you pro... | dietitian | unknown ❌ | general | unknown ❌ | 6.03 | |
|
| 179 |
+
| 161 | I've been experiencing recurring fatigue and blurr... | patient | patient ✅ | diagnosis | unknown ❌ | 47.62 | RoleClassifier: 315t/5.742s, ResponseValidator: 1382t/4.156s, SafetyCheck: 1388t/3.488s, PersistenceNode: 0t/0.006s |
|
| 180 |
+
| 162 | How often should I check my blood sugar levels, an... | patient | patient ✅ | monitoring | unknown ❌ | 45.21 | RoleClassifier: 311t/4.621s, ResponseValidator: 1083t/9.697s, SafetyCheck: 982t/3.936s, PersistenceNode: 0t/0.024s |
|
| 181 |
+
| 163 | I've been prescribed metformin to help with my ins... | patient | clinician ❌ | treatment | treatment ✅ | 71.52 | RoleClassifier: 313t/2.478s, IntentClassifier: 210t/3.039s, ClinicalSpecialist: 1137t/37.421s, OutputMerger: 2220t/28.577s |
|
| 182 |
+
| 164 | Can you recommend a healthy meal plan for someone ... | dietitian | dietary ❌ | general | unknown ❌ | 43.51 | RoleClassifier: 310t/2.459s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.006s, ToolsNode: 0t/0.006s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ResponseValidator: 280t/2.046s, SafetyCheck: 333t/1.974s |
|
| 183 |
+
| 165 | What's the difference between HbA1c and glucose mo... | researcher | patient ❌ | diagnosis | unknown ❌ | 37.85 | RoleClassifier: 322t/2.43s, ResponseValidator: 1065t/4.758s, SafetyCheck: 1075t/1.92s, PersistenceNode: 0t/0.026s |
|
| 184 |
+
| 166 | I've been experiencing excessive thirst and urinat... | patient | patient ✅ | diagnosis | unknown ❌ | 27.3 | RoleClassifier: 309t/2.118s, ResponseValidator: 901t/2.689s, SafetyCheck: 938t/3.962s, PersistenceNode: 0t/0.006s |
|
| 185 |
+
| 167 | What is the optimal HbA1c target for someone with ... | clinician | clinician ✅ | treatment | general ❌ | 70.84 | RoleClassifier: 328t/3.119s, IntentClassifier: 225t/2.006s, ClinicalSpecialist: 1320t/35.454s, OutputMerger: 2587t/30.248s |
|
| 186 |
+
| 168 | I've been noticing numbness in my feet, which I su... | patient | patient ✅ | general | unknown ❌ | 43.75 | RoleClassifier: 320t/2.439s, ResponseValidator: 1323t/3.272s, SafetyCheck: 1360t/2.218s, PersistenceNode: 0t/0.029s |
|
| 187 |
+
| 169 | My doctor recently started me on metformin for my ... | pregnant patient | clinician ❌ | treatment | general ❌ | 73.51 | RoleClassifier: 315t/7.363s, IntentClassifier: 224t/1.998s, ClinicalSpecialist: 1259t/36.699s, OutputMerger: 2385t/27.442s |
|
| 188 |
+
| 170 | I've been tracking my glucose levels using a conti... | patient | patient ✅ | monitoring | unknown ❌ | 49.67 | RoleClassifier: 336t/3.791s, ResponseValidator: 1389t/6.95s, SafetyCheck: 1339t/1.876s, PersistenceNode: 0t/0.03s |
|
| 189 |
+
| 171 | I've been experiencing frequent urination and blur... | patient | patient ✅ | symptoms | unknown ❌ | 45.95 | RoleClassifier: 313t/5.483s, ResponseValidator: 1403t/4.571s, SafetyCheck: 1439t/3.363s, PersistenceNode: 0t/0.04s |
|
| 190 |
+
| 172 | What is the recommended HbA1c target range for a p... | clinician | clinician ✅ | diagnosis | monitoring ❌ | 52.28 | RoleClassifier: 320t/2.909s, IntentClassifier: 227t/3.139s, ClinicalSpecialist: 1011t/25.743s, OutputMerger: 1779t/20.477s |
|
| 191 |
+
| 173 | I've been following a keto diet to manage my blood... | patient | dietary ❌ | dietary | unknown ❌ | 44.99 | RoleClassifier: 330t/2.908s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.007s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.037s, ResponseValidator: 365t/4.544s, SafetyCheck: 414t/2.491s |
|
| 192 |
+
| 174 | I've been experiencing severe headaches and fatigu... | patient | patient ✅ | treatment | unknown ❌ | 47.6 | RoleClassifier: 322t/2.364s, ResponseValidator: 1256t/4.015s, SafetyCheck: 1346t/4.894s, PersistenceNode: 0t/0.02s |
|
| 193 |
+
| 175 | I've been reading about the potential benefits of ... | researcher | patient ❌ | monitoring | unknown ❌ | 42.75 | RoleClassifier: 347t/2.98s, ResponseValidator: 1397t/5.886s, SafetyCheck: 1363t/2.111s, PersistenceNode: 0t/0.007s |
|
| 194 |
+
| 176 | I keep experiencing sudden episodes of blurry visi... | patient | patient ✅ | diagnosis | unknown ❌ | 40.29 | RoleClassifier: 329t/2.861s, ResponseValidator: 1125t/4.845s, SafetyCheck: 1137t/6.876s, PersistenceNode: 0t/0.023s |
|
| 195 |
+
| 177 | What's the difference between basal and bolus insu... | patient | patient ✅ | treatment | unknown ❌ | 51.94 | RoleClassifier: 322t/2.788s, ResponseValidator: 1396t/6.78s, SafetyCheck: 1338t/2.195s, PersistenceNode: 0t/0.006s |
|
| 196 |
+
| 178 | I've been following a low-carb diet for the past w... | dietitian | unknown ❌ | general | unknown ❌ | 6.28 | |
|
| 197 |
+
| 179 | My doctor recently told me I have high HbA1c level... | patient | patient ✅ | diagnosis | unknown ❌ | 76.9 | RoleClassifier: 333t/3.765s, ResponseValidator: 1239t/6.707s, SafetyCheck: 1261t/1.674s, PersistenceNode: 0t/0.021s |
|
| 198 |
+
| 180 | I've been researching different types of diabetes ... | researcher | clinician ❌ | general | treatment ❌ | 19.84 | RoleClassifier: 321t/3.344s, IntentClassifier: 228t/2.567s, ClinicalSpecialist: 336t/7.206s, OutputMerger: 603t/6.711s |
|
| 199 |
+
| 181 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 39.82 | RoleClassifier: 325t/8.572s, ResponseValidator: 1034t/2.624s, SafetyCheck: 1072t/2.038s, PersistenceNode: 0t/0.027s |
|
| 200 |
+
| 182 | I'm trying to lose weight and was wondering if it'... | patient | unknown ❌ | treatment | unknown ❌ | 7.37 | |
|
| 201 |
+
| 183 | My HbA1c test result came back at 7.5%. Is that wi... | patient | patient ✅ | monitoring | unknown ❌ | 37.83 | RoleClassifier: 326t/5.908s, ResponseValidator: 1177t/5.909s, SafetyCheck: 1200t/1.812s, PersistenceNode: 0t/0.006s |
|
| 202 |
+
| 184 | I've been prescribed metformin for my type 2 diabe... | patient | patient ✅ | treatment | unknown ❌ | 46.13 | RoleClassifier: 328t/3.34s, ResponseValidator: 1446t/5.314s, SafetyCheck: 1374t/2.43s, PersistenceNode: 0t/0.024s |
|
| 203 |
+
| 185 | I've noticed some numbness in my fingers and toes,... | patient | patient ✅ | diagnosis | unknown ❌ | 53.25 | RoleClassifier: 330t/2.898s, ResponseValidator: 1521t/5.124s, SafetyCheck: 1574t/5.776s, PersistenceNode: 0t/0.006s |
|
| 204 |
+
| 186 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 32.41 | RoleClassifier: 310t/3.167s, ResponseValidator: 871t/2.807s, SafetyCheck: 912t/2.109s, PersistenceNode: 0t/0.018s |
|
| 205 |
+
| 187 | What are the recommended daily carb limits for a t... | researcher | dietary ❌ | treatment | unknown ❌ | 83.23 | RoleClassifier: 316t/6.01s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.027s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.001s, ResponseValidator: 926t/7.715s, SafetyCheck: 923t/3.888s |
|
| 206 |
+
| 188 | I've been tracking my glucose levels and noticed t... | dietary | dietary ✅ | general | unknown ❌ | 55.03 | RoleClassifier: 321t/5.965s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.002s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.024s, ToolsNode: 0t/0.001s, ResponseValidator: 446t/6.595s, SafetyCheck: 465t/1.894s |
|
| 207 |
+
| 189 | My doctor just diagnosed me with diabetic retinopa... | patient | patient ✅ | treatment | unknown ❌ | 47.3 | RoleClassifier: 328t/2.785s, ResponseValidator: 1505t/4.019s, SafetyCheck: 1528t/1.829s, PersistenceNode: 0t/0.006s |
|
| 208 |
+
| 190 | I've been taking metformin for my type 2 diabetes,... | patient | patient ✅ | treatment | unknown ❌ | 42.42 | RoleClassifier: 338t/2.41s, ResponseValidator: 1265t/6.67s, SafetyCheck: 1280t/2.775s, PersistenceNode: 0t/0.006s |
|
| 209 |
+
| 191 | I've been experiencing frequent urination and feel... | patient | patient ✅ | diagnosis | unknown ❌ | 28.37 | RoleClassifier: 300t/7.086s, ResponseValidator: 572t/3.171s, SafetyCheck: 604t/4.334s, PersistenceNode: 0t/0.006s |
|
| 210 |
+
| 192 | What is the difference between basal insulin and b... | clinician | patient ❌ | treatment | unknown ❌ | 80.35 | RoleClassifier: 308t/10.365s, ResponseValidator: 1375t/12.809s, SafetyCheck: 1266t/7.487s, PersistenceNode: 0t/0.019s |
|
| 211 |
+
| 193 | I've had high blood sugar levels for a while, but ... | patient | patient ✅ | monitoring | unknown ❌ | 62.38 | RoleClassifier: 331t/7.873s, ResponseValidator: 1044t/6.706s, SafetyCheck: 1084t/5.39s, PersistenceNode: 0t/0.006s |
|
| 212 |
+
| 194 | How does the glycemic index of different foods aff... | researcher | dietary ❌ | general | unknown ❌ | 50.38 | RoleClassifier: 313t/10.066s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.001s, ToolsNode: 0t/0.006s, ToolsNode: 0t/0.001s, ResponseValidator: 255t/7.451s, SafetyCheck: 318t/8.845s |
|
| 213 |
+
| 195 | I've been experiencing numbness and tingling in my... | patient | patient ✅ | diagnosis | unknown ❌ | 56.54 | RoleClassifier: 306t/5.68s, ResponseValidator: 1057t/8.818s, SafetyCheck: 1065t/13.844s, PersistenceNode: 0t/0.006s |
|
| 214 |
+
| 196 | I've been experiencing frequent urination and blur... | patient | patient ✅ | diagnosis | unknown ❌ | 62.58 | RoleClassifier: 310t/9.06s, ResponseValidator: 1164t/9.602s, SafetyCheck: 1206t/3.469s, PersistenceNode: 0t/0.019s |
|
| 215 |
+
| 197 | How does metformin affect my blood sugar levels du... | patient | clinician ❌ | treatment | treatment ✅ | 73.51 | RoleClassifier: 315t/4.751s, IntentClassifier: 205t/3.484s, ClinicalSpecialist: 1151t/30.641s, OutputMerger: 2243t/34.622s |
|
| 216 |
+
| 198 | I've been tracking my glucose levels using a Conti... | patient | patient ✅ | monitoring | unknown ❌ | 72.88 | RoleClassifier: 336t/8.159s, ResponseValidator: 1260t/19.715s, SafetyCheck: 1128t/8.634s, PersistenceNode: 0t/0.006s |
|
| 217 |
+
| 199 | I've been advised to follow a low-carb diet to man... | dietary | unknown ❌ | treatment | unknown ❌ | 17.27 | |
|
| 218 |
+
| 200 | What are the potential risks associated with takin... | patient | patient ✅ | diagnosis | unknown ❌ | 64.32 | RoleClassifier: 321t/6.144s, ResponseValidator: 1494t/5.185s, SafetyCheck: 1552t/2.882s, PersistenceNode: 0t/0.006s |
|
performance_reports/report_openrouter_openai_gpt-oss-20b_free_2026-04-28_15-06-07.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Performance Report
|
| 2 |
+
|
| 3 |
+
## Summary
|
| 4 |
+
|
| 5 |
+
**Timestamp**: 2026-04-28_15-06-07
|
| 6 |
+
**Provider**: openrouter
|
| 7 |
+
**Model**: openai/gpt-oss-20b:free
|
| 8 |
+
**Total Requests Sent**: 1048
|
| 9 |
+
**Total Tokens Used**: 1.401M
|
| 10 |
+
|
| 11 |
+
**Total Tests Run**: 200
|
| 12 |
+
**Total Execution Time**: 13233.32s
|
| 13 |
+
**Average Time per Test**: 66.17s
|
| 14 |
+
**Role Match Rate**: 126/200 (63.0%)
|
| 15 |
+
**Intent Match Rate**: 27/200 (13.5%)
|
| 16 |
+
|
| 17 |
+
## Detailed Results
|
| 18 |
+
|
| 19 |
+
| ID | Question | Expected Role | Detected Role | Expected Intent | Detected Intent | Time (s) | Requests | Tokens |
|
| 20 |
+
| --- | ----------------------------------------------------- | ---------------- | ------------- | -------------------- | --------------- | -------- | --- | --- |
|
| 21 |
+
| 1 | I've been feeling really thirsty and urinating a l... | patient | patient ✅ | diagnosis | unknown ❌ | 22.83 |
|
| 22 |
+
| 2 | What is the optimal HbA1c target for a patient wit... | clinician | clinician ✅ | treatment | treatment ✅ | 50.31 |
|
| 23 |
+
| 3 | I've been taking metformin for my polycystic ovary... | patient | patient ✅ | treatment | unknown ❌ | 59.07 |
|
| 24 |
+
| 4 | What is the recommended diet for a patient with di... | dietitian | dietary ❌ | general | unknown ❌ | 92.62 |
|
| 25 |
+
| 5 | I'm planning to start a new exercise program to ma... | patient | patient ✅ | monitoring | unknown ❌ | 31.17 |
|
| 26 |
+
| 6 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 25.35 |
|
| 27 |
+
| 7 | My doctor just told me that my HbA1c levels are hi... | patient | clinician ❌ | treatment | treatment ✅ | 190.0 |
|
| 28 |
+
| 8 | I've been tracking my glucose levels using a conti... | patient | patient ✅ | monitoring | unknown ❌ | 39.87 |
|
| 29 |
+
| 9 | I've been reading about different diets for people... | researcher | unknown ❌ | general | unknown ❌ | 7.14 |
|
| 30 |
+
| 10 | My friend just got diagnosed with Type 2 diabetes,... | clinician | clinician ✅ | treatment | treatment ✅ | 126.99 |
|
| 31 |
+
| 11 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 67.34 |
|
| 32 |
+
| 12 | What is the recommended daily intake of carbohydra... | dietitian | dietary ❌ | treatment | unknown ❌ | 146.45 |
|
| 33 |
+
| 13 | My blood glucose levels have been consistently hig... | patient | patient ✅ | monitoring | unknown ❌ | 64.42 |
|
| 34 |
+
| 14 | I've been prescribed insulin glargine for my Type ... | patient | patient ✅ | treatment | unknown ❌ | 67.96 |
|
| 35 |
+
| 15 | A recent study suggests that incorporating more pl... | researcher | unknown ❌ | general | unknown ❌ | 17.63 |
|
| 36 |
+
| 16 | My mother was recently diagnosed with Type 2 diabe... | patient | patient ✅ | diagnosis | unknown ❌ | 80.04 |
|
| 37 |
+
| 17 | I've been taking metformin as prescribed by my doc... | patient | clinician ❌ | treatment | treatment ✅ | 129.58 |
|
| 38 |
+
| 18 | I've noticed that I've been getting really thirsty... | patient | patient ✅ | diagnosis | unknown ❌ | 61.51 |
|
| 39 |
+
| 19 | I'm planning to start a new diet that's high in su... | patient | dietary ❌ | general | unknown ❌ | 149.53 |
|
| 40 |
+
| 20 | My doctor mentioned that I should monitor my blood... | patient | patient ✅ | monitoring | unknown ❌ | 60.05 |
|
| 41 |
+
| 21 | I've been experiencing excessive thirst and urinat... | patient | patient ✅ | symptoms | unknown ❌ | 40.0 |
|
| 42 |
+
| 22 | My doctor has prescribed metformin for my Type 2 d... | patient | clinician ❌ | treatment | treatment ✅ | 93.22 |
|
| 43 |
+
| 23 | I'm planning to start a new exercise routine to ma... | patient | patient ✅ | lifestyle | unknown ❌ | 59.62 |
|
| 44 |
+
| 24 | I've been experiencing frequent episodes of hypogl... | patient | patient ✅ | complication | unknown ❌ | 105.03 |
|
| 45 |
+
| 25 | What are the most effective dietary habits for man... | dietitian | dietary ❌ | lifestyle | unknown ❌ | 240.49 |
|
| 46 |
+
| 26 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 47.93 |
|
| 47 |
+
| 27 | My doctor has prescribed metformin for my Type 1 d... | patient | patient ✅ | treatment | unknown ❌ | 85.82 |
|
| 48 |
+
| 28 | What is the ideal HbA1c target range for a patient... | clinician | clinician ✅ | diagnosis | treatment ❌ | 123.49 |
|
| 49 |
+
| 29 | I've been eating a lot of sweet dishes during fest... | patient | dietary ❌ | treatment | unknown ❌ | 160.96 |
|
| 50 |
+
| 30 | Are there any clinical trials or studies currently... | researcher | researcher ✅ | general | unknown ❌ | 71.55 |
|
| 51 |
+
| 31 | I've been experiencing frequent urination and my h... | patient | patient ✅ | symptoms | unknown ❌ | 58.89 |
|
| 52 |
+
| 32 | My HbA1c level is 8.5%, I'm currently on metformin... | patient | clinician ❌ | treatment | treatment ✅ | 91.23 |
|
| 53 |
+
| 33 | I've been told I have gestational diabetes, what d... | pregnant woman | dietary ❌ | prevention | unknown ❌ | 57.36 |
|
| 54 |
+
| 34 | My doctor wants me to start monitoring my blood gl... | patient | patient ✅ | monitoring | unknown ❌ | 63.96 |
|
| 55 |
+
| 35 | I've been reading about the benefits of a low-carb... | patient | unknown ❌ | lifestyle management | unknown ❌ | 5.38 |
|
| 56 |
+
| 36 | I've been experiencing excessive thirst and urinat... | patient | patient ✅ | diagnosis | unknown ❌ | 34.68 |
|
| 57 |
+
| 37 | My doctor has prescribed metformin to help lower m... | patient | clinician ❌ | treatment | treatment ✅ | 95.85 |
|
| 58 |
+
| 38 | I've been tracking my blood glucose levels for a f... | patient | patient ✅ | monitoring | unknown ❌ | 75.54 |
|
| 59 |
+
| 39 | I've recently started incorporating more plant-bas... | patient | dietary ❌ | general | unknown ❌ | 107.32 |
|
| 60 |
+
| 40 | I've been diagnosed with diabetic ketoacidosis (DK... | patient | patient ✅ | diagnosis | unknown ❌ | 45.68 |
|
| 61 |
+
| 41 | I've been experiencing numbness in my hands for th... | patient | patient ✅ | symptoms | unknown ❌ | 41.54 |
|
| 62 |
+
| 42 | What are the benefits of using a continuous glucos... | researcher | patient ❌ | treatment | unknown ❌ | 50.77 |
|
| 63 |
+
| 43 | Can you recommend some low-carb Indian recipes tha... | patient | unknown ❌ | lifestyle | unknown ❌ | 9.38 |
|
| 64 |
+
| 44 | I've been diagnosed with gestational diabetes and ... | pregnant woman | patient ❌ | diagnosis | unknown ❌ | 59.24 |
|
| 65 |
+
| 45 | How does metformin work in treating type 2 diabete... | clinician | clinician ✅ | treatment | general ❌ | 106.55 |
|
| 66 |
+
| 46 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 34.13 |
|
| 67 |
+
| 47 | What is the optimal HbA1c target for a patient wit... | clinician | clinician ✅ | treatment | treatment ✅ | 90.33 |
|
| 68 |
+
| 48 | I've been tracking my daily glucose levels using m... | patient | patient ✅ | monitoring | unknown ❌ | 24.89 |
|
| 69 |
+
| 49 | What are the latest guidelines for carbohydrate co... | researcher | clinician ❌ | treatment | general ❌ | 147.29 |
|
| 70 |
+
| 50 | I've been experiencing extreme thirst and hunger, ... | patient | patient ✅ | diagnosis | unknown ❌ | 59.71 |
|
| 71 |
+
| 51 | My doctor says I need to monitor my blood sugar le... | patient | patient ✅ | monitoring | unknown ❌ | 49.04 |
|
| 72 |
+
| 52 | I've been prescribed metformin for my diabetes, bu... | patient | patient ✅ | treatment | unknown ❌ | 67.6 |
|
| 73 |
+
| 53 | My friend has just been diagnosed with Gestational... | clinician | patient ❌ | diagnosis | unknown ❌ | 83.64 |
|
| 74 |
+
| 54 | I've noticed I'm experiencing frequent urination a... | patient | patient ✅ | symptoms | unknown ❌ | 84.71 |
|
| 75 |
+
| 55 | A recent study suggests that a specific dietary ap... | researcher | dietary ❌ | general | unknown ❌ | 166.94 |
|
| 76 |
+
| 56 | Doc, I've been experiencing weird tingling sensati... | patient | patient ✅ | symptoms | unknown ❌ | 54.72 |
|
| 77 |
+
| 57 | How often should I check my blood glucose levels, ... | clinician | patient ❌ | monitoring | unknown ❌ | 63.79 |
|
| 78 |
+
| 58 | I've been prescribed metformin for my gestational ... | patient | patient ✅ | treatment | unknown ❌ | 69.84 |
|
| 79 |
+
| 59 | If my HbA1c levels are consistently above 8%, does... | patient | patient ✅ | diagnosis | unknown ❌ | 49.93 |
|
| 80 |
+
| 60 | What's the best way to incorporate more plant-base... | researcher | unknown ❌ | dietary | unknown ❌ | 25.81 |
|
| 81 |
+
| 61 | I've been experiencing recurring chest pains when ... | patient | patient ✅ | diagnosis | unknown ❌ | 58.98 |
|
| 82 |
+
| 62 | My doctor prescribed metformin for my Type 2 diabe... | patient | clinician ❌ | treatment | treatment ✅ | 190.3 |
|
| 83 |
+
| 63 | I've noticed that my blood glucose levels tend to ... | patient | patient ✅ | monitoring | unknown ❌ | 77.67 |
|
| 84 |
+
| 64 | I've been reading about the benefits of a low-carb... | patient | unknown ❌ | general | unknown ❌ | 21.56 |
|
| 85 |
+
| 65 | I have a family history of Type 2 diabetes and am ... | patient | patient ✅ | prevention | unknown ❌ | 58.93 |
|
| 86 |
+
| 66 | I've been experiencing frequent urination and blur... | patient | patient ✅ | diagnosis | unknown ❌ | 66.1 |
|
| 87 |
+
| 67 | My HbA1c levels are consistently above 7%. What is... | patient | clinician ❌ | treatment | treatment ✅ | 165.33 |
|
| 88 |
+
| 68 | I've been taking insulin twice a day, but I'm stil... | patient | clinician ❌ | treatment | treatment ✅ | 141.41 |
|
| 89 |
+
| 69 | Can you explain the benefits and risks of switchin... | clinician | clinician ✅ | treatment | treatment ✅ | 141.79 |
|
| 90 |
+
| 70 | I'm considering a low-carb diet to manage my blood... | dietary | unknown ❌ | general | unknown ❌ | 12.02 |
|
| 91 |
+
| 71 | I've been experiencing weird tingling sensations i... | patient | patient ✅ | diagnosis | unknown ❌ | 56.09 |
|
| 92 |
+
| 72 | I was recently diagnosed with Type 2 diabetes, and... | patient | clinician ❌ | treatment | treatment ✅ | 94.25 |
|
| 93 |
+
| 73 | My fasting glucose levels have been consistently h... | patient | patient ✅ | monitoring | unknown ❌ | 57.44 |
|
| 94 |
+
| 74 | I've been reading about the benefits of a low-carb... | patient | unknown ❌ | general | unknown ❌ | 9.09 |
|
| 95 |
+
| 75 | I'm a researcher studying the effects of insulin p... | researcher | researcher ✅ | general | unknown ❌ | 39.04 |
|
| 96 |
+
| 76 | My blood sugar levels have been fluctuating a lot ... | patient | patient ✅ | diagnosis | unknown ❌ | 64.17 |
|
| 97 |
+
| 77 | I recently had an HbA1c test done and my levels ar... | patient | patient ✅ | diagnosis | unknown ❌ | 60.32 |
|
| 98 |
+
| 78 | I'm considering taking metformin to manage my bloo... | patient | patient ✅ | treatment | unknown ❌ | 72.92 |
|
| 99 |
+
| 79 | I'm planning a road trip with friends, but I'm wor... | patient | patient ✅ | general | unknown ❌ | 66.87 |
|
| 100 |
+
| 80 | My doctor mentioned that I may be at risk for diab... | patient | patient ✅ | diagnosis | unknown ❌ | 48.54 |
|
| 101 |
+
| 81 | I've been feeling really thirsty and hungry lately... | patient | patient ✅ | symptoms | unknown ❌ | 31.5 |
|
| 102 |
+
| 82 | My HbA1c levels are consistently above 7%, and my ... | patient | unknown ❌ | treatment | unknown ❌ | 25.3 |
|
| 103 |
+
| 83 | I have type 2 diabetes, and my doctor recommended ... | patient | patient ✅ | diagnosis | unknown ❌ | 54.62 |
|
| 104 |
+
| 84 | My blood glucose levels are fluctuating wildly thr... | clinician | patient ❌ | monitoring | unknown ❌ | 62.76 |
|
| 105 |
+
| 85 | I've been hearing about a new type of insulin pump... | researcher | patient ❌ | treatment | unknown ❌ | 90.44 |
|
| 106 |
+
| 86 | I've been experiencing extreme thirst and frequent... | patient | patient ✅ | treatment | unknown ❌ | 58.73 |
|
| 107 |
+
| 87 | What is the recommended HbA1c target for a patient... | clinician | clinician ✅ | management | treatment ❌ | 69.82 |
|
| 108 |
+
| 88 | I'm trying to follow a low-carb diet, but I keep r... | dietary | unknown ❌ | general | unknown ❌ | 5.13 |
|
| 109 |
+
| 89 | I've been feeling dizzy during physical activity. ... | patient | patient ✅ | diagnosis | unknown ❌ | 66.82 |
|
| 110 |
+
| 90 | What are the latest guidelines for foot care in pa... | clinician | clinician ✅ | management | general ❌ | 100.9 |
|
| 111 |
+
| 91 | I've been experiencing frequent urination and my h... | patient | patient ✅ | symptoms | unknown ❌ | 32.4 |
|
| 112 |
+
| 92 | What is the difference between a glucometer and a ... | patient | patient ✅ | diagnosis | unknown ❌ | 58.54 |
|
| 113 |
+
| 93 | I've been taking metformin to control my blood sug... | patient | clinician ❌ | treatment | treatment ✅ | 104.51 |
|
| 114 |
+
| 94 | I've been diagnosed with diabetic retinopathy, wha... | patient | patient ✅ | complications | unknown ❌ | 51.65 |
|
| 115 |
+
| 95 | What is the recommended carb count for a person wi... | dietitian | unknown ❌ | lifestyle management | unknown ❌ | 15.03 |
|
| 116 |
+
| 96 | I've been experiencing frequent urination and blur... | patient | patient ✅ | symptoms | unknown ❌ | 41.09 |
|
| 117 |
+
| 97 | What is the optimal HbA1c target for a patient wit... | clinician | clinician ✅ | treatment | treatment ✅ | 106.5 |
|
| 118 |
+
| 98 | I've been trying various low-carb diets but still ... | patient | dietary ❌ | general | unknown ❌ | 80.49 |
|
| 119 |
+
| 99 | My doctor has prescribed metformin, but I'm experi... | patient | patient ✅ | treatment | unknown ❌ | 33.32 |
|
| 120 |
+
| 100 | I've noticed my feet swelling after meals. Is this... | patient | patient ✅ | symptoms | unknown ❌ | 37.58 |
|
| 121 |
+
| 101 | I've been experiencing frequent urination and blur... | patient | patient ✅ | diagnosis | unknown ❌ | 31.88 |
|
| 122 |
+
| 102 | What are some effective ways to manage blood sugar... | researcher | dietary ❌ | general | unknown ❌ | 57.01 |
|
| 123 |
+
| 103 | I'm scheduled for a flu shot, but I have diabetes.... | patient | patient ✅ | monitoring | unknown ❌ | 38.82 |
|
| 124 |
+
| 104 | What is the recommended HbA1c target range for peo... | clinician | clinician ✅ | treatment | treatment ✅ | 101.87 |
|
| 125 |
+
| 105 | Can you recommend a low-carb diet plan that suits ... | dietary | unknown ❌ | general | unknown ❌ | 11.44 |
|
| 126 |
+
| 106 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 49.1 |
|
| 127 |
+
| 107 | My doctor just prescribed me metformin to control ... | patient | dietary ❌ | treatment | unknown ❌ | 126.44 |
|
| 128 |
+
| 108 | I'm a type 2 diabetic patient, I've been monitorin... | patient | patient ✅ | monitoring | unknown ❌ | 64.53 |
|
| 129 |
+
| 109 | I've been reading about the benefits of a ketogeni... | researcher | researcher ✅ | general | unknown ❌ | 21.1 |
|
| 130 |
+
| 110 | I have gestational diabetes and I'm due to give bi... | patient | patient ✅ | diagnosis | unknown ❌ | 65.06 |
|
| 131 |
+
| 111 | I've been experiencing blurred vision and frequent... | patient | patient ✅ | diagnosis | unknown ❌ | 42.77 |
|
| 132 |
+
| 112 | My doctor prescribed me metformin to control my bl... | patient | patient ✅ | treatment | unknown ❌ | 74.88 |
|
| 133 |
+
| 113 | I've been tracking my glucose levels using a conti... | patient | patient ✅ | monitoring | unknown ❌ | 52.27 |
|
| 134 |
+
| 114 | I've been reading about the importance of a balanc... | dietary | unknown ❌ | general | unknown ❌ | 91.69 |
|
| 135 |
+
| 115 | I'm planning to participate in a clinical trial fo... | researcher | clinician ❌ | general | treatment ❌ | 133.64 |
|
| 136 |
+
| 116 | I've been experiencing frequent urination and blur... | patient | patient ✅ | diagnosis | unknown ❌ | 42.48 |
|
| 137 |
+
| 117 | What is the ideal HbA1c target for someone with Ty... | patient | patient ✅ | treatment | unknown ❌ | 62.71 |
|
| 138 |
+
| 118 | I recently underwent a kidney biopsy due to suspec... | researcher | clinician ❌ | diagnosis | general ❌ | 86.66 |
|
| 139 |
+
| 119 | My doctor has prescribed metformin for my Type 2 d... | patient | clinician ❌ | treatment | treatment ✅ | 104.88 |
|
| 140 |
+
| 120 | I've been following a low-carb diet to manage my b... | dietitian | dietary ❌ | general | unknown ❌ | 85.07 |
|
| 141 |
+
| 121 | I've been experiencing constant fatigue and blurre... | patient | patient ✅ | diagnosis | unknown ❌ | 49.04 |
|
| 142 |
+
| 122 | What is the difference between metformin and sulfo... | clinician | clinician ✅ | treatment | treatment ✅ | 93.15 |
|
| 143 |
+
| 123 | I've been tracking my blood glucose levels daily, ... | patient | patient ✅ | monitoring | unknown ❌ | 63.2 |
|
| 144 |
+
| 124 | I recently underwent a low-carb diet for two month... | researcher | patient ❌ | general | unknown ❌ | 40.87 |
|
| 145 |
+
| 125 | What are the best foods to include in a meal plan ... | dietitian | dietary ❌ | dietary | unknown ❌ | 48.19 |
|
| 146 |
+
| 126 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 21.23 |
|
| 147 |
+
| 127 | What are the short-term effects of not taking metf... | patient | patient ✅ | treatment | unknown ❌ | 22.1 |
|
| 148 |
+
| 128 | How often should I check my blood glucose levels a... | patient | patient ✅ | monitoring | unknown ❌ | 38.62 |
|
| 149 |
+
| 129 | I've been trying the keto diet to manage my blood ... | researcher | dietary ❌ | general | unknown ❌ | 49.0 |
|
| 150 |
+
| 130 | My doctor has prescribed insulin therapy for my di... | patient | clinician ❌ | treatment | treatment ✅ | 96.03 |
|
| 151 |
+
| 131 | I've been experiencing frequent urination and blur... | patient | patient ✅ | diagnosis | unknown ❌ | 39.81 |
|
| 152 |
+
| 132 | My doctor has prescribed metformin to help with my... | patient | patient ✅ | treatment | unknown ❌ | 34.48 |
|
| 153 |
+
| 133 | I'm planning a road trip to India and want to know... | patient | dietary ❌ | general | unknown ❌ | 35.11 |
|
| 154 |
+
| 134 | I've been having trouble controlling my blood suga... | patient | patient ✅ | monitoring | unknown ❌ | 31.51 |
|
| 155 |
+
| 135 | I'm considering switching from a basal insulin to ... | patient | patient ✅ | treatment | unknown ❌ | 41.58 |
|
| 156 |
+
| 136 | I've been experiencing extreme thirst and frequent... | patient | patient ✅ | diagnosis | unknown ❌ | 36.21 |
|
| 157 |
+
| 137 | What is the optimal target HbA1c level for a patie... | clinician | clinician ✅ | treatment | treatment ✅ | 132.91 |
|
| 158 |
+
| 138 | I've noticed that my feet are feeling numb and tin... | patient | patient ✅ | monitoring | unknown ❌ | 39.86 |
|
| 159 |
+
| 139 | What are the potential risks associated with takin... | researcher | clinician ❌ | treatment | treatment ✅ | 92.02 |
|
| 160 |
+
| 140 | I'm planning to start a new diet that's low in car... | dietitian | dietary ❌ | general | unknown ❌ | 48.96 |
|
| 161 |
+
| 141 | I've been experiencing fatigue and blurred vision ... | patient | patient ✅ | diagnosis | unknown ❌ | 27.47 |
|
| 162 |
+
| 142 | What is the difference between basal and backgroun... | clinician | patient ❌ | treatment | unknown ❌ | 37.7 |
|
| 163 |
+
| 143 | I've been tracking my blood glucose levels using a... | patient | patient ✅ | monitoring | unknown ❌ | 38.88 |
|
| 164 |
+
| 144 | Is it true that following a low-carb diet can help... | researcher | unknown ❌ | general | unknown ❌ | 5.23 |
|
| 165 |
+
| 145 | I've been experiencing frequent urination and feel... | patient | patient ✅ | diagnosis | unknown ❌ | 41.52 |
|
| 166 |
+
| 146 | I've been experiencing excessive thirst and urinat... | patient | patient ✅ | diagnosis | unknown ❌ | 25.21 |
|
| 167 |
+
| 147 | What is the recommended HbA1c target range for pat... | clinician | clinician ✅ | treatment | general ❌ | 70.97 |
|
| 168 |
+
| 148 | I've noticed my feet are really cold all the time.... | patient | patient ✅ | diagnosis | unknown ❌ | 24.49 |
|
| 169 |
+
| 149 | How does a low-carb diet affect blood sugar levels... | dietitian | unknown ❌ | treatment | unknown ❌ | 4.93 |
|
| 170 |
+
| 150 | I've had an episode of diabetic ketoacidosis (DKA)... | researcher | patient ❌ | monitoring | unknown ❌ | 45.2 |
|
| 171 |
+
| 151 | Doc, I've been experiencing frequent urination and... | patient | patient ✅ | diagnosis | unknown ❌ | 31.07 |
|
| 172 |
+
| 152 | I've been prescribed metformin for my type 2 diabe... | patient | patient ✅ | treatment | unknown ❌ | 44.86 |
|
| 173 |
+
| 153 | I've been tracking my glucose levels for a week, a... | patient | patient ✅ | monitoring | unknown ❌ | 92.71 |
|
| 174 |
+
| 154 | Can you explain the difference between carbohydrat... | patient | dietary ❌ | general | unknown ❌ | 78.74 |
|
| 175 |
+
| 155 | I've been experiencing severe dehydration due to e... | patient | patient ✅ | general | unknown ❌ | 25.11 |
|
| 176 |
+
| 156 | I've been experiencing frequent urination and thir... | patient | patient ✅ | symptoms | unknown ❌ | 22.51 |
|
| 177 |
+
| 157 | What are the differences between metformin and pio... | clinician | clinician ✅ | treatment | treatment ✅ | 127.3 |
|
| 178 |
+
| 158 | I've noticed that my blood sugar levels are higher... | patient | dietary ❌ | general | unknown ❌ | 83.74 |
|
| 179 |
+
| 159 | What is the significance of HbA1c levels in monito... | researcher | clinician ❌ | monitoring | monitoring ✅ | 99.75 |
|
| 180 |
+
| 160 | I'm planning to start a low-carb diet. Can you pro... | dietitian | unknown ❌ | general | unknown ❌ | 6.32 |
|
| 181 |
+
| 161 | I've been experiencing recurring fatigue and blurr... | patient | patient ✅ | diagnosis | unknown ❌ | 43.38 |
|
| 182 |
+
| 162 | How often should I check my blood sugar levels, an... | patient | patient ✅ | monitoring | unknown ❌ | 34.76 |
|
| 183 |
+
| 163 | I've been prescribed metformin to help with my ins... | patient | patient ✅ | treatment | unknown ❌ | 44.99 |
|
| 184 |
+
| 164 | Can you recommend a healthy meal plan for someone ... | dietitian | dietary ❌ | general | unknown ❌ | 24.45 |
|
| 185 |
+
| 165 | What's the difference between HbA1c and glucose mo... | researcher | patient ❌ | diagnosis | unknown ❌ | 41.45 |
|
| 186 |
+
| 166 | I've been experiencing excessive thirst and urinat... | patient | patient ✅ | diagnosis | unknown ❌ | 47.29 |
|
| 187 |
+
| 167 | What is the optimal HbA1c target for someone with ... | clinician | clinician ✅ | treatment | treatment ✅ | 130.5 |
|
| 188 |
+
| 168 | I've been noticing numbness in my feet, which I su... | patient | patient ✅ | general | unknown ❌ | 56.12 |
|
| 189 |
+
| 169 | My doctor recently started me on metformin for my ... | pregnant patient | clinician ❌ | treatment | general ❌ | 91.36 |
|
| 190 |
+
| 170 | I've been tracking my glucose levels using a conti... | patient | patient ✅ | monitoring | unknown ❌ | 45.16 |
|
| 191 |
+
| 171 | I've been experiencing frequent urination and blur... | patient | patient ✅ | symptoms | unknown ❌ | 35.76 |
|
| 192 |
+
| 172 | What is the recommended HbA1c target range for a p... | clinician | clinician ✅ | diagnosis | treatment ❌ | 83.2 |
|
| 193 |
+
| 173 | I've been following a keto diet to manage my blood... | patient | dietary ❌ | dietary | unknown ❌ | 70.71 |
|
| 194 |
+
| 174 | I've been experiencing severe headaches and fatigu... | patient | patient ✅ | treatment | unknown ❌ | 52.9 |
|
| 195 |
+
| 175 | I've been reading about the potential benefits of ... | researcher | patient ❌ | monitoring | unknown ❌ | 65.99 |
|
| 196 |
+
| 176 | I keep experiencing sudden episodes of blurry visi... | patient | patient ✅ | diagnosis | unknown ❌ | 78.22 |
|
| 197 |
+
| 177 | What's the difference between basal and bolus insu... | patient | patient ✅ | treatment | unknown ❌ | 78.47 |
|
| 198 |
+
| 178 | I've been following a low-carb diet for the past w... | dietitian | unknown ❌ | general | unknown ❌ | 5.74 |
|
| 199 |
+
| 179 | My doctor recently told me I have high HbA1c level... | patient | patient ✅ | diagnosis | unknown ❌ | 41.84 |
|
| 200 |
+
| 180 | I've been researching different types of diabetes ... | researcher | researcher ✅ | general | unknown ❌ | 23.61 |
|
| 201 |
+
| 181 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 40.89 |
|
| 202 |
+
| 182 | I'm trying to lose weight and was wondering if it'... | patient | unknown ❌ | treatment | unknown ❌ | 7.35 |
|
| 203 |
+
| 183 | My HbA1c test result came back at 7.5%. Is that wi... | patient | patient ✅ | monitoring | unknown ❌ | 33.78 |
|
| 204 |
+
| 184 | I've been prescribed metformin for my type 2 diabe... | patient | clinician ❌ | treatment | treatment ✅ | 103.12 |
|
| 205 |
+
| 185 | I've noticed some numbness in my fingers and toes,... | patient | patient ✅ | diagnosis | unknown ❌ | 70.81 |
|
| 206 |
+
| 186 | I've been experiencing frequent urination and my h... | patient | patient ✅ | diagnosis | unknown ❌ | 80.43 |
|
| 207 |
+
| 187 | What are the recommended daily carb limits for a t... | researcher | unknown ❌ | treatment | unknown ❌ | 3.64 |
|
| 208 |
+
| 188 | I've been tracking my glucose levels and noticed t... | dietary | dietary ✅ | general | unknown ❌ | 133.59 |
|
| 209 |
+
| 189 | My doctor just diagnosed me with diabetic retinopa... | patient | patient ✅ | treatment | unknown ❌ | 108.03 |
|
| 210 |
+
| 190 | I've been taking metformin for my type 2 diabetes,... | patient | patient ✅ | treatment | unknown ❌ | 98.72 |
|
| 211 |
+
| 191 | I've been experiencing frequent urination and feel... | patient | patient ✅ | diagnosis | unknown ❌ | 71.7 |
|
| 212 |
+
| 192 | What is the difference between basal insulin and b... | clinician | patient ❌ | treatment | unknown ❌ | 62.17 |
|
| 213 |
+
| 193 | I've had high blood sugar levels for a while, but ... | patient | patient ✅ | monitoring | unknown ❌ | 78.8 |
|
| 214 |
+
| 194 | How does the glycemic index of different foods aff... | researcher | dietary ❌ | general | unknown ❌ | 325.47 |
|
| 215 |
+
| 195 | I've been experiencing numbness and tingling in my... | patient | patient ✅ | diagnosis | unknown ❌ | 44.42 |
|
| 216 |
+
| 196 | I've been experiencing frequent urination and blur... | patient | patient ✅ | diagnosis | unknown ❌ | 45.13 |
|
| 217 |
+
| 197 | How does metformin affect my blood sugar levels du... | patient | clinician ❌ | treatment | treatment ✅ | 176.6 |
|
| 218 |
+
| 198 | I've been tracking my glucose levels using a Conti... | patient | clinician ❌ | monitoring | monitoring ✅ | 137.94 |
|
| 219 |
+
| 199 | I've been advised to follow a low-carb diet to man... | dietary | unknown ❌ | treatment | unknown ❌ | 9.14 |
|
| 220 |
+
| 200 | What are the potential risks associated with takin... | patient | patient ✅ | diagnosis | unknown ❌ | 50.14 |
|
requirements.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
langchain
|
| 3 |
+
langchain_community
|
| 4 |
+
langchain_core
|
| 5 |
+
langgraph
|
| 6 |
+
langchain_ollama
|
| 7 |
+
pysqlite3
|
| 8 |
+
bs4
|
| 9 |
+
requests
|
| 10 |
+
pypdf
|
| 11 |
+
pymongo
|
| 12 |
+
langchain-mongodb
|
| 13 |
+
langchain-openai
|
| 14 |
+
pydantic
|
| 15 |
+
ddgs
|
| 16 |
+
chromadb
|
| 17 |
+
langchain-chroma
|
| 18 |
+
sentence-transformers
|
| 19 |
+
langchain-huggingface
|
| 20 |
+
fastapi
|
| 21 |
+
uvicorn
|
| 22 |
+
supabase
|
| 23 |
+
PyJWT
|
scripts/check_mongo.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pymongo import MongoClient
|
| 2 |
+
import os
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
|
| 5 |
+
load_dotenv()
|
| 6 |
+
mongo_uri = os.getenv("MONGO_URI", "mongodb://localhost:27017/")
|
| 7 |
+
client = MongoClient(mongo_uri)
|
| 8 |
+
|
| 9 |
+
print("Databases found:")
|
| 10 |
+
for db in client.list_database_names():
|
| 11 |
+
print(f"- {db}")
|
| 12 |
+
for coll in client[db].list_collection_names():
|
| 13 |
+
print(f" -- {coll} ({client[db][coll].count_documents({})} docs)")
|
scripts/csvToJson.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import json
|
| 3 |
+
from src.utils.logger import setup_logger
|
| 4 |
+
|
| 5 |
+
logger = setup_logger("CSVtoJSON")
|
| 6 |
+
|
| 7 |
+
logger.info("Starting conversion from EvalQuestions.csv to test_set.json")
|
| 8 |
+
|
| 9 |
+
df = pd.read_csv("data/csvFiles/small_test_set.csv")
|
| 10 |
+
|
| 11 |
+
df.drop(columns=["createdAt","updatedAt"],inplace=True, errors="ignore")
|
| 12 |
+
|
| 13 |
+
data = {"questions": df.to_dict(orient="records")}
|
| 14 |
+
|
| 15 |
+
with open("data/small_test_set.json", "w", encoding="utf-8") as f:
|
| 16 |
+
json.dump(data, f, indent=4)
|
scripts/migrate_db.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sqlite3
|
| 2 |
+
import os
|
| 3 |
+
from langchain_chroma import Chroma
|
| 4 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 5 |
+
from langchain_core.documents import Document
|
| 6 |
+
|
| 7 |
+
DB_PATH = "data/dietary_guidelines.db"
|
| 8 |
+
CHROMA_DIR = "data/chroma_db"
|
| 9 |
+
|
| 10 |
+
def migrate():
|
| 11 |
+
print("Connecting to sqlite DB...")
|
| 12 |
+
conn = sqlite3.connect(DB_PATH)
|
| 13 |
+
cursor = conn.cursor()
|
| 14 |
+
cursor.execute("SELECT id, source, page, content FROM guidelines")
|
| 15 |
+
rows = cursor.fetchall()
|
| 16 |
+
|
| 17 |
+
docs = []
|
| 18 |
+
for row in rows:
|
| 19 |
+
row_id, source, page, content = row
|
| 20 |
+
doc = Document(
|
| 21 |
+
page_content=content,
|
| 22 |
+
metadata={"source": source, "page": page, "id": row_id}
|
| 23 |
+
)
|
| 24 |
+
docs.append(doc)
|
| 25 |
+
|
| 26 |
+
print(f"Loaded {len(docs)} documents from SQLite. Creating embeddings...")
|
| 27 |
+
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
| 28 |
+
|
| 29 |
+
print("Inserting into Chroma DB...")
|
| 30 |
+
vectorstore = Chroma.from_documents(
|
| 31 |
+
documents=docs,
|
| 32 |
+
embedding=embeddings,
|
| 33 |
+
persist_directory=CHROMA_DIR,
|
| 34 |
+
collection_name="guidelines"
|
| 35 |
+
)
|
| 36 |
+
print("Migration complete!")
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
migrate()
|
scripts/migrate_kb_mongo_to_supabase.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import uuid
|
| 3 |
+
import datetime
|
| 4 |
+
from pymongo import MongoClient
|
| 5 |
+
from supabase import create_client, Client
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
from sentence_transformers import SentenceTransformer
|
| 8 |
+
|
| 9 |
+
load_dotenv()
|
| 10 |
+
|
| 11 |
+
# MongoDB Configuration
|
| 12 |
+
MONGO_URI = os.getenv("MONGO_URI", "mongodb://localhost:27017/")
|
| 13 |
+
MONGO_DB = "diet_db"
|
| 14 |
+
|
| 15 |
+
# Supabase Configuration
|
| 16 |
+
SUPABASE_URL = os.getenv("SUPABASE_URL")
|
| 17 |
+
SUPABASE_SERVICE_ROLE_KEY = os.getenv("SUPABASE_SERVICE_ROLE_KEY") or os.getenv("SUPABASE_KEY")
|
| 18 |
+
|
| 19 |
+
def migrate_kb():
|
| 20 |
+
print("Starting Knowledge Base migration from MongoDB to Supabase...")
|
| 21 |
+
|
| 22 |
+
if not SUPABASE_URL or not SUPABASE_SERVICE_ROLE_KEY:
|
| 23 |
+
print("Error: Supabase configuration missing.")
|
| 24 |
+
return
|
| 25 |
+
|
| 26 |
+
mongo_client = MongoClient(MONGO_URI)
|
| 27 |
+
supabase: Client = create_client(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY)
|
| 28 |
+
|
| 29 |
+
# Load embedding model
|
| 30 |
+
print("Loading embedding model (all-MiniLM-L6-v2)...")
|
| 31 |
+
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 32 |
+
|
| 33 |
+
# We need to migrate multiple collections possibly
|
| 34 |
+
# In kb_manager.py, default was 'documents' in 'medical_kb'
|
| 35 |
+
# In dietary_tools.py, it was 'diabetes' in 'test_index'
|
| 36 |
+
collections_to_migrate = [
|
| 37 |
+
{"db": "medical_kb", "coll": "documents"},
|
| 38 |
+
{"db": "test_index", "coll": "diabetes"},
|
| 39 |
+
{"db": "diet_db", "coll": "diabetes"}
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
for item in collections_to_migrate:
|
| 43 |
+
db_name = item["db"]
|
| 44 |
+
coll_name = item["coll"]
|
| 45 |
+
|
| 46 |
+
print(f"Migrating {db_name}.{coll_name}...")
|
| 47 |
+
try:
|
| 48 |
+
mongo_docs = list(mongo_client[db_name][coll_name].find())
|
| 49 |
+
if not mongo_docs:
|
| 50 |
+
print(f"No documents found in {db_name}.{coll_name}. Skipping.")
|
| 51 |
+
continue
|
| 52 |
+
|
| 53 |
+
# Batch processing for efficiency
|
| 54 |
+
batch_size = 50
|
| 55 |
+
for i in range(0, len(mongo_docs), batch_size):
|
| 56 |
+
batch = mongo_docs[i:i+batch_size]
|
| 57 |
+
texts = [doc.get("text", "") for doc in batch]
|
| 58 |
+
|
| 59 |
+
# Generate embeddings
|
| 60 |
+
embeddings = model.encode(texts).tolist()
|
| 61 |
+
|
| 62 |
+
supabase_data = []
|
| 63 |
+
for doc, emb in zip(batch, embeddings):
|
| 64 |
+
supabase_data.append({
|
| 65 |
+
"id": str(uuid.uuid4()),
|
| 66 |
+
"content": doc.get("text", ""),
|
| 67 |
+
"metadata": doc.get("metadata", {}),
|
| 68 |
+
"embedding": emb,
|
| 69 |
+
"collection_name": f"{db_name}_{coll_name}"
|
| 70 |
+
})
|
| 71 |
+
|
| 72 |
+
supabase.table("knowledge_base").insert(supabase_data).execute()
|
| 73 |
+
print(f"Uploaded {len(supabase_data)} documents...")
|
| 74 |
+
|
| 75 |
+
print(f"Successfully migrated {len(mongo_docs)} documents from {db_name}.{coll_name}.")
|
| 76 |
+
except Exception as e:
|
| 77 |
+
print(f"Error migrating {db_name}.{coll_name}: {e}")
|
| 78 |
+
|
| 79 |
+
print("Knowledge Base migration complete!")
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__":
|
| 82 |
+
migrate_kb()
|
scripts/migrate_mongo_to_supabase.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import uuid
|
| 3 |
+
import datetime
|
| 4 |
+
from pymongo import MongoClient
|
| 5 |
+
from supabase import create_client, Client
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
# MongoDB Configuration
|
| 11 |
+
MONGO_URI = os.getenv("MONGO_URI", "mongodb://localhost:27017/")
|
| 12 |
+
MONGO_DB = "medical_kb"
|
| 13 |
+
|
| 14 |
+
# Supabase Configuration
|
| 15 |
+
SUPABASE_URL = os.getenv("SUPABASE_URL")
|
| 16 |
+
# Use Service Role Key for migration to bypass RLS
|
| 17 |
+
SUPABASE_KEY = os.getenv("SUPABASE_SERVICE_ROLE_KEY") or os.getenv("SUPABASE_KEY")
|
| 18 |
+
|
| 19 |
+
DEFAULT_PATIENT_ID = os.getenv("DEFAULT_PATIENT_UUID")
|
| 20 |
+
|
| 21 |
+
def migrate():
|
| 22 |
+
print("Starting migration from MongoDB to Supabase...")
|
| 23 |
+
|
| 24 |
+
if not SUPABASE_URL or not SUPABASE_KEY:
|
| 25 |
+
print("Error: Supabase configuration missing.")
|
| 26 |
+
return
|
| 27 |
+
|
| 28 |
+
mongo_client = MongoClient(MONGO_URI)
|
| 29 |
+
mongo_db = mongo_client[MONGO_DB]
|
| 30 |
+
supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
|
| 31 |
+
|
| 32 |
+
# 1. Migrate Patients
|
| 33 |
+
print("Migrating Patients...")
|
| 34 |
+
patients = list(mongo_db["patient"].find())
|
| 35 |
+
for p in patients:
|
| 36 |
+
p_id = p.get("id") or str(p.get("_id"))
|
| 37 |
+
if p_id == "anonymous":
|
| 38 |
+
p_id = DEFAULT_PATIENT_ID
|
| 39 |
+
|
| 40 |
+
resource = {
|
| 41 |
+
"resourceType": "Patient",
|
| 42 |
+
"id": p_id,
|
| 43 |
+
"name": p.get("name", [{"text": "Unknown"}]),
|
| 44 |
+
"active": p.get("active", True)
|
| 45 |
+
}
|
| 46 |
+
data = {
|
| 47 |
+
"id": p_id,
|
| 48 |
+
"resource": resource,
|
| 49 |
+
"last_updated": datetime.datetime.now(datetime.timezone.utc).isoformat()
|
| 50 |
+
}
|
| 51 |
+
supabase.table("patients").upsert(data).execute()
|
| 52 |
+
print(f"Migrated {len(patients)} patients.")
|
| 53 |
+
|
| 54 |
+
# 2. Migrate Observations
|
| 55 |
+
print("Migrating Observations...")
|
| 56 |
+
observations = list(mongo_db["observation"].find())
|
| 57 |
+
for o in observations:
|
| 58 |
+
obs_id = o.get("id") or str(o.get("_id"))
|
| 59 |
+
# Map patient reference
|
| 60 |
+
ref = o.get("subject", {}).get("reference", "")
|
| 61 |
+
patient_id = None
|
| 62 |
+
if "Patient/" in ref:
|
| 63 |
+
patient_id = ref.split("/")[-1]
|
| 64 |
+
|
| 65 |
+
if not patient_id or patient_id == "anonymous":
|
| 66 |
+
patient_id = DEFAULT_PATIENT_ID
|
| 67 |
+
|
| 68 |
+
o.pop("_id", None)
|
| 69 |
+
data = {
|
| 70 |
+
"id": obs_id,
|
| 71 |
+
"patient_id": patient_id,
|
| 72 |
+
"resource": o,
|
| 73 |
+
"last_updated": datetime.datetime.now(datetime.timezone.utc).isoformat()
|
| 74 |
+
}
|
| 75 |
+
supabase.table("observations").upsert(data).execute()
|
| 76 |
+
print(f"Migrated {len(observations)} observations.")
|
| 77 |
+
|
| 78 |
+
# 3. Migrate Communications (Chat History)
|
| 79 |
+
print("Migrating Communications...")
|
| 80 |
+
comms = list(mongo_db["patient_data"].find())
|
| 81 |
+
for c in comms:
|
| 82 |
+
c_id = c.get("id") or str(c.get("_id"))
|
| 83 |
+
ref = c.get("subject", {}).get("reference", "")
|
| 84 |
+
patient_id = None
|
| 85 |
+
if "Patient/" in ref:
|
| 86 |
+
patient_id = ref.split("/")[-1]
|
| 87 |
+
|
| 88 |
+
if not patient_id or patient_id == "anonymous":
|
| 89 |
+
patient_id = DEFAULT_PATIENT_ID
|
| 90 |
+
|
| 91 |
+
c.pop("_id", None)
|
| 92 |
+
data = {
|
| 93 |
+
"id": c_id,
|
| 94 |
+
"patient_id": patient_id,
|
| 95 |
+
"resource": c,
|
| 96 |
+
"last_updated": datetime.datetime.now(datetime.timezone.utc).isoformat()
|
| 97 |
+
}
|
| 98 |
+
supabase.table("communications").upsert(data).execute()
|
| 99 |
+
print(f"Migrated {len(comms)} communications.")
|
| 100 |
+
|
| 101 |
+
print("Migration complete!")
|
| 102 |
+
|
| 103 |
+
if __name__ == "__main__":
|
| 104 |
+
migrate()
|
src/agents/agent_instances.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from src.agents.agents import (
|
| 2 |
+
RoleClassifier, PatientLLM, ResponseValidator, SafetyCheck,
|
| 3 |
+
IntentClassifier, ClinicalSpecialist, OutputMerger, ResearchAgent,
|
| 4 |
+
DietarySpecialist
|
| 5 |
+
)
|
| 6 |
+
from src.agents.cdm_agents import HealthCoach, TrendAnalyzer
|
| 7 |
+
from src.utils.logger import setup_logger
|
| 8 |
+
|
| 9 |
+
logger = setup_logger("AgentInstances")
|
| 10 |
+
|
| 11 |
+
# Instantiate all agents
|
| 12 |
+
role_classifier = RoleClassifier()
|
| 13 |
+
patient_llm = PatientLLM()
|
| 14 |
+
validator = ResponseValidator()
|
| 15 |
+
safety_check = SafetyCheck()
|
| 16 |
+
intent_classifier = IntentClassifier()
|
| 17 |
+
|
| 18 |
+
# Clinical specialists
|
| 19 |
+
diagnosis_assist = ClinicalSpecialist("Diagnosis")
|
| 20 |
+
treatment_assist = ClinicalSpecialist("Treatment")
|
| 21 |
+
monitoring_assist = ClinicalSpecialist("Monitoring")
|
| 22 |
+
general_assist = ClinicalSpecialist("General Clinical Support")
|
| 23 |
+
|
| 24 |
+
output_merger = OutputMerger()
|
| 25 |
+
research_agent = ResearchAgent()
|
| 26 |
+
dietary_assist = DietarySpecialist()
|
| 27 |
+
|
| 28 |
+
# CDM Agents
|
| 29 |
+
health_coach = HealthCoach()
|
| 30 |
+
trend_analyzer = TrendAnalyzer()
|
| 31 |
+
|
| 32 |
+
def update_all_agents_llm(provider_name: str):
|
| 33 |
+
from src.core.model_manager import model_manager
|
| 34 |
+
|
| 35 |
+
if model_manager.provider == provider_name.lower():
|
| 36 |
+
return
|
| 37 |
+
|
| 38 |
+
model_manager.provider = provider_name.lower()
|
| 39 |
+
logger.info(f"Switching LLM provider to: {provider_name}")
|
| 40 |
+
|
| 41 |
+
all_agents = [
|
| 42 |
+
role_classifier, patient_llm, validator, safety_check,
|
| 43 |
+
intent_classifier, diagnosis_assist, treatment_assist,
|
| 44 |
+
monitoring_assist, general_assist, output_merger,
|
| 45 |
+
research_agent, dietary_assist, health_coach, trend_analyzer
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
for agent in all_agents:
|
| 49 |
+
agent.llm = model_manager.get_llm()
|
| 50 |
+
if hasattr(agent, 'tools') and agent.tools:
|
| 51 |
+
agent.llm = agent.llm.bind_tools(agent.tools)
|
src/agents/agents.py
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
from langchain_core.messages import SystemMessage, HumanMessage, AIMessage
|
| 4 |
+
from langchain_core.prompts import ChatPromptTemplate
|
| 5 |
+
import json
|
| 6 |
+
import time
|
| 7 |
+
from src.utils.logger import setup_logger
|
| 8 |
+
|
| 9 |
+
logger = setup_logger("Agents")
|
| 10 |
+
|
| 11 |
+
# Absolute import management for the new structure - removed as it's redundant and can cause issues
|
| 12 |
+
|
| 13 |
+
from src.core.model_manager import model_manager
|
| 14 |
+
from src.core.state import AgentState
|
| 15 |
+
from src.tools.web_tools import web_search_tool
|
| 16 |
+
from src.tools.dietary_tools import search_guidelines, get_nutritional_data, page_indexed_retrieval
|
| 17 |
+
from src.tools.patient_memory import save_patient_memory, get_patient_memory
|
| 18 |
+
|
| 19 |
+
class BaseAgent:
|
| 20 |
+
def __init__(self, fallback_prompt: str, prompt_file: str = None, tools: list = None):
|
| 21 |
+
self.llm = model_manager.get_llm()
|
| 22 |
+
self.tools = tools
|
| 23 |
+
if tools:
|
| 24 |
+
# We use bind_tools for LLMs that support it
|
| 25 |
+
self.llm = self.llm.bind_tools(tools)
|
| 26 |
+
self.fallback_prompt = fallback_prompt
|
| 27 |
+
self.prompt_file = prompt_file
|
| 28 |
+
|
| 29 |
+
@property
|
| 30 |
+
def system_prompt(self) -> str:
|
| 31 |
+
"""Dynamically load prompt from file if available, otherwise use fallback."""
|
| 32 |
+
if self.prompt_file:
|
| 33 |
+
# Get the path relative to this file's location
|
| 34 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 35 |
+
prompt_path = os.path.abspath(os.path.join(current_dir, "..", "prompts", self.prompt_file))
|
| 36 |
+
try:
|
| 37 |
+
if os.path.exists(prompt_path):
|
| 38 |
+
with open(prompt_path, "r", encoding="utf-8") as f:
|
| 39 |
+
return f.read().strip()
|
| 40 |
+
except Exception as e:
|
| 41 |
+
# Log locally or via print, then fall back
|
| 42 |
+
pass
|
| 43 |
+
return self.fallback_prompt
|
| 44 |
+
|
| 45 |
+
async def run(self, state: AgentState):
|
| 46 |
+
"""Standard run method for graph nodes."""
|
| 47 |
+
messages = [SystemMessage(content=self.system_prompt)] + state["messages"]
|
| 48 |
+
logger.info(f"--- Sending {len(messages)} messages to LLM ({self.__class__.__name__}) ---")
|
| 49 |
+
|
| 50 |
+
start_time = time.time()
|
| 51 |
+
try:
|
| 52 |
+
response = await self.llm.ainvoke(messages)
|
| 53 |
+
end_time = time.time()
|
| 54 |
+
|
| 55 |
+
# Extract tokens
|
| 56 |
+
tokens = 0
|
| 57 |
+
if hasattr(response, "usage_metadata") and response.usage_metadata:
|
| 58 |
+
tokens = response.usage_metadata.get("total_tokens", 0)
|
| 59 |
+
elif "token_usage" in response.response_metadata:
|
| 60 |
+
tokens = response.response_metadata["token_usage"].get("total_tokens", 0)
|
| 61 |
+
|
| 62 |
+
metrics = {
|
| 63 |
+
"agent": self.__class__.__name__,
|
| 64 |
+
"tokens": tokens,
|
| 65 |
+
"time": round(end_time - start_time, 3)
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
return {"messages": [response], "metrics": [metrics]}
|
| 69 |
+
except Exception as e:
|
| 70 |
+
logger.error(f"Error in {self.__class__.__name__}.run: {e}")
|
| 71 |
+
raise
|
| 72 |
+
|
| 73 |
+
class RoleClassifier(BaseAgent):
|
| 74 |
+
def __init__(self):
|
| 75 |
+
fallback_prompt = """You are a medical triage assistant.
|
| 76 |
+
Classify the user input into one of four roles: 'patient', 'clinician', 'researcher', or 'dietary'. Return only the name."""
|
| 77 |
+
super().__init__(fallback_prompt, "RoleClassifier.txt")
|
| 78 |
+
|
| 79 |
+
async def run(self, state: AgentState):
|
| 80 |
+
messages = [SystemMessage(content=self.system_prompt)] + state["messages"]
|
| 81 |
+
logger.info(f"--- RoleClassifier: Sending {len(messages)} messages to LLM ---")
|
| 82 |
+
|
| 83 |
+
start_time = time.time()
|
| 84 |
+
try:
|
| 85 |
+
response = await self.llm.ainvoke(messages)
|
| 86 |
+
end_time = time.time()
|
| 87 |
+
|
| 88 |
+
role = response.content.lower().strip()
|
| 89 |
+
if not role:
|
| 90 |
+
role = "patient"
|
| 91 |
+
roles = ["patient", "clinician", "researcher", "dietary"]
|
| 92 |
+
for r in roles:
|
| 93 |
+
if r in role:
|
| 94 |
+
role = r
|
| 95 |
+
break
|
| 96 |
+
if role not in roles:
|
| 97 |
+
role = "patient"
|
| 98 |
+
|
| 99 |
+
tokens = 0
|
| 100 |
+
if hasattr(response, "usage_metadata") and response.usage_metadata:
|
| 101 |
+
tokens = response.usage_metadata.get("total_tokens", 0)
|
| 102 |
+
elif "token_usage" in response.response_metadata:
|
| 103 |
+
tokens = response.response_metadata["token_usage"].get("total_tokens", 0)
|
| 104 |
+
|
| 105 |
+
metrics = {
|
| 106 |
+
"agent": "RoleClassifier",
|
| 107 |
+
"tokens": tokens,
|
| 108 |
+
"time": round(end_time - start_time, 3)
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
return {"user_role": role, "metrics": [metrics]}
|
| 112 |
+
except Exception as e:
|
| 113 |
+
logger.error(f"Error in RoleClassifier.run: {e}")
|
| 114 |
+
raise
|
| 115 |
+
|
| 116 |
+
class PatientLLM(BaseAgent):
|
| 117 |
+
def __init__(self):
|
| 118 |
+
fallback_prompt = """You are a compassionate medical assistant for patients.
|
| 119 |
+
Provide helpful, empathetic, and medically sound advice."""
|
| 120 |
+
super().__init__(fallback_prompt, "PatientLLM.txt", tools=[web_search_tool, save_patient_memory, get_patient_memory])
|
| 121 |
+
|
| 122 |
+
class ResponseValidator(BaseAgent):
|
| 123 |
+
def __init__(self):
|
| 124 |
+
fallback_prompt = """You are a medical response validator.
|
| 125 |
+
Check if the last response is medically accurate and follows guidelines. Return 'valid' or 'invalid'."""
|
| 126 |
+
super().__init__(fallback_prompt, "ResponseValidator.txt")
|
| 127 |
+
|
| 128 |
+
async def run(self, state: AgentState):
|
| 129 |
+
# We check the last AI message in the state
|
| 130 |
+
last_message = state["messages"][-1].content
|
| 131 |
+
|
| 132 |
+
start_time = time.time()
|
| 133 |
+
response = await self.llm.ainvoke([
|
| 134 |
+
SystemMessage(content=self.system_prompt),
|
| 135 |
+
HumanMessage(content=f"Verify this response: {last_message}")
|
| 136 |
+
])
|
| 137 |
+
end_time = time.time()
|
| 138 |
+
|
| 139 |
+
is_valid = "valid" in response.content.lower()
|
| 140 |
+
|
| 141 |
+
tokens = 0
|
| 142 |
+
if hasattr(response, "usage_metadata") and response.usage_metadata:
|
| 143 |
+
tokens = response.usage_metadata.get("total_tokens", 0)
|
| 144 |
+
elif "token_usage" in response.response_metadata:
|
| 145 |
+
tokens = response.response_metadata["token_usage"].get("total_tokens", 0)
|
| 146 |
+
|
| 147 |
+
metrics = {
|
| 148 |
+
"agent": "ResponseValidator",
|
| 149 |
+
"tokens": tokens,
|
| 150 |
+
"time": round(end_time - start_time, 3)
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
return {"is_valid": is_valid, "metrics": [metrics]}
|
| 154 |
+
|
| 155 |
+
class SafetyCheck(BaseAgent):
|
| 156 |
+
def __init__(self):
|
| 157 |
+
fallback_prompt = """You are a medical safety officer.
|
| 158 |
+
Check if the response contains any dangerous advice or misinformation. Return 'safe' or 'unsafe'."""
|
| 159 |
+
super().__init__(fallback_prompt, "SafetyCheck.txt")
|
| 160 |
+
|
| 161 |
+
async def run(self, state: AgentState):
|
| 162 |
+
last_message = state["messages"][-1].content
|
| 163 |
+
|
| 164 |
+
start_time = time.time()
|
| 165 |
+
response = await self.llm.ainvoke([
|
| 166 |
+
SystemMessage(content=self.system_prompt),
|
| 167 |
+
HumanMessage(content=f"Safety check on this: {last_message}")
|
| 168 |
+
])
|
| 169 |
+
end_time = time.time()
|
| 170 |
+
|
| 171 |
+
is_safe = "safe" in response.content.lower()
|
| 172 |
+
|
| 173 |
+
tokens = 0
|
| 174 |
+
if hasattr(response, "usage_metadata") and response.usage_metadata:
|
| 175 |
+
tokens = response.usage_metadata.get("total_tokens", 0)
|
| 176 |
+
elif "token_usage" in response.response_metadata:
|
| 177 |
+
tokens = response.response_metadata["token_usage"].get("total_tokens", 0)
|
| 178 |
+
|
| 179 |
+
metrics = {
|
| 180 |
+
"agent": "SafetyCheck",
|
| 181 |
+
"tokens": tokens,
|
| 182 |
+
"time": round(end_time - start_time, 3)
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
return {"is_safe": is_safe, "metrics": [metrics]}
|
| 186 |
+
|
| 187 |
+
class IntentClassifier(BaseAgent):
|
| 188 |
+
def __init__(self):
|
| 189 |
+
fallback_prompt = """You are a clinical intent classifier.
|
| 190 |
+
Classify into: 'diagnosis', 'treatment', 'monitoring', or 'general'."""
|
| 191 |
+
super().__init__(fallback_prompt, "IntentClassifier.txt")
|
| 192 |
+
|
| 193 |
+
async def run(self, state: AgentState):
|
| 194 |
+
start_time = time.time()
|
| 195 |
+
response = await self.llm.ainvoke([SystemMessage(content=self.system_prompt)] + state["messages"])
|
| 196 |
+
end_time = time.time()
|
| 197 |
+
|
| 198 |
+
intent = response.content.lower().strip()
|
| 199 |
+
|
| 200 |
+
tokens = 0
|
| 201 |
+
if hasattr(response, "usage_metadata") and response.usage_metadata:
|
| 202 |
+
tokens = response.usage_metadata.get("total_tokens", 0)
|
| 203 |
+
elif "token_usage" in response.response_metadata:
|
| 204 |
+
tokens = response.response_metadata["token_usage"].get("total_tokens", 0)
|
| 205 |
+
|
| 206 |
+
metrics = {
|
| 207 |
+
"agent": "IntentClassifier",
|
| 208 |
+
"tokens": tokens,
|
| 209 |
+
"time": round(end_time - start_time, 3)
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
return {"intent_type": intent, "metrics": [metrics]}
|
| 213 |
+
|
| 214 |
+
class ClinicalSpecialist(BaseAgent):
|
| 215 |
+
def __init__(self, specialty: str):
|
| 216 |
+
fallback_prompt = f"You are a clinical specialist in {specialty}. Provide expert medical support."
|
| 217 |
+
super().__init__(fallback_prompt, f"ClinicalSpecialist_{specialty}.txt")
|
| 218 |
+
|
| 219 |
+
class OutputMerger(BaseAgent):
|
| 220 |
+
def __init__(self):
|
| 221 |
+
fallback_prompt = "You are a clinical coordinator. Merge outputs into a single cohesive report."
|
| 222 |
+
super().__init__(fallback_prompt, "OutputMerger.txt")
|
| 223 |
+
|
| 224 |
+
class ResearchAgent(BaseAgent):
|
| 225 |
+
def __init__(self):
|
| 226 |
+
fallback_prompt = """You are a medical research assistant. Provide detailed information for researchers."""
|
| 227 |
+
super().__init__(fallback_prompt, "ResearchAgent.txt", tools=[web_search_tool, page_indexed_retrieval])
|
| 228 |
+
|
| 229 |
+
class DietarySpecialist(BaseAgent):
|
| 230 |
+
def __init__(self):
|
| 231 |
+
fallback_prompt = """You are a certified dietary specialist. Provide advice based on guidelines."""
|
| 232 |
+
super().__init__(fallback_prompt, "DietarySpecialist.txt", tools=[search_guidelines, get_nutritional_data, page_indexed_retrieval, save_patient_memory, get_patient_memory])
|
| 233 |
+
|
| 234 |
+
async def run(self, state: AgentState):
|
| 235 |
+
messages = [SystemMessage(content=self.system_prompt)] + state["messages"]
|
| 236 |
+
response = await self.llm.ainvoke(messages)
|
| 237 |
+
return {"messages": [response]}
|
src/agents/cdm_agents.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import time
|
| 3 |
+
from src.agents.agents import BaseAgent
|
| 4 |
+
from src.core.state import AgentState
|
| 5 |
+
from src.tools.fhir_memory import get_observations_by_patient
|
| 6 |
+
from langchain_core.messages import SystemMessage, HumanMessage
|
| 7 |
+
from src.utils.logger import setup_logger
|
| 8 |
+
|
| 9 |
+
logger = setup_logger("CDMAgents")
|
| 10 |
+
|
| 11 |
+
class HealthCoach(BaseAgent):
|
| 12 |
+
def __init__(self):
|
| 13 |
+
fallback_prompt = """You are a proactive Chronic Disease Management (CDM) Health Coach.
|
| 14 |
+
Your goal is to help patients manage their conditions (like Diabetes or Hypertension) through motivation, education, and lifestyle tracking.
|
| 15 |
+
Always review their recent FHIR observations and provide trend-aware advice.
|
| 16 |
+
Be encouraging but firm about safety guidelines."""
|
| 17 |
+
super().__init__(fallback_prompt, "HealthCoach.txt")
|
| 18 |
+
|
| 19 |
+
class TrendAnalyzer(BaseAgent):
|
| 20 |
+
def __init__(self):
|
| 21 |
+
fallback_prompt = """You are a medical data trend analyzer.
|
| 22 |
+
You analyze FHIR observations and identify clinically significant trends.
|
| 23 |
+
If you see rising glucose levels or blood pressure, flag them immediately.
|
| 24 |
+
Provide a concise summary of the last 7 days of data."""
|
| 25 |
+
super().__init__(fallback_prompt, "TrendAnalyzer.txt")
|
| 26 |
+
|
| 27 |
+
async def analyze_trends(self, patient_id: str):
|
| 28 |
+
"""
|
| 29 |
+
Logic to analyze trends for a specific patient.
|
| 30 |
+
This can be called as a tool or as an agent step.
|
| 31 |
+
"""
|
| 32 |
+
logger.info(f"Analyzing health trends for patient: {patient_id}")
|
| 33 |
+
observations = get_observations_by_patient.invoke({"patient_id": patient_id})
|
| 34 |
+
if isinstance(observations, str):
|
| 35 |
+
return observations
|
| 36 |
+
|
| 37 |
+
# Group by LOINC code
|
| 38 |
+
data_points = {}
|
| 39 |
+
for obs in observations:
|
| 40 |
+
code = obs["code"]["coding"][0]["display"]
|
| 41 |
+
val = obs["valueQuantity"]["value"]
|
| 42 |
+
date = obs["effectiveDateTime"]
|
| 43 |
+
if code not in data_points:
|
| 44 |
+
data_points[code] = []
|
| 45 |
+
data_points[code].append({"value": val, "date": date})
|
| 46 |
+
|
| 47 |
+
# Basic trend analysis logic
|
| 48 |
+
analysis = "Trend Analysis Summary:\n"
|
| 49 |
+
for code, points in data_points.items():
|
| 50 |
+
if len(points) >= 2:
|
| 51 |
+
latest = points[0]["value"]
|
| 52 |
+
previous = points[1]["value"]
|
| 53 |
+
diff = latest - previous
|
| 54 |
+
trend = "increasing" if diff > 0 else "decreasing" if diff < 0 else "stable"
|
| 55 |
+
analysis += f"- {code}: {trend} (latest: {latest}, change: {diff:+.1f})\n"
|
| 56 |
+
else:
|
| 57 |
+
analysis += f"- {code}: Insufficient data for trend (latest: {points[0]['value']})\n"
|
| 58 |
+
|
| 59 |
+
return analysis
|
| 60 |
+
|
| 61 |
+
async def run(self, state: AgentState):
|
| 62 |
+
# Extract patient ID from messages or state
|
| 63 |
+
# For simplicity, we assume it's in the state or can be derived
|
| 64 |
+
# In a real scenario, we'd have a 'patient_id' in AgentState
|
| 65 |
+
patient_id = state.get("patient_id", "unknown")
|
| 66 |
+
if patient_id == "unknown":
|
| 67 |
+
logger.warning("TrendAnalyzer: No patient ID found in state.")
|
| 68 |
+
return {"logs": ["TrendAnalyzer: No patient ID found in state."]}
|
| 69 |
+
|
| 70 |
+
start_time = time.time()
|
| 71 |
+
analysis = await self.analyze_trends(patient_id)
|
| 72 |
+
end_time = time.time()
|
| 73 |
+
|
| 74 |
+
metrics = {
|
| 75 |
+
"agent": "TrendAnalyzer",
|
| 76 |
+
"tokens": 0, # Logic based, no LLM call here
|
| 77 |
+
"time": round(end_time - start_time, 3)
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
return {
|
| 81 |
+
"trend_analysis": analysis,
|
| 82 |
+
"logs": [f"TrendAnalyzer: Completed analysis for {patient_id}"],
|
| 83 |
+
"metrics": [metrics]
|
| 84 |
+
}
|
src/core/graph.py
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langgraph.graph import StateGraph, END
|
| 2 |
+
from src.core.state import AgentState
|
| 3 |
+
from src.agents.agent_instances import (
|
| 4 |
+
role_classifier, patient_llm, validator, safety_check,
|
| 5 |
+
intent_classifier, diagnosis_assist, treatment_assist,
|
| 6 |
+
monitoring_assist, general_assist, output_merger, research_agent,
|
| 7 |
+
dietary_assist
|
| 8 |
+
)
|
| 9 |
+
from langchain_core.messages import AIMessage, ToolMessage
|
| 10 |
+
from langgraph.prebuilt import ToolNode
|
| 11 |
+
from src.tools.web_tools import web_search_tool
|
| 12 |
+
from src.utils.logger import setup_logger
|
| 13 |
+
from src.tools.fhir_memory import save_chat_as_fhir
|
| 14 |
+
import time
|
| 15 |
+
|
| 16 |
+
logger = setup_logger("MedicalPipeline")
|
| 17 |
+
|
| 18 |
+
def log_step(name: str, output: str = None):
|
| 19 |
+
"""Utility to log both to terminal and return a state update for the logs list."""
|
| 20 |
+
logger.info(f"Executing: {name}")
|
| 21 |
+
log_msg = f"➔ Executing Node: {name}"
|
| 22 |
+
if output:
|
| 23 |
+
log_msg += f"\nOutput: {output}"
|
| 24 |
+
return {"logs": [log_msg]}
|
| 25 |
+
|
| 26 |
+
async def role_classifier_node(state: AgentState):
|
| 27 |
+
res = await role_classifier.run(state)
|
| 28 |
+
log = log_step("Role Classifier", f"Detected Role: {res.get('user_role')}")
|
| 29 |
+
res.update(log)
|
| 30 |
+
|
| 31 |
+
if res.get('user_role') != "clinician":
|
| 32 |
+
res['intent_type'] = "general"
|
| 33 |
+
|
| 34 |
+
return res
|
| 35 |
+
|
| 36 |
+
async def patient_llm_node(state: AgentState):
|
| 37 |
+
res = await patient_llm.run(state)
|
| 38 |
+
last_msg = res["messages"][-1]
|
| 39 |
+
content = last_msg.content if getattr(last_msg, "content", "") else str(getattr(last_msg, "tool_calls", ""))
|
| 40 |
+
log = log_step("Patient LLM", content)
|
| 41 |
+
return {"messages": res["messages"], "logs": log["logs"]}
|
| 42 |
+
|
| 43 |
+
async def validator_node(state: AgentState):
|
| 44 |
+
res = await validator.run(state)
|
| 45 |
+
log = log_step("Response Validator", f"Valid: {res.get('is_valid')}")
|
| 46 |
+
res.update(log)
|
| 47 |
+
return res
|
| 48 |
+
|
| 49 |
+
async def safety_check_node(state: AgentState):
|
| 50 |
+
res = await safety_check.run(state)
|
| 51 |
+
log = log_step("Safety Check", f"Safe: {res.get('is_safe')}")
|
| 52 |
+
res.update(log)
|
| 53 |
+
return res
|
| 54 |
+
|
| 55 |
+
async def recovery_loop_node(state: AgentState):
|
| 56 |
+
attempts = state.get("attempts", 0) + 1
|
| 57 |
+
log = log_step("Recovery Loop", f"Attempt {attempts}")
|
| 58 |
+
return {
|
| 59 |
+
"attempts": attempts,
|
| 60 |
+
"messages": [AIMessage(content="[RECOVERY] Let me try rephrasing or improving my previous response.")],
|
| 61 |
+
"logs": log["logs"]
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
async def intent_classifier_node(state: AgentState):
|
| 65 |
+
res = await intent_classifier.run(state)
|
| 66 |
+
log = log_step("Intent Classifier", f"Intent: {res.get('intent_type')}")
|
| 67 |
+
res.update(log)
|
| 68 |
+
return res
|
| 69 |
+
|
| 70 |
+
async def diagnosis_assist_node(state: AgentState):
|
| 71 |
+
res = await diagnosis_assist.run(state)
|
| 72 |
+
log = log_step("Diagnosis Assistant", res.get('clinician_outputs', [""])[-1] if res.get('clinician_outputs') else "")
|
| 73 |
+
res.update(log)
|
| 74 |
+
return res
|
| 75 |
+
|
| 76 |
+
async def treatment_assist_node(state: AgentState):
|
| 77 |
+
res = await treatment_assist.run(state)
|
| 78 |
+
log = log_step("Treatment Assistant", res.get('clinician_outputs', [""])[-1] if res.get('clinician_outputs') else "")
|
| 79 |
+
res.update(log)
|
| 80 |
+
return res
|
| 81 |
+
|
| 82 |
+
async def monitoring_assist_node(state: AgentState):
|
| 83 |
+
res = await monitoring_assist.run(state)
|
| 84 |
+
log = log_step("Monitoring Assistant", res.get('clinician_outputs', [""])[-1] if res.get('clinician_outputs') else "")
|
| 85 |
+
res.update(log)
|
| 86 |
+
return res
|
| 87 |
+
|
| 88 |
+
async def general_assist_node(state: AgentState):
|
| 89 |
+
res = await general_assist.run(state)
|
| 90 |
+
log = log_step("General Clinical Assistant", res.get('clinician_outputs', [""])[-1] if res.get('clinician_outputs') else "")
|
| 91 |
+
res.update(log)
|
| 92 |
+
return res
|
| 93 |
+
|
| 94 |
+
async def merge_outputs_node(state: AgentState):
|
| 95 |
+
res = await output_merger.run(state)
|
| 96 |
+
log = log_step("Output Merger", "Merged outputs successfully.")
|
| 97 |
+
res.update(log)
|
| 98 |
+
return res
|
| 99 |
+
|
| 100 |
+
async def research_agent_node(state: AgentState):
|
| 101 |
+
res = await research_agent.run(state)
|
| 102 |
+
log = log_step("Research Assistant", res.get('research_output', ''))
|
| 103 |
+
res.update(log)
|
| 104 |
+
return res
|
| 105 |
+
|
| 106 |
+
async def dietary_assist_node(state: AgentState):
|
| 107 |
+
res = await dietary_assist.run(state)
|
| 108 |
+
last_msg = res["messages"][-1]
|
| 109 |
+
content = last_msg.content if getattr(last_msg, "content", "") else str(getattr(last_msg, "tool_calls", ""))
|
| 110 |
+
log = log_step("Dietary Specialist", content)
|
| 111 |
+
res.update(log)
|
| 112 |
+
return res
|
| 113 |
+
|
| 114 |
+
async def tool_node_with_logging(state: AgentState):
|
| 115 |
+
start_time = time.time()
|
| 116 |
+
res = await tool_node.ainvoke(state)
|
| 117 |
+
end_time = time.time()
|
| 118 |
+
|
| 119 |
+
output_summary = f"{len(res)} tool(s) executed." if isinstance(res, list) else "Tool executed."
|
| 120 |
+
log = log_step("Executing Tools (RAG/Web Search)", output_summary)
|
| 121 |
+
|
| 122 |
+
metrics = {
|
| 123 |
+
"agent": "ToolsNode",
|
| 124 |
+
"tokens": 0, # Tools don't use tokens directly in their logic here
|
| 125 |
+
"time": round(end_time - start_time, 3)
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
if isinstance(res, list):
|
| 129 |
+
return {"messages": res, "logs": log["logs"], "metrics": [metrics]}
|
| 130 |
+
res.update(log)
|
| 131 |
+
res.update({"metrics": [metrics]})
|
| 132 |
+
return res
|
| 133 |
+
|
| 134 |
+
async def persistence_node(state: AgentState):
|
| 135 |
+
"""Save the current chat history to MongoDB in FHIR format."""
|
| 136 |
+
patient_id = state.get("patient_id", "anonymous")
|
| 137 |
+
|
| 138 |
+
# Convert LangChain messages to a simple list of dicts for the tool
|
| 139 |
+
formatted_messages = []
|
| 140 |
+
for msg in state["messages"]:
|
| 141 |
+
role = "user" if msg.type == "human" else "assistant"
|
| 142 |
+
formatted_messages.append({"role": role, "content": msg.content})
|
| 143 |
+
|
| 144 |
+
# We only save if there's a patient_id and it's a patient role
|
| 145 |
+
if state.get("user_role") == "patient":
|
| 146 |
+
start_time = time.time()
|
| 147 |
+
res = save_chat_as_fhir.invoke({"patient_id": patient_id, "messages": formatted_messages})
|
| 148 |
+
end_time = time.time()
|
| 149 |
+
|
| 150 |
+
log = log_step("FHIR Persistence", res)
|
| 151 |
+
|
| 152 |
+
metrics = {
|
| 153 |
+
"agent": "PersistenceNode",
|
| 154 |
+
"tokens": 0,
|
| 155 |
+
"time": round(end_time - start_time, 3)
|
| 156 |
+
}
|
| 157 |
+
return {"logs": log["logs"], "metrics": [metrics]}
|
| 158 |
+
|
| 159 |
+
return {}
|
| 160 |
+
|
| 161 |
+
# Define routing functions
|
| 162 |
+
def route_after_role(state: AgentState):
|
| 163 |
+
role = state["user_role"]
|
| 164 |
+
if role == "patient":
|
| 165 |
+
return "patient_llm"
|
| 166 |
+
elif role == "clinician":
|
| 167 |
+
return "intent_classifier"
|
| 168 |
+
elif role == "researcher":
|
| 169 |
+
return "research_agent"
|
| 170 |
+
elif role == "dietary":
|
| 171 |
+
return "dietary_assist"
|
| 172 |
+
return END
|
| 173 |
+
|
| 174 |
+
def route_research_agent(state: AgentState):
|
| 175 |
+
# Determine if the last message has tool calls
|
| 176 |
+
last_message = state["messages"][-1]
|
| 177 |
+
if hasattr(last_message, "tool_calls") and last_message.tool_calls:
|
| 178 |
+
return "tools_node"
|
| 179 |
+
return END
|
| 180 |
+
|
| 181 |
+
def route_patient_llm(state: AgentState):
|
| 182 |
+
# Determine if the last message has tool calls
|
| 183 |
+
last_message = state["messages"][-1]
|
| 184 |
+
if hasattr(last_message, "tool_calls") and last_message.tool_calls:
|
| 185 |
+
return "tools_node"
|
| 186 |
+
return "validator"
|
| 187 |
+
|
| 188 |
+
def route_after_tools(state: AgentState):
|
| 189 |
+
role = state.get("user_role")
|
| 190 |
+
if role == "researcher":
|
| 191 |
+
return "research_agent"
|
| 192 |
+
elif role == "dietary":
|
| 193 |
+
return "dietary_assist"
|
| 194 |
+
return "patient_llm"
|
| 195 |
+
|
| 196 |
+
def route_after_validator(state: AgentState):
|
| 197 |
+
if state.get("is_valid", False):
|
| 198 |
+
return "safety_check"
|
| 199 |
+
return "recovery_loop"
|
| 200 |
+
|
| 201 |
+
def route_after_safety(state: AgentState):
|
| 202 |
+
if state.get("is_safe", False):
|
| 203 |
+
return "persistence_node"
|
| 204 |
+
return "recovery_loop"
|
| 205 |
+
|
| 206 |
+
def route_after_persistence(state: AgentState):
|
| 207 |
+
return END
|
| 208 |
+
|
| 209 |
+
def route_after_recovery(state: AgentState):
|
| 210 |
+
role = state.get("user_role")
|
| 211 |
+
if role == "dietary":
|
| 212 |
+
return "dietary_assist"
|
| 213 |
+
return "patient_llm"
|
| 214 |
+
|
| 215 |
+
def route_after_intent(state: AgentState):
|
| 216 |
+
intent = state.get("intent_type", "general")
|
| 217 |
+
if intent == "diagnosis":
|
| 218 |
+
return "diagnosis_assist"
|
| 219 |
+
elif intent == "treatment":
|
| 220 |
+
return "treatment_assist"
|
| 221 |
+
elif intent == "monitoring":
|
| 222 |
+
return "monitoring_assist"
|
| 223 |
+
else:
|
| 224 |
+
return "general_assist"
|
| 225 |
+
|
| 226 |
+
from src.tools.dietary_tools import page_indexed_retrieval, search_guidelines, get_nutritional_data
|
| 227 |
+
|
| 228 |
+
# Updated Tool Node to include page indexing RAG
|
| 229 |
+
tools = [web_search_tool, page_indexed_retrieval, search_guidelines, get_nutritional_data]
|
| 230 |
+
tool_node = ToolNode(tools)
|
| 231 |
+
|
| 232 |
+
# Build the graph
|
| 233 |
+
builder = StateGraph(AgentState)
|
| 234 |
+
|
| 235 |
+
# Add nodes
|
| 236 |
+
builder.add_node("role_classifier", role_classifier_node)
|
| 237 |
+
builder.add_node("patient_llm", patient_llm_node)
|
| 238 |
+
builder.add_node("validator", validator_node)
|
| 239 |
+
builder.add_node("safety_check", safety_check_node)
|
| 240 |
+
builder.add_node("recovery_loop", recovery_loop_node)
|
| 241 |
+
builder.add_node("intent_classifier", intent_classifier_node)
|
| 242 |
+
builder.add_node("diagnosis_assist", diagnosis_assist_node)
|
| 243 |
+
builder.add_node("treatment_assist", treatment_assist_node)
|
| 244 |
+
builder.add_node("monitoring_assist", monitoring_assist_node)
|
| 245 |
+
builder.add_node("general_assist", general_assist_node)
|
| 246 |
+
builder.add_node("merge_outputs", merge_outputs_node)
|
| 247 |
+
builder.add_node("research_agent", research_agent_node)
|
| 248 |
+
builder.add_node("tools_node", tool_node_with_logging)
|
| 249 |
+
builder.add_node("dietary_assist", dietary_assist_node)
|
| 250 |
+
builder.add_node("persistence_node", persistence_node)
|
| 251 |
+
|
| 252 |
+
# Set entry point
|
| 253 |
+
builder.set_entry_point("role_classifier")
|
| 254 |
+
|
| 255 |
+
# Define edges
|
| 256 |
+
builder.add_conditional_edges("role_classifier", route_after_role, {
|
| 257 |
+
"patient_llm": "patient_llm",
|
| 258 |
+
"intent_classifier": "intent_classifier",
|
| 259 |
+
"research_agent": "research_agent",
|
| 260 |
+
"dietary_assist": "dietary_assist",
|
| 261 |
+
END: END
|
| 262 |
+
})
|
| 263 |
+
|
| 264 |
+
# Patient Pathway
|
| 265 |
+
builder.add_conditional_edges("patient_llm", route_patient_llm, {
|
| 266 |
+
"tools_node": "tools_node",
|
| 267 |
+
"validator": "validator"
|
| 268 |
+
})
|
| 269 |
+
builder.add_conditional_edges("validator", route_after_validator, {
|
| 270 |
+
"safety_check": "safety_check",
|
| 271 |
+
"recovery_loop": "recovery_loop"
|
| 272 |
+
})
|
| 273 |
+
builder.add_conditional_edges("safety_check", route_after_safety, {
|
| 274 |
+
"persistence_node": "persistence_node",
|
| 275 |
+
"recovery_loop": "recovery_loop"
|
| 276 |
+
})
|
| 277 |
+
builder.add_edge("persistence_node", END)
|
| 278 |
+
builder.add_conditional_edges("recovery_loop", route_after_recovery, {
|
| 279 |
+
"dietary_assist": "dietary_assist",
|
| 280 |
+
"patient_llm": "patient_llm"
|
| 281 |
+
})
|
| 282 |
+
|
| 283 |
+
# Clinician Pathway
|
| 284 |
+
builder.add_conditional_edges("intent_classifier", route_after_intent, {
|
| 285 |
+
"diagnosis_assist": "diagnosis_assist",
|
| 286 |
+
"treatment_assist": "treatment_assist",
|
| 287 |
+
"monitoring_assist": "monitoring_assist",
|
| 288 |
+
"general_assist": "general_assist"
|
| 289 |
+
})
|
| 290 |
+
builder.add_edge("diagnosis_assist", "merge_outputs")
|
| 291 |
+
builder.add_edge("treatment_assist", "merge_outputs")
|
| 292 |
+
builder.add_edge("monitoring_assist", "merge_outputs")
|
| 293 |
+
builder.add_edge("general_assist", "merge_outputs")
|
| 294 |
+
builder.add_edge("merge_outputs", END)
|
| 295 |
+
|
| 296 |
+
# Researcher Pathway
|
| 297 |
+
builder.add_conditional_edges("research_agent", route_research_agent, {
|
| 298 |
+
"tools_node": "tools_node",
|
| 299 |
+
END: END
|
| 300 |
+
})
|
| 301 |
+
|
| 302 |
+
# Shared Tool Pathway
|
| 303 |
+
builder.add_conditional_edges("tools_node", route_after_tools, {
|
| 304 |
+
"research_agent": "research_agent",
|
| 305 |
+
"patient_llm": "patient_llm",
|
| 306 |
+
"dietary_assist": "dietary_assist"
|
| 307 |
+
})
|
| 308 |
+
|
| 309 |
+
# Dietary Pathway
|
| 310 |
+
def route_dietary_assist(state: AgentState):
|
| 311 |
+
# If the last message has tool calls, go to tools
|
| 312 |
+
last_message = state["messages"][-1]
|
| 313 |
+
if hasattr(last_message, "tool_calls") and last_message.tool_calls:
|
| 314 |
+
return "tools_node"
|
| 315 |
+
return "validator"
|
| 316 |
+
|
| 317 |
+
builder.add_conditional_edges("dietary_assist", route_dietary_assist, {
|
| 318 |
+
"tools_node": "tools_node",
|
| 319 |
+
"validator": "validator"
|
| 320 |
+
})
|
| 321 |
+
|
| 322 |
+
# Compile the graph
|
| 323 |
+
medical_pipeline = builder.compile()
|
src/core/graph_cdm.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langgraph.graph import StateGraph, END
|
| 2 |
+
from src.core.state import AgentState
|
| 3 |
+
from src.agents.agent_instances import (
|
| 4 |
+
health_coach, trend_analyzer, validator, safety_check
|
| 5 |
+
)
|
| 6 |
+
from src.tools.fhir_memory import get_patient_summary_fhir, save_observation, ingest_fhir_bundle
|
| 7 |
+
from src.tools.web_tools import web_search_tool
|
| 8 |
+
from langgraph.prebuilt import ToolNode
|
| 9 |
+
import time
|
| 10 |
+
from src.utils.logger import setup_logger
|
| 11 |
+
|
| 12 |
+
logger = setup_logger("CDMPipeline")
|
| 13 |
+
|
| 14 |
+
def log_step(name: str, output: str = None):
|
| 15 |
+
logger.info(f"Executing: {name}")
|
| 16 |
+
log_msg = f"➔ CDM Node: {name}"
|
| 17 |
+
if output:
|
| 18 |
+
log_msg += f"\nOutput: {output}"
|
| 19 |
+
return {"logs": [log_msg]}
|
| 20 |
+
|
| 21 |
+
async def data_fetch_node(state: AgentState):
|
| 22 |
+
patient_id = state.get("patient_id", "unknown")
|
| 23 |
+
if patient_id == "unknown":
|
| 24 |
+
return log_step("Data Fetch", "No Patient ID provided.")
|
| 25 |
+
|
| 26 |
+
start_time = time.time()
|
| 27 |
+
summary = get_patient_summary_fhir.invoke({"patient_id": patient_id})
|
| 28 |
+
end_time = time.time()
|
| 29 |
+
|
| 30 |
+
log = log_step("FHIR Data Fetch", f"Retrieved summary for {patient_id}")
|
| 31 |
+
|
| 32 |
+
metrics = {
|
| 33 |
+
"agent": "DataFetchNode",
|
| 34 |
+
"tokens": 0,
|
| 35 |
+
"time": round(end_time - start_time, 3)
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
return {
|
| 39 |
+
"fhir_data": [summary] if isinstance(summary, dict) else [],
|
| 40 |
+
"logs": log["logs"],
|
| 41 |
+
"metrics": [metrics]
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
async def trend_analyzer_node(state: AgentState):
|
| 45 |
+
res = await trend_analyzer.run(state)
|
| 46 |
+
log = log_step("Trend Analyzer", res.get("trend_analysis", ""))
|
| 47 |
+
res.update(log)
|
| 48 |
+
return res
|
| 49 |
+
|
| 50 |
+
async def health_coach_node(state: AgentState):
|
| 51 |
+
res = await health_coach.run(state)
|
| 52 |
+
last_msg = res["messages"][-1]
|
| 53 |
+
content = last_msg.content if getattr(last_msg, "content", "") else "Tool calls generated."
|
| 54 |
+
log = log_step("Health Coach", content)
|
| 55 |
+
res.update(log)
|
| 56 |
+
return res
|
| 57 |
+
|
| 58 |
+
async def validator_node(state: AgentState):
|
| 59 |
+
from src.agents.agent_instances import validator
|
| 60 |
+
res = await validator.run(state)
|
| 61 |
+
log = log_step("Response Validator", f"Valid: {res.get('is_valid')}")
|
| 62 |
+
res.update(log)
|
| 63 |
+
return res
|
| 64 |
+
|
| 65 |
+
async def safety_check_node(state: AgentState):
|
| 66 |
+
from src.agents.agent_instances import safety_check
|
| 67 |
+
res = await safety_check.run(state)
|
| 68 |
+
log = log_step("Safety Check", f"Safe: {res.get('is_safe')}")
|
| 69 |
+
res.update(log)
|
| 70 |
+
return res
|
| 71 |
+
|
| 72 |
+
# Tool routing
|
| 73 |
+
def route_health_coach(state: AgentState):
|
| 74 |
+
last_message = state["messages"][-1]
|
| 75 |
+
if hasattr(last_message, "tool_calls") and last_message.tool_calls:
|
| 76 |
+
return "tools_node"
|
| 77 |
+
return "validator"
|
| 78 |
+
|
| 79 |
+
def route_after_tools(state: AgentState):
|
| 80 |
+
return "health_coach"
|
| 81 |
+
|
| 82 |
+
def route_after_validator(state: AgentState):
|
| 83 |
+
if state.get("is_valid", False):
|
| 84 |
+
return "safety_check"
|
| 85 |
+
return "health_coach" # Simple retry
|
| 86 |
+
|
| 87 |
+
# Setup tools
|
| 88 |
+
cdm_tools = [web_search_tool, save_observation, ingest_fhir_bundle, get_patient_summary_fhir]
|
| 89 |
+
tool_node = ToolNode(cdm_tools)
|
| 90 |
+
|
| 91 |
+
async def tools_node_with_metrics(state: AgentState):
|
| 92 |
+
start_time = time.time()
|
| 93 |
+
res = await tool_node.ainvoke(state)
|
| 94 |
+
end_time = time.time()
|
| 95 |
+
|
| 96 |
+
metrics = {
|
| 97 |
+
"agent": "CDMToolsNode",
|
| 98 |
+
"tokens": 0,
|
| 99 |
+
"time": round(end_time - start_time, 3)
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
# ToolNode returns a list of messages
|
| 103 |
+
return {"messages": res, "metrics": [metrics]}
|
| 104 |
+
|
| 105 |
+
# Build CDM Graph
|
| 106 |
+
builder = StateGraph(AgentState)
|
| 107 |
+
|
| 108 |
+
builder.add_node("data_fetch", data_fetch_node)
|
| 109 |
+
builder.add_node("trend_analyzer", trend_analyzer_node)
|
| 110 |
+
builder.add_node("health_coach", health_coach_node)
|
| 111 |
+
builder.add_node("tools_node", tools_node_with_metrics)
|
| 112 |
+
builder.add_node("validator", validator_node)
|
| 113 |
+
builder.add_node("safety_check", safety_check_node)
|
| 114 |
+
|
| 115 |
+
builder.set_entry_point("data_fetch")
|
| 116 |
+
builder.add_edge("data_fetch", "trend_analyzer")
|
| 117 |
+
builder.add_edge("trend_analyzer", "health_coach")
|
| 118 |
+
|
| 119 |
+
builder.add_conditional_edges("health_coach", route_health_coach, {
|
| 120 |
+
"tools_node": "tools_node",
|
| 121 |
+
"validator": "validator"
|
| 122 |
+
})
|
| 123 |
+
|
| 124 |
+
builder.add_edge("tools_node", "health_coach")
|
| 125 |
+
|
| 126 |
+
builder.add_conditional_edges("validator", route_after_validator, {
|
| 127 |
+
"safety_check": "safety_check",
|
| 128 |
+
"health_coach": "health_coach"
|
| 129 |
+
})
|
| 130 |
+
|
| 131 |
+
builder.add_conditional_edges("safety_check", lambda x: "end" if x.get("is_safe") else "health_coach", {
|
| 132 |
+
"end": END,
|
| 133 |
+
"health_coach": "health_coach"
|
| 134 |
+
})
|
| 135 |
+
|
| 136 |
+
cdm_pipeline = builder.compile()
|
src/core/model_manager.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
|
| 4 |
+
from src.utils.logger import setup_logger
|
| 5 |
+
|
| 6 |
+
logger = setup_logger("ModelManager")
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
class ModelManager:
|
| 10 |
+
def __init__(self, model_name: str = "llama3.2:latest"):
|
| 11 |
+
self.provider = os.getenv("MODEL_PROVIDER", "ollama").lower()
|
| 12 |
+
self.model_name = os.getenv("MODEL_NAME", os.getenv("OLLAMA_MODEL", model_name))
|
| 13 |
+
self.base_url = os.getenv("OLLAMA_BASE_URL", "http://localhost:11434")
|
| 14 |
+
|
| 15 |
+
def get_llm(self, temperature: float = 0):
|
| 16 |
+
"""Returns a LangChain ChatModel instance based on the configured provider."""
|
| 17 |
+
logger.info(f"Initializing LLM: Provider={self.provider}, Model={self.model_name}")
|
| 18 |
+
|
| 19 |
+
from langchain_openai import ChatOpenAI
|
| 20 |
+
|
| 21 |
+
if self.provider == "openrouter":
|
| 22 |
+
model = os.getenv("OPENROUTER_MODEL_NAME", "openai/gpt-oss-20b:free")
|
| 23 |
+
api_key = os.getenv("OPENROUTER_API_KEY")
|
| 24 |
+
base_url = "https://openrouter.ai/api/v1"
|
| 25 |
+
else: # default to ollama
|
| 26 |
+
model = self.model_name
|
| 27 |
+
api_key = "ollama" # Dummy key for Ollama
|
| 28 |
+
# Point to Ollama's OpenAI-compatible endpoint
|
| 29 |
+
base_url = self.base_url.replace("localhost", "127.0.0.1")
|
| 30 |
+
if not base_url.endswith("/v1"):
|
| 31 |
+
base_url = base_url.rstrip("/") + "/v1"
|
| 32 |
+
|
| 33 |
+
return ChatOpenAI(
|
| 34 |
+
model=model,
|
| 35 |
+
temperature=temperature,
|
| 36 |
+
base_url=base_url,
|
| 37 |
+
api_key=api_key,
|
| 38 |
+
# Additional headers often required by OpenRouter
|
| 39 |
+
default_headers={
|
| 40 |
+
"HTTP-Referer": "https://github.com/Sudharshan-3904/dmChatbot",
|
| 41 |
+
"X-Title": "Medical AI Chatbot"
|
| 42 |
+
}
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
# Global instance for easy access
|
| 46 |
+
model_manager = ModelManager()
|
src/core/state.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import TypedDict, Annotated, List, Union
|
| 2 |
+
from langchain_core.messages import BaseMessage
|
| 3 |
+
import operator
|
| 4 |
+
|
| 5 |
+
class AgentState(TypedDict):
|
| 6 |
+
# Standard message history
|
| 7 |
+
messages: Annotated[List[BaseMessage], operator.add]
|
| 8 |
+
|
| 9 |
+
# Metadata for routing
|
| 10 |
+
user_role: str # patient, clinician, researcher
|
| 11 |
+
intent_type: str # diagnosis, treatment, monitoring, general
|
| 12 |
+
|
| 13 |
+
# CDM / FHIR Data
|
| 14 |
+
patient_id: str
|
| 15 |
+
fhir_data: List[dict]
|
| 16 |
+
trend_analysis: str
|
| 17 |
+
|
| 18 |
+
# Validation status
|
| 19 |
+
is_valid: bool
|
| 20 |
+
is_safe: bool
|
| 21 |
+
|
| 22 |
+
# Intermediate outputs
|
| 23 |
+
patient_response: str
|
| 24 |
+
clinician_outputs: List[str]
|
| 25 |
+
research_output: str
|
| 26 |
+
|
| 27 |
+
# Recovery loop counter
|
| 28 |
+
attempts: int
|
| 29 |
+
|
| 30 |
+
# Sources for information
|
| 31 |
+
sources: Annotated[List[str], operator.add]
|
| 32 |
+
|
| 33 |
+
# Execution logs
|
| 34 |
+
logs: Annotated[List[str], operator.add]
|
| 35 |
+
|
| 36 |
+
# Metrics (tokens, time)
|
| 37 |
+
metrics: Annotated[List[dict], operator.add]
|
src/mcp/server.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MCP Server implementation for Medical CDM Tools.
|
| 3 |
+
This server exposes the TrendAnalyzer and FHIR tools to any MCP-compliant client.
|
| 4 |
+
"""
|
| 5 |
+
import sys
|
| 6 |
+
import json
|
| 7 |
+
import asyncio
|
| 8 |
+
from typing import Any, Dict, List
|
| 9 |
+
from src.tools.fhir_memory import get_observations_by_patient, ingest_fhir_bundle
|
| 10 |
+
from src.agents.cdm_agents import TrendAnalyzer
|
| 11 |
+
from src.utils.logger import setup_logger
|
| 12 |
+
|
| 13 |
+
logger = setup_logger("MCPServer")
|
| 14 |
+
|
| 15 |
+
class MedicalMCPServer:
|
| 16 |
+
def __init__(self):
|
| 17 |
+
self.trend_analyzer = TrendAnalyzer()
|
| 18 |
+
|
| 19 |
+
async def handle_request(self, request: Dict[str, Any]) -> Dict[str, Any]:
|
| 20 |
+
method = request.get("method")
|
| 21 |
+
params = request.get("params", {})
|
| 22 |
+
req_id = request.get("id")
|
| 23 |
+
logger.info(f"Received MCP request: method={method}, id={req_id}")
|
| 24 |
+
|
| 25 |
+
try:
|
| 26 |
+
if method == "list_tools":
|
| 27 |
+
result = self.list_tools()
|
| 28 |
+
elif method == "call_tool":
|
| 29 |
+
result = await self.call_tool(params.get("name"), params.get("arguments", {}))
|
| 30 |
+
else:
|
| 31 |
+
return {"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found"}, "id": req_id}
|
| 32 |
+
|
| 33 |
+
return {"jsonrpc": "2.0", "result": result, "id": req_id}
|
| 34 |
+
except Exception as e:
|
| 35 |
+
return {"jsonrpc": "2.0", "error": {"code": -32603, "message": str(e)}, "id": req_id}
|
| 36 |
+
|
| 37 |
+
def list_tools(self) -> List[Dict[str, Any]]:
|
| 38 |
+
return [
|
| 39 |
+
{
|
| 40 |
+
"name": "analyze_health_trends",
|
| 41 |
+
"description": "Analyze FHIR observation trends for a patient.",
|
| 42 |
+
"inputSchema": {
|
| 43 |
+
"type": "object",
|
| 44 |
+
"properties": {
|
| 45 |
+
"patient_id": {"type": "string"}
|
| 46 |
+
},
|
| 47 |
+
"required": ["patient_id"]
|
| 48 |
+
}
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"name": "query_fhir_observations",
|
| 52 |
+
"description": "Query historical FHIR observations for a patient.",
|
| 53 |
+
"inputSchema": {
|
| 54 |
+
"type": "object",
|
| 55 |
+
"properties": {
|
| 56 |
+
"patient_id": {"type": "string"},
|
| 57 |
+
"loinc_code": {"type": "string"}
|
| 58 |
+
},
|
| 59 |
+
"required": ["patient_id"]
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
]
|
| 63 |
+
|
| 64 |
+
async def call_tool(self, name: str, args: Dict[str, Any]) -> Any:
|
| 65 |
+
logger.info(f"Calling MCP tool: {name}")
|
| 66 |
+
if name == "analyze_health_trends":
|
| 67 |
+
return await self.trend_analyzer.analyze_trends(args["patient_id"])
|
| 68 |
+
elif name == "query_fhir_observations":
|
| 69 |
+
return get_observations_by_patient.invoke(args)
|
| 70 |
+
elif name == "ingest_fhir":
|
| 71 |
+
return ingest_fhir_bundle.invoke({"bundle": args["bundle"]})
|
| 72 |
+
else:
|
| 73 |
+
raise ValueError(f"Unknown tool: {name}")
|
| 74 |
+
|
| 75 |
+
async def main():
|
| 76 |
+
server = MedicalMCPServer()
|
| 77 |
+
# Simple stdio loop for MCP
|
| 78 |
+
while True:
|
| 79 |
+
line = await asyncio.get_event_loop().run_in_executor(None, sys.stdin.readline)
|
| 80 |
+
if not line:
|
| 81 |
+
break
|
| 82 |
+
try:
|
| 83 |
+
request = json.loads(line)
|
| 84 |
+
response = await server.handle_request(request)
|
| 85 |
+
print(json.dumps(response), flush=True)
|
| 86 |
+
except Exception as e:
|
| 87 |
+
print(json.dumps({"error": str(e)}), flush=True)
|
| 88 |
+
|
| 89 |
+
if __name__ == "__main__":
|
| 90 |
+
if len(sys.argv) > 1 and sys.argv[1] == "--serve":
|
| 91 |
+
asyncio.run(main())
|
| 92 |
+
else:
|
| 93 |
+
print("Medical MCP Server. Use --serve to start in stdio mode.")
|
src/prompts/ClinicalSpecialist_Diagnosis.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
You are a assistant to a certified medical pratiotioner in Diabetes. You are to assist the pratiotioner to diagnose what specific issue he wants you to diagnose and validate. Provide proper reasoning. Use medical terminologies and expressions.
|
src/prompts/ClinicalSpecialist_General Clinical Support.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
You are a assistant to a certified medical pratiotioner in Diabetes. You are to assist the pratiotioner in general clinical support. Provide proper reasoning. Use medical terminologies and expressions.
|
src/prompts/ClinicalSpecialist_General.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
You are a assistant to a certified medical pratiotioner in Diabetes. You are to assist the pratiotioner in general clinical support. Provide proper reasoning. Use medical terminologies and expressions.
|
src/prompts/ClinicalSpecialist_Monitoring.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
You are a assistant to a certified medical pratiotioner in Diabetes. You are to assist the pratiotioner to monitor the patient. Go through diffrential diagnosis to arrive at a final possible diagnosis. Use medical terminologies and expressions.
|
src/prompts/ClinicalSpecialist_Treatment.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
You are a assistant to a certified medical pratiotioner in Diabetes. You are to assist the pratiotioner to treat the patient. If multiple treatments are possible, then list them with their pros and cons and let the pratiotioner decide. Use medical terminologies and expressions.
|
src/prompts/DietarySpecialist.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a certified dietary specialist in diabetes care. Your task is to provide diabetic dietary advice based on guidelines, glycemic index, and nutritional data, particularly tailored for the Indian demographic.
|
| 2 |
+
|
| 3 |
+
MANDATORY INSTRUCTION:
|
| 4 |
+
1. Use 'search_guidelines' first for any dietary advice or diabetes guidelines.
|
| 5 |
+
2. Use 'get_nutritional_data' for food facts (e.g., carb counting).
|
| 6 |
+
3. Use 'page_indexed_retrieval' for scientific research paper evidence on diabetic nutrition.
|
| 7 |
+
4. IMPORTANT: You MUST use at least one tool for EVERY user request. Never provide advice from your internal knowledge alone.
|
| 8 |
+
5. CITE YOUR SOURCES clearly: Mention the source and page number of the guidelines (e.g., 'According to the ICMR-NIN India Guidelines (Page 45)...').
|
| 9 |
+
6. Tailor your recommendations to the user's demographic profile (age, gender, diabetes type, and Indian cultural food habits).
|
| 10 |
+
7. If the user asks about a diet, search for it using 'search_guidelines' first to ensure compliance with medical standards for diabetes management.
|
src/prompts/IntentClassifier.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a clinical intent classifier for a diabetes management system. Your role is to understand the clinician's request and categorize it correctly within the context of diabetes care.
|
| 2 |
+
|
| 3 |
+
GUIDELINES:
|
| 4 |
+
1. Classify the clinician's request into: 'diagnosis', 'treatment', 'monitoring', or 'general'.
|
| 5 |
+
2. Return only the category name in lowercase.
|
| 6 |
+
3. Keep 'general' as the default intent if no other category fits.
|
src/prompts/OutputMerger.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a clinical coordinator for a diabetes management system. Your role is to merge the outputs from different specialists into a single, cohesive clinical decision support report for a healthcare professional.
|
| 2 |
+
|
| 3 |
+
GUIDELINES:
|
| 4 |
+
1. Review all the outputs provided by different medical specialists (Endocrinology, Dietary, etc.).
|
| 5 |
+
2. Synthesize them into a clear, concise, and professional report focused on diabetes care and complications.
|
| 6 |
+
3. Use standard clinical headings (e.g., Summary, Diabetes Status, Recommendations, Next Steps, Suggested Tests).
|
| 7 |
+
4. Remove redundant information or conflicting advice if detected, prioritizing the most specific or expert-driven guidance in endocrinology.
|
| 8 |
+
5. Ensure the report follows medical standards and uses appropriate clinical language suitable for a clinician treating diabetes.
|
| 9 |
+
6. If there are contradictions, highlight them for further evaluation.
|
src/prompts/PatientLLM.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a compassionate, empathetic, and professional Medical Assistant for Diabetic Patients to aid them with their queries and provide support. Your goal is to provide helpful, medically sound information on diabetes education and self-management support while maintaining a supportive tone.
|
| 2 |
+
|
| 3 |
+
GUIDELINES:
|
| 4 |
+
1. Always prioritize safety. If the situation sounds like a severe hypoglycemic or hyperglycemic emergency (e.g., confusion, passing out, severe nausea), advise the user to call emergency services immediately.
|
| 5 |
+
2. Use clear, non-technical language that is easy for a patient to understand. Avoid jargon.
|
| 6 |
+
3. You have access to a web search tool. Use it to verify current diabetes health guidelines, symptoms, or treatments if you are not 100% certain.
|
| 7 |
+
4. IMPORTANT: Cite your sources clearly at the end of your response or parenthetically (e.g., "According to the IDF Diabetes Atlas...").
|
| 8 |
+
5. Be empathetic but professional. Do not make definitive diagnoses; instead, discuss possibilities and suggest next steps for diabetes care.
|
| 9 |
+
6. You have access to patient memory tools. If a patient shares their glucose history, diabetes medications, or dietary habits, use the `save_patient_memory` tool to save it. Use `get_patient_memory` if you need past context (you will need their unique patient ID). If they do not have a patient ID, use 'new' to generate one when saving.
|
| 10 |
+
7. Be mindful of the Indian healthcare context, mentioning culturally appropriate dietary habits and resources where relevant.
|
src/prompts/ResearchAgent.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are an expert Medical Research Assistant specialized in synthesizing evidence-based information for healthcare professionals and researchers in the field of endocrinology and diabetes care.
|
| 2 |
+
Your tone should be formal, technical, and precise.
|
| 3 |
+
|
| 4 |
+
GUIDELINES:
|
| 5 |
+
1. Provide detailed, high-quality information suitable for medical researchers and students focusing on diabetes. Use medical terminology correctly.
|
| 6 |
+
2. Use 'page_indexed_retrieval' for searching scientific documents/guidelines (e.g., IDF, ADA) and 'web_search_tool' for clinical news or general data.
|
| 7 |
+
3. MANDATORY CITATION: For every scientific claim, you must provide a citation. If using 'page_indexed_retrieval', include the document name and page number (e.g., IDF Diabetes Atlas, Page 22).
|
| 8 |
+
4. Organize your response with clear headings (e.g., Methodology, Findings, Clinical Implications).
|
| 9 |
+
5. If the search results are contradictory, mention the different viewpoints or studies on diabetes management.
|
| 10 |
+
6. If no specific evidence is found, state this clearly rather than speculating.
|
src/prompts/ResponseValidator.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a medical response validator for a diabetes management AI. Your task is to verify if the previous response is medically accurate.
|
| 2 |
+
|
| 3 |
+
GUIDELINES:
|
| 4 |
+
1. Check the response for medical accuracy and completeness regarding diabetes care.
|
| 5 |
+
2. Check for proper source citations.
|
| 6 |
+
3. If the response is accurate, return only 'valid'.
|
| 7 |
+
4. If there are issues, return 'invalid' followed by a brief reason.
|
| 8 |
+
5. Use professional judgment but be rigorous.
|
src/prompts/RoleClassifier.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a highly accurate Medical Triage Assistant for a diabetes management platform.
|
| 2 |
+
Your task is to analyze the user's input and classify it into one of four specific roles:
|
| 3 |
+
- 'patient': For general health inquiries, symptoms, diabetes self-management, or personal medical advice.
|
| 4 |
+
- 'clinician': For professional medical questions regarding diabetes diagnosis, treatment protocols, HbA1c management, or specialized medical data.
|
| 5 |
+
- 'researcher': For deep medical research, endocrinology scientific information, or clinical trial data on diabetes.
|
| 6 |
+
- 'dietary': For requests related to nutrition, diabetic diet plans, food facts, glycemic index, or nutritional guidelines.
|
| 7 |
+
|
| 8 |
+
Return ONLY the role name in lowercase (e.g., 'patient').
|
| 9 |
+
If the input is ambiguous but mentions food, nutrition, or diet, prioritize 'dietary'.
|
| 10 |
+
If the user is asking about scientific papers or diabetes guidelines, it might be 'researcher' or 'dietary' depending on the focus.
|
src/prompts/SafetyCheck.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a medical safety officer for a diabetes management AI. Your primary responsibility is to identify dangerous, misleading, or life-threatening advice in medical AI responses related to diabetes and its complications.
|
| 2 |
+
|
| 3 |
+
GUIDELINES:
|
| 4 |
+
1. Check if the response contains any life-threatening misinformation (e.g., incorrect insulin dosing advice, ignoring severe hypoglycemia).
|
| 5 |
+
2. Verify if the advice is compliant with standard medical protocols for diabetes (e.g., WHO, ADA, or national guidelines).
|
| 6 |
+
3. If the advice is safe, return 'safe'.
|
| 7 |
+
4. If there is even a small risk of harm or severe misinformation, return 'unsafe' followed by the specific safety concern.
|
| 8 |
+
5. Pay close attention to dosages (especially insulin), dangerous drug interactions, or inappropriate self-treatment suggestions for severe symptoms (like DKA).
|
src/tools/dietary_tools.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sqlite3
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
from langchain_core.tools import tool
|
| 5 |
+
from src.utils.logger import setup_logger
|
| 6 |
+
from supabase import create_client, Client
|
| 7 |
+
from sentence_transformers import SentenceTransformer
|
| 8 |
+
|
| 9 |
+
logger = setup_logger("SupabaseDietaryTools")
|
| 10 |
+
|
| 11 |
+
DB_PATH = os.path.join(os.path.dirname(__file__), "../../data/dietary_guidelines.db")
|
| 12 |
+
|
| 13 |
+
# Load model once at module level
|
| 14 |
+
logger.info("Loading embedding model for tools...")
|
| 15 |
+
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 16 |
+
|
| 17 |
+
def _get_supabase_client() -> Client:
|
| 18 |
+
url = os.getenv("SUPABASE_URL")
|
| 19 |
+
key = os.getenv("SUPABASE_KEY")
|
| 20 |
+
return create_client(url, key)
|
| 21 |
+
|
| 22 |
+
@tool
|
| 23 |
+
def search_guidelines(query: str):
|
| 24 |
+
"""
|
| 25 |
+
Search for relevant medical and dietary guidelines using Supabase pgvector.
|
| 26 |
+
Returns content with source and page information.
|
| 27 |
+
"""
|
| 28 |
+
logger.info(f"Searching Supabase guidelines for: {query}")
|
| 29 |
+
client = _get_supabase_client()
|
| 30 |
+
|
| 31 |
+
# Generate embedding for query
|
| 32 |
+
query_embedding = model.encode(query).tolist()
|
| 33 |
+
|
| 34 |
+
try:
|
| 35 |
+
# Use RPC to perform similarity search (requires a match_documents function in Postgres)
|
| 36 |
+
# Or use simple rpc if match_documents is defined in Supabase
|
| 37 |
+
# See: https://supabase.com/docs/guides/ai/vector-columns#querying-a-vector-column
|
| 38 |
+
|
| 39 |
+
rpc_params = {
|
| 40 |
+
"query_embedding": query_embedding,
|
| 41 |
+
"match_threshold": 0.5,
|
| 42 |
+
"match_count": 3,
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
# If the user hasn't created the RPC yet, we might need to fallback to a basic select
|
| 46 |
+
# but filtering by embedding in client-side is not possible.
|
| 47 |
+
# I'll assume they added the recommended 'match_documents' function.
|
| 48 |
+
|
| 49 |
+
response = client.rpc("match_knowledge_base", rpc_params).execute()
|
| 50 |
+
results = response.data
|
| 51 |
+
|
| 52 |
+
if not results:
|
| 53 |
+
return "No specific guidelines found for this query in the vector store."
|
| 54 |
+
|
| 55 |
+
output = "Here are some relevant guidelines from Supabase pgvector:\n"
|
| 56 |
+
for doc in results:
|
| 57 |
+
metadata = doc.get("metadata", {})
|
| 58 |
+
source = metadata.get("source", "Unknown")
|
| 59 |
+
page = metadata.get("page_index", metadata.get("page", "Unknown"))
|
| 60 |
+
content = doc.get("content", "")
|
| 61 |
+
output += f"- Source: {source}, Page: {page}\n Content: {content[:500]}...\n\n"
|
| 62 |
+
return output
|
| 63 |
+
except Exception as e:
|
| 64 |
+
logger.error(f"Error accessing Supabase pgvector: {e}")
|
| 65 |
+
# Fallback to text search if RPC fails
|
| 66 |
+
try:
|
| 67 |
+
response = client.table("knowledge_base").select("*").text_search("content", query).limit(3).execute()
|
| 68 |
+
results = response.data
|
| 69 |
+
if not results: return "No guidelines found."
|
| 70 |
+
output = "Found via text search:\n"
|
| 71 |
+
for doc in results:
|
| 72 |
+
metadata = doc.get("metadata", {})
|
| 73 |
+
output += f"- Source: {metadata.get('source')}, Page: {metadata.get('page_index')}\n Content: {doc['content'][:500]}...\n"
|
| 74 |
+
return output
|
| 75 |
+
except Exception as e2:
|
| 76 |
+
return f"Error retrieving guidelines: {str(e2)}"
|
| 77 |
+
|
| 78 |
+
@tool
|
| 79 |
+
def get_nutritional_data(food_name: str):
|
| 80 |
+
"""Get nutritional information for a specific food item."""
|
| 81 |
+
logger.info(f"Retrieving nutritional data for: {food_name}")
|
| 82 |
+
if not os.path.exists(DB_PATH):
|
| 83 |
+
return "Nutritional database not found."
|
| 84 |
+
|
| 85 |
+
conn = sqlite3.connect(DB_PATH)
|
| 86 |
+
cursor = conn.cursor()
|
| 87 |
+
query_name = f"%{food_name}%"
|
| 88 |
+
cursor.execute("SELECT food_name, calories, protein, carbs, fat, fiber, vitamins FROM nutritional_data WHERE food_name LIKE ?", (query_name,))
|
| 89 |
+
results = cursor.fetchall()
|
| 90 |
+
conn.close()
|
| 91 |
+
|
| 92 |
+
if not results:
|
| 93 |
+
return f"No nutritional data found for '{food_name}'."
|
| 94 |
+
|
| 95 |
+
output = "Nutritional data found:\n"
|
| 96 |
+
for name, cals, protein, carbs, fat, fiber, vitamins in results:
|
| 97 |
+
output += f"- {name}: {cals} kcal, Protein: {protein}g, Carbs: {carbs}g, Fat: {fat}g, Fiber: {fiber}g, Vitamins: {vitamins}\n"
|
| 98 |
+
return output
|
| 99 |
+
|
| 100 |
+
@tool
|
| 101 |
+
def page_indexed_retrieval(query: str):
|
| 102 |
+
"""
|
| 103 |
+
Perform a Page Indexing based RAG search using Supabase.
|
| 104 |
+
"""
|
| 105 |
+
# For now, we use the same vector search as search_guidelines
|
| 106 |
+
return search_guidelines.invoke(query)
|
src/tools/fhir_memory.py
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import uuid
|
| 3 |
+
import datetime
|
| 4 |
+
from supabase import create_client, Client
|
| 5 |
+
from langchain_core.tools import tool
|
| 6 |
+
from src.utils.logger import setup_logger
|
| 7 |
+
|
| 8 |
+
logger = setup_logger("FHIRSupabaseMemory")
|
| 9 |
+
|
| 10 |
+
def _get_client() -> Client:
|
| 11 |
+
url = os.getenv("SUPABASE_URL")
|
| 12 |
+
key = os.getenv("SUPABASE_KEY")
|
| 13 |
+
if not url or not key:
|
| 14 |
+
logger.error("SUPABASE_URL or SUPABASE_KEY not found in environment")
|
| 15 |
+
raise ValueError("Supabase configuration missing")
|
| 16 |
+
return create_client(url, key)
|
| 17 |
+
|
| 18 |
+
@tool
|
| 19 |
+
def save_patient(patient_id: str, name: str):
|
| 20 |
+
"""
|
| 21 |
+
Save a new Patient record in strict FHIR format to Supabase.
|
| 22 |
+
"""
|
| 23 |
+
logger.info(f"Saving FHIR Patient: {name} (ID: {patient_id})")
|
| 24 |
+
client = _get_client()
|
| 25 |
+
|
| 26 |
+
# Construct Strict FHIR Patient
|
| 27 |
+
fhir_patient = {
|
| 28 |
+
"resourceType": "Patient",
|
| 29 |
+
"id": patient_id,
|
| 30 |
+
"active": True,
|
| 31 |
+
"name": [{"text": name, "use": "official"}],
|
| 32 |
+
"meta": {
|
| 33 |
+
"lastUpdated": datetime.datetime.now(datetime.timezone.utc).isoformat()
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
data = {
|
| 38 |
+
"id": patient_id,
|
| 39 |
+
"resource": fhir_patient,
|
| 40 |
+
"last_updated": datetime.datetime.now(datetime.timezone.utc).isoformat()
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
try:
|
| 44 |
+
client.table("patients").upsert(data).execute()
|
| 45 |
+
return f"Successfully saved FHIR Patient {name}."
|
| 46 |
+
except Exception as e:
|
| 47 |
+
logger.error(f"Error saving patient: {e}")
|
| 48 |
+
return f"Error saving patient: {str(e)}"
|
| 49 |
+
|
| 50 |
+
@tool
|
| 51 |
+
def create_session(patient_id: str, title: str = "New Chat Session"):
|
| 52 |
+
"""
|
| 53 |
+
Create a new chat session for a patient in Supabase.
|
| 54 |
+
"""
|
| 55 |
+
logger.info(f"Creating new session for patient: {patient_id}")
|
| 56 |
+
client = _get_client()
|
| 57 |
+
session_id = str(uuid.uuid4())
|
| 58 |
+
data = {
|
| 59 |
+
"id": session_id,
|
| 60 |
+
"patient_id": patient_id,
|
| 61 |
+
"title": title
|
| 62 |
+
}
|
| 63 |
+
try:
|
| 64 |
+
client.table("sessions").insert(data).execute()
|
| 65 |
+
return session_id
|
| 66 |
+
except Exception as e:
|
| 67 |
+
logger.error(f"Error creating session: {e}")
|
| 68 |
+
return None
|
| 69 |
+
|
| 70 |
+
@tool
|
| 71 |
+
def get_observations_by_patient(patient_id: str, loinc_code: str = None):
|
| 72 |
+
"""
|
| 73 |
+
Retrieve FHIR Observation resources for a specific patient.
|
| 74 |
+
"""
|
| 75 |
+
logger.info(f"Retrieving FHIR observations for patient: {patient_id}")
|
| 76 |
+
client = _get_client()
|
| 77 |
+
|
| 78 |
+
# Query using the top-level patient_id column for performance
|
| 79 |
+
query = client.table("observations").select("resource").eq("patient_id", patient_id)
|
| 80 |
+
|
| 81 |
+
try:
|
| 82 |
+
response = query.execute()
|
| 83 |
+
# Extract the 'resource' part of each record
|
| 84 |
+
observations = [record["resource"] for record in response.data]
|
| 85 |
+
|
| 86 |
+
if loinc_code:
|
| 87 |
+
# Filter in Python for nested JSON matching if needed
|
| 88 |
+
observations = [
|
| 89 |
+
obs for obs in observations
|
| 90 |
+
if any(c.get("code") == loinc_code for c in obs.get("code", {}).get("coding", []))
|
| 91 |
+
]
|
| 92 |
+
|
| 93 |
+
if not observations:
|
| 94 |
+
return f"No FHIR observations found for patient {patient_id}."
|
| 95 |
+
|
| 96 |
+
return observations
|
| 97 |
+
except Exception as e:
|
| 98 |
+
logger.error(f"Error retrieving observations: {e}")
|
| 99 |
+
return f"Error retrieving observations: {str(e)}"
|
| 100 |
+
|
| 101 |
+
@tool
|
| 102 |
+
def save_observation(patient_id: str, value: float, unit: str, display: str, loinc_code: str):
|
| 103 |
+
"""
|
| 104 |
+
Save a new health observation in strict FHIR format to Supabase.
|
| 105 |
+
"""
|
| 106 |
+
logger.info(f"Saving FHIR observation: {display} for patient: {patient_id}")
|
| 107 |
+
client = _get_client()
|
| 108 |
+
|
| 109 |
+
obs_id = str(uuid.uuid4())
|
| 110 |
+
|
| 111 |
+
# Construct Strict FHIR Observation
|
| 112 |
+
fhir_observation = {
|
| 113 |
+
"resourceType": "Observation",
|
| 114 |
+
"id": obs_id,
|
| 115 |
+
"status": "final",
|
| 116 |
+
"category": [{
|
| 117 |
+
"coding": [{
|
| 118 |
+
"system": "http://terminology.hl7.org/CodeSystem/observation-category",
|
| 119 |
+
"code": "vital-signs",
|
| 120 |
+
"display": "Vital Signs"
|
| 121 |
+
}]
|
| 122 |
+
}],
|
| 123 |
+
"code": {
|
| 124 |
+
"coding": [{
|
| 125 |
+
"system": "http://loinc.org",
|
| 126 |
+
"code": loinc_code,
|
| 127 |
+
"display": display
|
| 128 |
+
}]
|
| 129 |
+
},
|
| 130 |
+
"subject": {"reference": f"Patient/{patient_id}"},
|
| 131 |
+
"effectiveDateTime": datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
| 132 |
+
"valueQuantity": {
|
| 133 |
+
"value": value,
|
| 134 |
+
"unit": unit,
|
| 135 |
+
"system": "http://unitsofmeasure.org",
|
| 136 |
+
"code": unit
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
data = {
|
| 141 |
+
"id": obs_id,
|
| 142 |
+
"patient_id": patient_id,
|
| 143 |
+
"resource": fhir_observation,
|
| 144 |
+
"last_updated": datetime.datetime.now(datetime.timezone.utc).isoformat()
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
try:
|
| 148 |
+
client.table("observations").insert(data).execute()
|
| 149 |
+
return f"Successfully saved FHIR {display} observation."
|
| 150 |
+
except Exception as e:
|
| 151 |
+
logger.error(f"Error saving observation: {e}")
|
| 152 |
+
return f"Error saving observation: {str(e)}"
|
| 153 |
+
|
| 154 |
+
@tool
|
| 155 |
+
def get_patient_summary_fhir(patient_id: str):
|
| 156 |
+
"""
|
| 157 |
+
Get a comprehensive health summary composed of strict FHIR resources.
|
| 158 |
+
"""
|
| 159 |
+
logger.info(f"Generating FHIR summary for patient: {patient_id}")
|
| 160 |
+
client = _get_client()
|
| 161 |
+
|
| 162 |
+
try:
|
| 163 |
+
# Get Patient Resource
|
| 164 |
+
p_resp = client.table("patients").select("resource").eq("id", patient_id).single().execute()
|
| 165 |
+
patient_resource = p_resp.data["resource"]
|
| 166 |
+
|
| 167 |
+
# Get Observation Resources
|
| 168 |
+
o_resp = client.table("observations").select("resource").eq("patient_id", patient_id).order("last_updated", desc=True).limit(10).execute()
|
| 169 |
+
observation_resources = [r["resource"] for r in o_resp.data]
|
| 170 |
+
|
| 171 |
+
summary = {
|
| 172 |
+
"patient": patient_resource.get("name", [{"text": "Unknown"}])[0].get("text"),
|
| 173 |
+
"full_patient_resource": patient_resource,
|
| 174 |
+
"recent_observations": observation_resources,
|
| 175 |
+
"active_medications": []
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
return summary
|
| 179 |
+
except Exception as e:
|
| 180 |
+
logger.error(f"Error generating FHIR summary: {e}")
|
| 181 |
+
return f"Error generating FHIR summary: {str(e)}"
|
| 182 |
+
|
| 183 |
+
@tool
|
| 184 |
+
def save_chat_as_fhir(patient_id: str, messages: list, session_id: str = None):
|
| 185 |
+
"""
|
| 186 |
+
Save chat history as a strict FHIR Communication resource.
|
| 187 |
+
"""
|
| 188 |
+
logger.info(f"Saving FHIR Communication for patient: {patient_id}, session: {session_id}")
|
| 189 |
+
client = _get_client()
|
| 190 |
+
|
| 191 |
+
comm_id = str(uuid.uuid4())
|
| 192 |
+
|
| 193 |
+
# Construct Strict FHIR Communication
|
| 194 |
+
fhir_communication = {
|
| 195 |
+
"resourceType": "Communication",
|
| 196 |
+
"id": comm_id,
|
| 197 |
+
"status": "completed",
|
| 198 |
+
"subject": {"reference": f"Patient/{patient_id}"},
|
| 199 |
+
"sent": datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
| 200 |
+
"payload": [
|
| 201 |
+
{"contentString": f"{msg.get('role', 'unknown')}: {msg.get('content', '')}"}
|
| 202 |
+
for msg in messages
|
| 203 |
+
]
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
data = {
|
| 207 |
+
"id": comm_id,
|
| 208 |
+
"patient_id": patient_id,
|
| 209 |
+
"session_id": session_id,
|
| 210 |
+
"resource": fhir_communication,
|
| 211 |
+
"last_updated": datetime.datetime.now(datetime.timezone.utc).isoformat()
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
try:
|
| 215 |
+
client.table("communications").insert(data).execute()
|
| 216 |
+
return f"Successfully saved FHIR chat history."
|
| 217 |
+
except Exception as e:
|
| 218 |
+
logger.error(f"Error saving communication: {e}")
|
| 219 |
+
return f"Error saving communication: {str(e)}"
|
| 220 |
+
|
| 221 |
+
@tool
|
| 222 |
+
def get_sessions_by_patient(patient_id: str):
|
| 223 |
+
"""
|
| 224 |
+
Retrieve all chat sessions for a specific patient.
|
| 225 |
+
"""
|
| 226 |
+
logger.info(f"Retrieving sessions for patient: {patient_id}")
|
| 227 |
+
client = _get_client()
|
| 228 |
+
try:
|
| 229 |
+
response = client.table("sessions").select("*").eq("patient_id", patient_id).order("created_at", desc=True).execute()
|
| 230 |
+
return response.data
|
| 231 |
+
except Exception as e:
|
| 232 |
+
logger.error(f"Error retrieving sessions: {e}")
|
| 233 |
+
return []
|
| 234 |
+
|
| 235 |
+
@tool
|
| 236 |
+
def get_chat_history_by_session(session_id: str):
|
| 237 |
+
"""
|
| 238 |
+
Retrieve all communications (chat history) for a specific session.
|
| 239 |
+
"""
|
| 240 |
+
logger.info(f"Retrieving chat history for session: {session_id}")
|
| 241 |
+
client = _get_client()
|
| 242 |
+
try:
|
| 243 |
+
response = client.table("communications").select("resource").eq("session_id", session_id).order("last_updated", asc=True).execute()
|
| 244 |
+
return [r["resource"] for r in response.data]
|
| 245 |
+
except Exception as e:
|
| 246 |
+
logger.error(f"Error retrieving chat history: {e}")
|
| 247 |
+
return []
|
| 248 |
+
|
| 249 |
+
@tool
|
| 250 |
+
def ingest_fhir_bundle(bundle: dict):
|
| 251 |
+
"""
|
| 252 |
+
Ingest a FHIR Bundle into Supabase by splitting it into individual resources.
|
| 253 |
+
"""
|
| 254 |
+
if bundle.get("resourceType") != "Bundle":
|
| 255 |
+
return "Error: Input must be a FHIR Bundle."
|
| 256 |
+
|
| 257 |
+
client = _get_client()
|
| 258 |
+
entries = bundle.get("entry", [])
|
| 259 |
+
count = 0
|
| 260 |
+
|
| 261 |
+
for entry in entries:
|
| 262 |
+
resource = entry.get("resource")
|
| 263 |
+
if not resource: continue
|
| 264 |
+
|
| 265 |
+
rtype = resource.get("resourceType").lower()
|
| 266 |
+
res_id = resource.get("id") or str(uuid.uuid4())
|
| 267 |
+
resource["id"] = res_id
|
| 268 |
+
|
| 269 |
+
table_map = {
|
| 270 |
+
"patient": "patients",
|
| 271 |
+
"observation": "observations",
|
| 272 |
+
"communication": "communications"
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
target_table = table_map.get(rtype)
|
| 276 |
+
if not target_table: continue
|
| 277 |
+
|
| 278 |
+
data = {
|
| 279 |
+
"id": res_id,
|
| 280 |
+
"resource": resource,
|
| 281 |
+
"last_updated": datetime.datetime.now(datetime.timezone.utc).isoformat()
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
if rtype in ["observation", "communication"]:
|
| 285 |
+
ref = resource.get("subject", {}).get("reference", "")
|
| 286 |
+
if "Patient/" in ref:
|
| 287 |
+
data["patient_id"] = ref.split("/")[-1]
|
| 288 |
+
|
| 289 |
+
client.table(target_table).upsert(data).execute()
|
| 290 |
+
count += 1
|
| 291 |
+
|
| 292 |
+
return f"Successfully ingested {count} resources from FHIR Bundle."
|
src/tools/patient_memory.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import uuid
|
| 3 |
+
import datetime
|
| 4 |
+
from supabase import create_client, Client
|
| 5 |
+
from langchain_core.tools import tool
|
| 6 |
+
from src.utils.logger import setup_logger
|
| 7 |
+
|
| 8 |
+
logger = setup_logger("FHIRPatientMemory")
|
| 9 |
+
|
| 10 |
+
def _get_client() -> Client:
|
| 11 |
+
url = os.getenv("SUPABASE_URL")
|
| 12 |
+
key = os.getenv("SUPABASE_KEY")
|
| 13 |
+
return create_client(url, key)
|
| 14 |
+
|
| 15 |
+
@tool
|
| 16 |
+
def save_patient_memory(patient_id: str, glucose_history: str = None, medications: str = None, diet: str = None):
|
| 17 |
+
"""
|
| 18 |
+
Save patient memory (narrative context) as strict FHIR Observation resources.
|
| 19 |
+
"""
|
| 20 |
+
logger.info(f"Saving FHIR narrative memory for patient: {patient_id}")
|
| 21 |
+
client = _get_client()
|
| 22 |
+
|
| 23 |
+
results = []
|
| 24 |
+
|
| 25 |
+
# Map narrative categories to FHIR-like coding
|
| 26 |
+
categories = {
|
| 27 |
+
"glucose_history": {"code": "narrative-glucose", "display": "Glucose History Narrative"},
|
| 28 |
+
"medications": {"code": "narrative-meds", "display": "Medications Narrative"},
|
| 29 |
+
"diet": {"code": "narrative-diet", "display": "Dietary Narrative"}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
for key, value in [("glucose_history", glucose_history), ("medications", medications), ("diet", diet)]:
|
| 33 |
+
if value is not None:
|
| 34 |
+
obs_id = str(uuid.uuid4())
|
| 35 |
+
fhir_obs = {
|
| 36 |
+
"resourceType": "Observation",
|
| 37 |
+
"id": obs_id,
|
| 38 |
+
"status": "final",
|
| 39 |
+
"code": {
|
| 40 |
+
"coding": [{
|
| 41 |
+
"system": "http://dm-chatbot.ai/codes",
|
| 42 |
+
"code": categories[key]["code"],
|
| 43 |
+
"display": categories[key]["display"]
|
| 44 |
+
}]
|
| 45 |
+
},
|
| 46 |
+
"subject": {"reference": f"Patient/{patient_id}"},
|
| 47 |
+
"effectiveDateTime": datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
| 48 |
+
"valueString": value # Using valueString for narrative text
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
data = {
|
| 52 |
+
"id": obs_id,
|
| 53 |
+
"patient_id": patient_id,
|
| 54 |
+
"resource": fhir_obs,
|
| 55 |
+
"last_updated": datetime.datetime.now(datetime.timezone.utc).isoformat()
|
| 56 |
+
}
|
| 57 |
+
client.table("observations").insert(data).execute()
|
| 58 |
+
results.append(key)
|
| 59 |
+
|
| 60 |
+
return f"Successfully saved FHIR narrative memory for: {', '.join(results)}"
|
| 61 |
+
|
| 62 |
+
@tool
|
| 63 |
+
def get_patient_memory(patient_id: str):
|
| 64 |
+
"""
|
| 65 |
+
Retrieve patient narrative memory from FHIR Observation resources.
|
| 66 |
+
"""
|
| 67 |
+
logger.info(f"Retrieving FHIR narrative memory for patient: {patient_id}")
|
| 68 |
+
client = _get_client()
|
| 69 |
+
|
| 70 |
+
try:
|
| 71 |
+
# Fetch observations with narrative codes
|
| 72 |
+
response = client.table("observations").select("resource").eq("patient_id", patient_id).execute()
|
| 73 |
+
observations = [r["resource"] for r in response.data]
|
| 74 |
+
|
| 75 |
+
# Filter for narrative codes
|
| 76 |
+
memory = {}
|
| 77 |
+
codes_map = {
|
| 78 |
+
"narrative-glucose": "Glucose History",
|
| 79 |
+
"narrative-meds": "Medications",
|
| 80 |
+
"narrative-diet": "Diet"
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
for obs in observations:
|
| 84 |
+
for coding in obs.get("code", {}).get("coding", []):
|
| 85 |
+
code = coding.get("code")
|
| 86 |
+
if code in codes_map:
|
| 87 |
+
# Keep only the latest one for each category
|
| 88 |
+
memory[codes_map[code]] = obs.get("valueString", "N/A")
|
| 89 |
+
|
| 90 |
+
if not memory:
|
| 91 |
+
return f"No FHIR narrative memory found for patient {patient_id}."
|
| 92 |
+
|
| 93 |
+
output = f"Patient Narrative Memory (FHIR) for {patient_id}:\n"
|
| 94 |
+
for cat, val in memory.items():
|
| 95 |
+
output += f"- {cat}: {val}\n"
|
| 96 |
+
return output
|
| 97 |
+
|
| 98 |
+
except Exception as e:
|
| 99 |
+
logger.error(f"Error retrieving FHIR memory: {e}")
|
| 100 |
+
return f"Error retrieving FHIR memory: {str(e)}"
|
src/tools/web_tools.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain_community.tools import DuckDuckGoSearchRun
|
| 2 |
+
|
| 3 |
+
def search_web(query: str) -> str:
|
| 4 |
+
"""Useful for searching the web for medical information or nutritional data."""
|
| 5 |
+
search = DuckDuckGoSearchRun()
|
| 6 |
+
return search.run(query)
|
| 7 |
+
|
| 8 |
+
# We can also use it as a standalone tool object
|
| 9 |
+
web_search_tool = DuckDuckGoSearchRun()
|
src/utils/auth.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import jwt
|
| 3 |
+
from fastapi import Request, HTTPException, Depends
|
| 4 |
+
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
| 5 |
+
from src.utils.logger import setup_logger
|
| 6 |
+
|
| 7 |
+
logger = setup_logger("Auth")
|
| 8 |
+
security = HTTPBearer(auto_error=False)
|
| 9 |
+
|
| 10 |
+
DEFAULT_PATIENT_ID = os.getenv("DEFAULT_PATIENT_UUID")
|
| 11 |
+
|
| 12 |
+
def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(security)):
|
| 13 |
+
"""
|
| 14 |
+
Verifies the Supabase JWT and returns the user ID (sub).
|
| 15 |
+
"""
|
| 16 |
+
token = credentials.credentials
|
| 17 |
+
jwt_secret = os.getenv("SUPABASE_JWT_SECRET")
|
| 18 |
+
|
| 19 |
+
if not jwt_secret:
|
| 20 |
+
logger.error("SUPABASE_JWT_SECRET not found in environment")
|
| 21 |
+
raise HTTPException(status_code=500, detail="JWT secret missing")
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
# Supabase uses HS256 for signing JWTs with the project secret
|
| 25 |
+
payload = jwt.decode(token, jwt_secret, algorithms=["HS256"], audience="authenticated")
|
| 26 |
+
user_id = payload.get("sub")
|
| 27 |
+
if not user_id:
|
| 28 |
+
raise HTTPException(status_code=401, detail="Invalid token: missing sub")
|
| 29 |
+
return user_id
|
| 30 |
+
except jwt.ExpiredSignatureError:
|
| 31 |
+
raise HTTPException(status_code=401, detail="Token has expired")
|
| 32 |
+
except jwt.InvalidTokenError as e:
|
| 33 |
+
logger.warning(f"Invalid token: {e}")
|
| 34 |
+
raise HTTPException(status_code=401, detail="Invalid token")
|
| 35 |
+
|
| 36 |
+
def get_active_user(credentials: HTTPAuthorizationCredentials = Depends(security)):
|
| 37 |
+
"""
|
| 38 |
+
Returns the user ID from the token if valid, otherwise returns the DEFAULT_PATIENT_ID.
|
| 39 |
+
"""
|
| 40 |
+
if not credentials:
|
| 41 |
+
return DEFAULT_PATIENT_ID
|
| 42 |
+
|
| 43 |
+
try:
|
| 44 |
+
return get_current_user(credentials)
|
| 45 |
+
except Exception:
|
| 46 |
+
return DEFAULT_PATIENT_ID
|
src/utils/export_prompts.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
# Absolute import management
|
| 5 |
+
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../"))
|
| 6 |
+
if project_root not in sys.path:
|
| 7 |
+
sys.path.append(project_root)
|
| 8 |
+
|
| 9 |
+
from src.agents.agents import (
|
| 10 |
+
RoleClassifier, PatientLLM, ResponseValidator, SafetyCheck,
|
| 11 |
+
IntentClassifier, ClinicalSpecialist, OutputMerger,
|
| 12 |
+
ResearchAgent, DietarySpecialist
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
def export_prompts():
|
| 16 |
+
output_dir = os.path.join(project_root, "src/prompts")
|
| 17 |
+
if not os.path.exists(output_dir):
|
| 18 |
+
os.makedirs(output_dir)
|
| 19 |
+
|
| 20 |
+
# Dictionary of agents and their display names
|
| 21 |
+
agents = {
|
| 22 |
+
"RoleClassifier": RoleClassifier(),
|
| 23 |
+
"PatientLLM": PatientLLM(),
|
| 24 |
+
"ResponseValidator": ResponseValidator(),
|
| 25 |
+
"SafetyCheck": SafetyCheck(),
|
| 26 |
+
"IntentClassifier": IntentClassifier(),
|
| 27 |
+
"ClinicalSpecialist_General": ClinicalSpecialist("General Medicine"),
|
| 28 |
+
"OutputMerger": OutputMerger(),
|
| 29 |
+
"ResearchAgent": ResearchAgent(),
|
| 30 |
+
"DietarySpecialist": DietarySpecialist()
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
for name, agent in agents.items():
|
| 34 |
+
filename = f"{name}.txt"
|
| 35 |
+
filepath = os.path.join(output_dir, filename)
|
| 36 |
+
with open(filepath, "w", encoding="utf-8") as f:
|
| 37 |
+
f.write(agent.system_prompt)
|
| 38 |
+
print(f"Exported system prompt for {name} to {filepath}")
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
export_prompts()
|
src/utils/kb_manager.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import uuid
|
| 4 |
+
import datetime
|
| 5 |
+
from langchain_community.document_loaders import PyPDFLoader
|
| 6 |
+
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 7 |
+
from sentence_transformers import SentenceTransformer
|
| 8 |
+
from supabase import create_client, Client
|
| 9 |
+
from src.utils.logger import setup_logger
|
| 10 |
+
|
| 11 |
+
logger = setup_logger("KBManager")
|
| 12 |
+
|
| 13 |
+
def _get_supabase_client() -> Client:
|
| 14 |
+
url = os.getenv("SUPABASE_URL")
|
| 15 |
+
key = os.getenv("SUPABASE_SERVICE_ROLE_KEY") or os.getenv("SUPABASE_KEY")
|
| 16 |
+
if not url or not key:
|
| 17 |
+
raise ValueError("Supabase configuration missing")
|
| 18 |
+
return create_client(url, key)
|
| 19 |
+
|
| 20 |
+
def create_knowledge_base_supabase(pdf_path: str, collection_name: str = "general"):
|
| 21 |
+
"""
|
| 22 |
+
Creates a new knowledge base in Supabase (pgvector) from a PDF document.
|
| 23 |
+
"""
|
| 24 |
+
if not os.path.exists(pdf_path):
|
| 25 |
+
logger.error(f"Error: File not found at {pdf_path}")
|
| 26 |
+
return
|
| 27 |
+
|
| 28 |
+
logger.info(f"Loading document: {pdf_path}")
|
| 29 |
+
loader = PyPDFLoader(pdf_path)
|
| 30 |
+
docs = loader.load()
|
| 31 |
+
|
| 32 |
+
for doc in docs:
|
| 33 |
+
if 'page' in doc.metadata:
|
| 34 |
+
doc.metadata['page_index'] = doc.metadata['page']
|
| 35 |
+
|
| 36 |
+
logger.info(f"Successfully loaded {len(docs)} pages.")
|
| 37 |
+
|
| 38 |
+
logger.info("Splitting text into chunks...")
|
| 39 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 40 |
+
splits = text_splitter.split_documents(docs)
|
| 41 |
+
logger.info(f"Created {len(splits)} chunks.")
|
| 42 |
+
|
| 43 |
+
# Generate embeddings
|
| 44 |
+
logger.info("Generating embeddings...")
|
| 45 |
+
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 46 |
+
texts = [s.page_content for s in splits]
|
| 47 |
+
embeddings = model.encode(texts).tolist()
|
| 48 |
+
|
| 49 |
+
supabase = _get_supabase_client()
|
| 50 |
+
|
| 51 |
+
# Store in Supabase
|
| 52 |
+
logger.info(f"Storing {len(splits)} chunks in Supabase knowledge_base...")
|
| 53 |
+
supabase_data = []
|
| 54 |
+
for chunk, emb in zip(splits, embeddings):
|
| 55 |
+
supabase_data.append({
|
| 56 |
+
"content": chunk.page_content,
|
| 57 |
+
"metadata": chunk.metadata,
|
| 58 |
+
"embedding": emb,
|
| 59 |
+
"collection_name": collection_name
|
| 60 |
+
})
|
| 61 |
+
|
| 62 |
+
# Bulk insert (limited by payload size, so batching)
|
| 63 |
+
batch_size = 100
|
| 64 |
+
for i in range(0, len(supabase_data), batch_size):
|
| 65 |
+
supabase.table("knowledge_base").insert(supabase_data[i:i+batch_size]).execute()
|
| 66 |
+
|
| 67 |
+
logger.info("Knowledge base integration to Supabase complete.")
|
| 68 |
+
return True
|
| 69 |
+
|
| 70 |
+
if __name__ == "__main__":
|
| 71 |
+
# Example usage for Supabase migration
|
| 72 |
+
sources_dir = "data/sources"
|
| 73 |
+
if os.path.exists(sources_dir):
|
| 74 |
+
for filename in os.listdir(sources_dir):
|
| 75 |
+
if filename.endswith(".pdf"):
|
| 76 |
+
pdf_path = os.path.join(sources_dir, filename)
|
| 77 |
+
create_knowledge_base_supabase(pdf_path, collection_name="diabetes_guidelines")
|
src/utils/logger.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
def setup_logger(name):
|
| 5 |
+
"""
|
| 6 |
+
Sets up a logger with a standard configuration that logs to both the console
|
| 7 |
+
and a file named 'app.log'.
|
| 8 |
+
"""
|
| 9 |
+
logger = logging.getLogger(name)
|
| 10 |
+
|
| 11 |
+
# If logger already has handlers, don't add more (to avoid duplicate logs)
|
| 12 |
+
if not logger.handlers:
|
| 13 |
+
logger.setLevel(logging.INFO)
|
| 14 |
+
|
| 15 |
+
# Create formatters
|
| 16 |
+
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 17 |
+
|
| 18 |
+
# Console Handler
|
| 19 |
+
console_handler = logging.StreamHandler()
|
| 20 |
+
console_handler.setFormatter(formatter)
|
| 21 |
+
logger.addHandler(console_handler)
|
| 22 |
+
|
| 23 |
+
# File Handler
|
| 24 |
+
os.makedirs("logs", exist_ok=True)
|
| 25 |
+
file_handler = logging.FileHandler("logs/app.log", encoding='utf-8')
|
| 26 |
+
file_handler.setFormatter(formatter)
|
| 27 |
+
logger.addHandler(file_handler)
|
| 28 |
+
|
| 29 |
+
return logger
|
src/utils/visualizer.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
|
| 4 |
+
|
| 5 |
+
from src.core.graph import medical_pipeline
|
| 6 |
+
from src.utils.logger import setup_logger
|
| 7 |
+
|
| 8 |
+
logger = setup_logger("Visualizer")
|
| 9 |
+
|
| 10 |
+
def generate_graphviz_dot():
|
| 11 |
+
"""Dynamically reads the medical_pipeline graph and returns a DOT string for Graphviz."""
|
| 12 |
+
try:
|
| 13 |
+
# Get the internal graph structure from LangGraph
|
| 14 |
+
graph = medical_pipeline.get_graph()
|
| 15 |
+
|
| 16 |
+
# Start DOT graph
|
| 17 |
+
dot = ["digraph G {"]
|
| 18 |
+
dot.append(' node [shape=box, style="filled, rounded", fontname="Arial", fillcolor="#f0f2f6", color="#b0b2b6"];')
|
| 19 |
+
dot.append(' edge [fontname="Arial", color="#505256"];')
|
| 20 |
+
dot.append(' rankdir=TB;') # Top to Bottom layout
|
| 21 |
+
|
| 22 |
+
# Add nodes
|
| 23 |
+
for node_id, node in graph.nodes.items():
|
| 24 |
+
label = node_id.replace("_", " ").title()
|
| 25 |
+
# Style specific nodes
|
| 26 |
+
color = "#e1f5fe" if "classifier" in node_id else "#f1f8e9"
|
| 27 |
+
if "validator" in node_id or "safety" in node_id:
|
| 28 |
+
color = "#fff3e0"
|
| 29 |
+
if "tools" in node_id or "search" in node_id:
|
| 30 |
+
color = "#f3e5f5"
|
| 31 |
+
dot.append(f' "{node_id}" [label="{label}", fillcolor="{color}"];')
|
| 32 |
+
|
| 33 |
+
# Add edges
|
| 34 |
+
for edge in graph.edges:
|
| 35 |
+
source = edge.source
|
| 36 |
+
target = edge.target
|
| 37 |
+
label = edge.data if edge.data else ""
|
| 38 |
+
|
| 39 |
+
# Sanitizing labels for DOT
|
| 40 |
+
if label:
|
| 41 |
+
dot.append(f' "{source}" -> "{target}" [label="{label}"];')
|
| 42 |
+
else:
|
| 43 |
+
dot.append(f' "{source}" -> "{target}";')
|
| 44 |
+
|
| 45 |
+
dot.append("}")
|
| 46 |
+
return "\n".join(dot)
|
| 47 |
+
except Exception as e:
|
| 48 |
+
return f'digraph G {{ "Error" [label="Error generating graph: {str(e)}"]; }}'
|
| 49 |
+
|
| 50 |
+
def generate_pipeline_image():
|
| 51 |
+
"""Generates a PNG image of the LangGraph using its internal mermaid renderer."""
|
| 52 |
+
try:
|
| 53 |
+
graph = medical_pipeline.get_graph()
|
| 54 |
+
|
| 55 |
+
# Define visually appealing node colors
|
| 56 |
+
node_colors = {}
|
| 57 |
+
for node_id in graph.nodes:
|
| 58 |
+
node_id_lower = str(node_id).lower()
|
| 59 |
+
if "classifier" in node_id_lower:
|
| 60 |
+
node_colors[node_id] = "#BBDEFB" # Light Blue
|
| 61 |
+
elif "validator" in node_id_lower or "safety" in node_id_lower:
|
| 62 |
+
node_colors[node_id] = "#FFE0B2" # Light Orange
|
| 63 |
+
elif "tools" in node_id_lower or "search" in node_id_lower:
|
| 64 |
+
node_colors[node_id] = "#E1BEE7" # Light Purple
|
| 65 |
+
elif "agent" in node_id_lower or "bot" in node_id_lower:
|
| 66 |
+
node_colors[node_id] = "#C8E6C9" # Light Green
|
| 67 |
+
else:
|
| 68 |
+
node_colors[node_id] = "#F5F5F5" # Light Gray
|
| 69 |
+
|
| 70 |
+
kwargs = {"node_colors": node_colors, "background_color": "#ffffff"}
|
| 71 |
+
|
| 72 |
+
try:
|
| 73 |
+
from langchain_core.runnables.graph import CurveStyle
|
| 74 |
+
kwargs["curve_style"] = CurveStyle.BASIS
|
| 75 |
+
except ImportError:
|
| 76 |
+
pass
|
| 77 |
+
|
| 78 |
+
try:
|
| 79 |
+
# Try with all visual enhancements
|
| 80 |
+
return graph.draw_mermaid_png(**kwargs)
|
| 81 |
+
except TypeError:
|
| 82 |
+
try:
|
| 83 |
+
# Try without background_color if that fails
|
| 84 |
+
kwargs.pop("background_color", None)
|
| 85 |
+
return graph.draw_mermaid_png(**kwargs)
|
| 86 |
+
except TypeError:
|
| 87 |
+
# Ultimate fallback
|
| 88 |
+
return graph.draw_mermaid_png()
|
| 89 |
+
|
| 90 |
+
except Exception as e:
|
| 91 |
+
logger.error(f"Error generating Mermaid image: {e}")
|
| 92 |
+
return None
|
| 93 |
+
|
| 94 |
+
def generate_graph_svg():
|
| 95 |
+
"""Alternative: Generates SVG bytes using Mermaid."""
|
| 96 |
+
try:
|
| 97 |
+
# Many systems prefer SVG for crispness
|
| 98 |
+
return medical_pipeline.get_graph().draw_mermaid_png() # draw_mermaid_png actually returns PNG
|
| 99 |
+
except Exception as e:
|
| 100 |
+
return None
|
| 101 |
+
|
| 102 |
+
if __name__ == "__main__":
|
| 103 |
+
# When run directly, generate and save the image
|
| 104 |
+
image_data = generate_pipeline_image()
|
| 105 |
+
if image_data:
|
| 106 |
+
output_path = "medical_pipeline_graph.png"
|
| 107 |
+
with open(output_path, "wb") as f:
|
| 108 |
+
f.write(image_data)
|
| 109 |
+
|
| 110 |
+
# Create a separate file in the assets directory
|
| 111 |
+
assets_dir = os.path.join(os.path.dirname(__file__), '../../assets')
|
| 112 |
+
os.makedirs(assets_dir, exist_ok=True)
|
| 113 |
+
arch_path = os.path.join(assets_dir, 'assets/architecture.png')
|
| 114 |
+
with open(arch_path, "wb") as f:
|
| 115 |
+
f.write(image_data)
|
| 116 |
+
|
| 117 |
+
logger.info(f"Success! Graph image saved to: {output_path} and {os.path.abspath(arch_path)}")
|
| 118 |
+
else:
|
| 119 |
+
# Fallback to DOT if mermaid fails
|
| 120 |
+
logger.warning("Mermaid failed. Printing DOT source instead.")
|
| 121 |
+
logger.info(generate_graphviz_dot())
|