Spaces:
Sleeping
Sleeping
No info found warning
Browse files
app.py
CHANGED
|
@@ -179,6 +179,31 @@ async def chat(query, history, sources, reports, subtype, year, client_ip=None,
|
|
| 179 |
|
| 180 |
context_retrieved = get_context(vectorstore=vectorstore,query=query,reports=reports,
|
| 181 |
sources=sources,subtype=subtype,year=year)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
context_retrieved_formatted = "||".join(doc.page_content for doc in context_retrieved)
|
| 183 |
context_retrieved_lst = [doc.page_content for doc in context_retrieved]
|
| 184 |
|
|
|
|
| 179 |
|
| 180 |
context_retrieved = get_context(vectorstore=vectorstore,query=query,reports=reports,
|
| 181 |
sources=sources,subtype=subtype,year=year)
|
| 182 |
+
|
| 183 |
+
# Check if any paragraphs were retrieved - add warning if none found
|
| 184 |
+
if not context_retrieved or len(context_retrieved) == 0:
|
| 185 |
+
warning_message = "⚠️ **No relevant information was found in the audit reports pertaining your query.** Please try rephrasing your question or selecting different report filters."
|
| 186 |
+
history[-1] = (query, warning_message)
|
| 187 |
+
# Update logs with the warning instead of answer
|
| 188 |
+
logs_data = {
|
| 189 |
+
"record_id": str(uuid4()),
|
| 190 |
+
"session_id": session_id,
|
| 191 |
+
"session_duration_seconds": session_duration,
|
| 192 |
+
"client_location": session_data['location_info'],
|
| 193 |
+
"platform": session_data['platform_info'],
|
| 194 |
+
"year": year,
|
| 195 |
+
"question": query,
|
| 196 |
+
"retriever": model_config.get('retriever','MODEL'),
|
| 197 |
+
"endpoint_type": model_config.get('reader','TYPE'),
|
| 198 |
+
"reader": model_config.get('reader','NVIDIA_MODEL'),
|
| 199 |
+
"answer": warning_message,
|
| 200 |
+
"no_results": True # Flag to indicate no results were found
|
| 201 |
+
}
|
| 202 |
+
yield [tuple(x) for x in history], "", logs_data, session_id
|
| 203 |
+
# Save log for the warning response
|
| 204 |
+
save_logs(scheduler, JSON_DATASET_PATH, logs_data)
|
| 205 |
+
return
|
| 206 |
+
|
| 207 |
context_retrieved_formatted = "||".join(doc.page_content for doc in context_retrieved)
|
| 208 |
context_retrieved_lst = [doc.page_content for doc in context_retrieved]
|
| 209 |
|