Spaces:
Sleeping
Sleeping
Update alz_companion/agent.py
Browse files- alz_companion/agent.py +9 -0
alz_companion/agent.py
CHANGED
|
@@ -479,6 +479,9 @@ def make_rag_chain(vs_general: FAISS, vs_personal: FAISS, *, for_evaluation: boo
|
|
| 479 |
# NEW
|
| 480 |
def _answer_fn(query: str, query_type: str, chat_history: List[Dict[str, str]], **kwargs) -> Dict[str, Any]:
|
| 481 |
|
|
|
|
|
|
|
|
|
|
| 482 |
# --- ADD THIS LINE FOR VERIFICATION ---
|
| 483 |
print(f"DEBUG: RAG chain received disease_stage = '{disease_stage}'")
|
| 484 |
# --- END OF ADDITION ---
|
|
@@ -710,20 +713,26 @@ def make_rag_chain(vs_general: FAISS, vs_personal: FAISS, *, for_evaluation: boo
|
|
| 710 |
if disease_stage in ["Moderate Stage", "Advanced Stage"]:
|
| 711 |
# --- STAGE-AWARE LOGIC FOR CAREGIVING SCENARIOS ---
|
| 712 |
if filtered_general_docs:
|
|
|
|
| 713 |
all_retrieved_docs = filtered_general_docs
|
| 714 |
elif filtered_personal_docs:
|
|
|
|
| 715 |
all_retrieved_docs = filtered_personal_docs
|
| 716 |
else:
|
|
|
|
| 717 |
all_retrieved_docs = []
|
| 718 |
# --- END STAGE-AWARE BLOCK ---
|
| 719 |
else:
|
| 720 |
# --- NORMAL ROUTING LOGIC ---
|
| 721 |
# Conditional Blending logic for caregiving remains.
|
| 722 |
if abs(best_personal_score - best_general_score) <= SCORE_MARGIN:
|
|
|
|
| 723 |
all_retrieved_docs = list({doc.page_content: doc for doc in filtered_personal_docs + filtered_general_docs}.values())[:4]
|
| 724 |
elif best_personal_score < best_general_score:
|
|
|
|
| 725 |
all_retrieved_docs = filtered_personal_docs
|
| 726 |
else:
|
|
|
|
| 727 |
all_retrieved_docs = filtered_general_docs
|
| 728 |
|
| 729 |
# --- Prompt Generation and LLM Call ---
|
|
|
|
| 479 |
# NEW
|
| 480 |
def _answer_fn(query: str, query_type: str, chat_history: List[Dict[str, str]], **kwargs) -> Dict[str, Any]:
|
| 481 |
|
| 482 |
+
print(f"[DEBUG] The Query is: {query}")
|
| 483 |
+
print(f"[DEBUG] The Query Type is: {query_type}")
|
| 484 |
+
|
| 485 |
# --- ADD THIS LINE FOR VERIFICATION ---
|
| 486 |
print(f"DEBUG: RAG chain received disease_stage = '{disease_stage}'")
|
| 487 |
# --- END OF ADDITION ---
|
|
|
|
| 713 |
if disease_stage in ["Moderate Stage", "Advanced Stage"]:
|
| 714 |
# --- STAGE-AWARE LOGIC FOR CAREGIVING SCENARIOS ---
|
| 715 |
if filtered_general_docs:
|
| 716 |
+
print("[DEBUG] Stage-Aware Logic: Prioritizing general documents.")
|
| 717 |
all_retrieved_docs = filtered_general_docs
|
| 718 |
elif filtered_personal_docs:
|
| 719 |
+
print("[DEBUG] Stage-Aware Logic: Falling back to personal documents.")
|
| 720 |
all_retrieved_docs = filtered_personal_docs
|
| 721 |
else:
|
| 722 |
+
print("[DEBUG] Stage-Aware Logic: No relevant documents found.")
|
| 723 |
all_retrieved_docs = []
|
| 724 |
# --- END STAGE-AWARE BLOCK ---
|
| 725 |
else:
|
| 726 |
# --- NORMAL ROUTING LOGIC ---
|
| 727 |
# Conditional Blending logic for caregiving remains.
|
| 728 |
if abs(best_personal_score - best_general_score) <= SCORE_MARGIN:
|
| 729 |
+
print("[DEBUG] Normal Logic: Blending personal and general docs (scores are close).")
|
| 730 |
all_retrieved_docs = list({doc.page_content: doc for doc in filtered_personal_docs + filtered_general_docs}.values())[:4]
|
| 731 |
elif best_personal_score < best_general_score:
|
| 732 |
+
print("[DEBUG] Normal Logic: Prioritizing personal docs (better score).")
|
| 733 |
all_retrieved_docs = filtered_personal_docs
|
| 734 |
else:
|
| 735 |
+
print("[DEBUG] Normal Logic: Prioritizing general docs (better score).")
|
| 736 |
all_retrieved_docs = filtered_general_docs
|
| 737 |
|
| 738 |
# --- Prompt Generation and LLM Call ---
|