Spaces:
Sleeping
Sleeping
Update alz_companion/agent.py
Browse files- alz_companion/agent.py +11 -20
alz_companion/agent.py
CHANGED
|
@@ -483,32 +483,21 @@ def route_query_type(query: str, severity: str = "Normal / Unspecified"):
|
|
| 483 |
|
| 484 |
# helper: put near other small utils in agent.py
|
| 485 |
# In agent.py, replace the _source_ids_for_eval function
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
- For jsonl files, it returns the numeric chunk ID or the scene_id if present.
|
| 490 |
-
- For ANY other source, it returns the generic name "Text Input".
|
| 491 |
-
- It excludes the 'placeholder' source.
|
| 492 |
-
"""
|
| 493 |
out, seen = [], set()
|
| 494 |
for d in docs or []:
|
| 495 |
md = getattr(d, "metadata", {}) or {}
|
| 496 |
-
src =
|
| 497 |
|
| 498 |
-
if src == 'placeholder':
|
| 499 |
continue
|
| 500 |
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
if 'scene_id' in md:
|
| 506 |
-
key = str(md['scene_id'])
|
| 507 |
-
# Fallback to numeric chunk ID for other jsonl files
|
| 508 |
-
elif 'chunk' in md and isinstance(md['chunk'], int):
|
| 509 |
-
key = str(md['chunk'])
|
| 510 |
-
else:
|
| 511 |
-
key = "Text Input"
|
| 512 |
|
| 513 |
if key and key not in seen:
|
| 514 |
seen.add(key)
|
|
@@ -517,6 +506,8 @@ def _source_ids_for_eval(docs, cap=5):
|
|
| 517 |
break
|
| 518 |
return out
|
| 519 |
|
|
|
|
|
|
|
| 520 |
|
| 521 |
# In agent.py, replace the ENTIRE make_rag_chain function with this one.
|
| 522 |
# def make_rag_chain(vs_general: FAISS, vs_personal: FAISS, *, for_evaluation: bool = False, role: str = "patient", temperature: float = 0.6, language: str = "English", patient_name: str = "the patient", caregiver_name: str = "the caregiver", tone: str = "warm"):
|
|
|
|
| 483 |
|
| 484 |
# helper: put near other small utils in agent.py
|
| 485 |
# In agent.py, replace the _source_ids_for_eval function
|
| 486 |
+
# In agent.py, inside _source_ids_for_eval(...)
|
| 487 |
+
|
| 488 |
+
def _source_ids_for_eval(docs, cap=3): # NEW change from 5 to 3
|
|
|
|
|
|
|
|
|
|
|
|
|
| 489 |
out, seen = [], set()
|
| 490 |
for d in docs or []:
|
| 491 |
md = getattr(d, "metadata", {}) or {}
|
| 492 |
+
src = md.get("source")
|
| 493 |
|
| 494 |
+
if not src or src == 'placeholder':
|
| 495 |
continue
|
| 496 |
|
| 497 |
+
# --- MODIFICATION START ---
|
| 498 |
+
# Always use the filename as the key, regardless of file type.
|
| 499 |
+
key = src
|
| 500 |
+
# --- MODIFICATION END ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 501 |
|
| 502 |
if key and key not in seen:
|
| 503 |
seen.add(key)
|
|
|
|
| 506 |
break
|
| 507 |
return out
|
| 508 |
|
| 509 |
+
|
| 510 |
+
|
| 511 |
|
| 512 |
# In agent.py, replace the ENTIRE make_rag_chain function with this one.
|
| 513 |
# def make_rag_chain(vs_general: FAISS, vs_personal: FAISS, *, for_evaluation: bool = False, role: str = "patient", temperature: float = 0.6, language: str = "English", patient_name: str = "the patient", caregiver_name: str = "the caregiver", tone: str = "warm"):
|