Update src/streamlit_app.py
Browse files- src/streamlit_app.py +9 -2
src/streamlit_app.py
CHANGED
|
@@ -177,9 +177,16 @@ def handle_send():
|
|
| 177 |
# - any(kw in rag_answer.lower() for kw in fallback_keywords): checks if any "bad" keyword appears
|
| 178 |
# - len(rag_answer.strip()) < 50: checks if the dataset-based answer is too short (likely low quality)
|
| 179 |
# - not (...): inverts the condition — we show dataset answer only if it’s *good enough*
|
| 180 |
-
fallback_keywords = [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
rag_too_short = len(rag_answer.strip()) < 50
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
if rag_weak or rag_too_short:
|
| 185 |
# Step 3: Fallback to general reasoning ONLY if RAG is weak
|
|
|
|
| 177 |
# - any(kw in rag_answer.lower() for kw in fallback_keywords): checks if any "bad" keyword appears
|
| 178 |
# - len(rag_answer.strip()) < 50: checks if the dataset-based answer is too short (likely low quality)
|
| 179 |
# - not (...): inverts the condition — we show dataset answer only if it’s *good enough*
|
| 180 |
+
fallback_keywords = [
|
| 181 |
+
"cannot answer", "no information", "based on the context", "i'm sorry",
|
| 182 |
+
"not a mental health question", "cannot provide", "not relevant",
|
| 183 |
+
"no relevant", "not a question"
|
| 184 |
+
]
|
| 185 |
rag_too_short = len(rag_answer.strip()) < 50
|
| 186 |
+
rag_irrelevant = any(kw in rag_answer.lower() for kw in fallback_keywords)
|
| 187 |
+
rag_generic = rag_answer.lower().startswith(("the provided context", "context does not"))
|
| 188 |
+
rag_weak = rag_too_short or rag_irrelevant or rag_generic
|
| 189 |
+
|
| 190 |
|
| 191 |
if rag_weak or rag_too_short:
|
| 192 |
# Step 3: Fallback to general reasoning ONLY if RAG is weak
|