Spaces:
Sleeping
Sleeping
Ara Yeroyan
commited on
Commit
Β·
6f5999e
1
Parent(s):
3fc1b5f
add gemini traceability
Browse files
app.py
CHANGED
|
@@ -491,6 +491,36 @@ def main():
|
|
| 491 |
if rag_result:
|
| 492 |
sources = rag_result.get('sources', []) if isinstance(rag_result, dict) else (rag_result.sources if hasattr(rag_result, 'sources') else [])
|
| 493 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 494 |
# Get the actual RAG query
|
| 495 |
actual_rag_query = chat_result.get('actual_rag_query', '')
|
| 496 |
if actual_rag_query:
|
|
@@ -516,6 +546,9 @@ def main():
|
|
| 516 |
"timestamp": time.time()
|
| 517 |
}
|
| 518 |
st.session_state.rag_retrieval_history.append(retrieval_entry)
|
|
|
|
|
|
|
|
|
|
| 519 |
else:
|
| 520 |
response = chat_result
|
| 521 |
st.session_state.last_rag_result = None
|
|
@@ -545,6 +578,16 @@ def main():
|
|
| 545 |
# Dictionary format from multi-agent system
|
| 546 |
sources = rag_result['sources']
|
| 547 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
if sources and len(sources) > 0:
|
| 549 |
# Count unique filenames
|
| 550 |
unique_filenames = set()
|
|
@@ -772,7 +815,11 @@ def main():
|
|
| 772 |
logger.info("π€ SNOWFLAKE UI: Attempting to save feedback to Snowflake...")
|
| 773 |
print("π€ SNOWFLAKE UI: Attempting to save feedback to Snowflake...")
|
| 774 |
|
| 775 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 776 |
if snowflake_success:
|
| 777 |
logger.info("β
SNOWFLAKE UI: Successfully saved to Snowflake")
|
| 778 |
print("β
SNOWFLAKE UI: Successfully saved to Snowflake")
|
|
|
|
| 491 |
if rag_result:
|
| 492 |
sources = rag_result.get('sources', []) if isinstance(rag_result, dict) else (rag_result.sources if hasattr(rag_result, 'sources') else [])
|
| 493 |
|
| 494 |
+
# For Gemini, also check gemini_result for sources
|
| 495 |
+
if not sources or len(sources) == 0:
|
| 496 |
+
gemini_result = chat_result.get('gemini_result')
|
| 497 |
+
print(f"π DEBUG: Checking gemini_result for sources...")
|
| 498 |
+
print(f" gemini_result exists: {gemini_result is not None}")
|
| 499 |
+
if gemini_result:
|
| 500 |
+
print(f" gemini_result type: {type(gemini_result)}")
|
| 501 |
+
print(f" has sources attr: {hasattr(gemini_result, 'sources')}")
|
| 502 |
+
if hasattr(gemini_result, 'sources'):
|
| 503 |
+
print(f" sources length: {len(gemini_result.sources) if gemini_result.sources else 0}")
|
| 504 |
+
|
| 505 |
+
if gemini_result and hasattr(gemini_result, 'sources'):
|
| 506 |
+
# Format Gemini sources for display
|
| 507 |
+
if hasattr(st.session_state.chatbot, 'gemini_client'):
|
| 508 |
+
sources = st.session_state.chatbot.gemini_client.format_sources_for_display(gemini_result)
|
| 509 |
+
print(f"β
Formatted {len(sources)} sources from gemini_client")
|
| 510 |
+
elif hasattr(st.session_state.chatbot, '_format_gemini_sources'):
|
| 511 |
+
sources = st.session_state.chatbot._format_gemini_sources(gemini_result)
|
| 512 |
+
print(f"β
Formatted {len(sources)} sources from _format_gemini_sources")
|
| 513 |
+
|
| 514 |
+
# Update rag_result with sources if we found them
|
| 515 |
+
if sources and len(sources) > 0:
|
| 516 |
+
if isinstance(rag_result, dict):
|
| 517 |
+
rag_result['sources'] = sources
|
| 518 |
+
elif hasattr(rag_result, 'sources'):
|
| 519 |
+
rag_result.sources = sources
|
| 520 |
+
# Update last_rag_result with sources
|
| 521 |
+
st.session_state.last_rag_result = rag_result
|
| 522 |
+
print(f"β
Updated rag_result with {len(sources)} sources")
|
| 523 |
+
|
| 524 |
# Get the actual RAG query
|
| 525 |
actual_rag_query = chat_result.get('actual_rag_query', '')
|
| 526 |
if actual_rag_query:
|
|
|
|
| 546 |
"timestamp": time.time()
|
| 547 |
}
|
| 548 |
st.session_state.rag_retrieval_history.append(retrieval_entry)
|
| 549 |
+
|
| 550 |
+
# Debug logging
|
| 551 |
+
print(f"π RETRIEVAL TRACKING: {len(sources)} sources stored in retrieval history")
|
| 552 |
else:
|
| 553 |
response = chat_result
|
| 554 |
st.session_state.last_rag_result = None
|
|
|
|
| 578 |
# Dictionary format from multi-agent system
|
| 579 |
sources = rag_result['sources']
|
| 580 |
|
| 581 |
+
# For Gemini, also check if we need to format sources from gemini_result
|
| 582 |
+
if (not sources or len(sources) == 0) and isinstance(rag_result, dict):
|
| 583 |
+
gemini_result = rag_result.get('gemini_result')
|
| 584 |
+
if gemini_result and hasattr(gemini_result, 'sources'):
|
| 585 |
+
# Format Gemini sources for display
|
| 586 |
+
if hasattr(st.session_state.chatbot, 'gemini_client'):
|
| 587 |
+
sources = st.session_state.chatbot.gemini_client.format_sources_for_display(gemini_result)
|
| 588 |
+
elif hasattr(st.session_state.chatbot, '_format_gemini_sources'):
|
| 589 |
+
sources = st.session_state.chatbot._format_gemini_sources(gemini_result)
|
| 590 |
+
|
| 591 |
if sources and len(sources) > 0:
|
| 592 |
# Count unique filenames
|
| 593 |
unique_filenames = set()
|
|
|
|
| 815 |
logger.info("π€ SNOWFLAKE UI: Attempting to save feedback to Snowflake...")
|
| 816 |
print("π€ SNOWFLAKE UI: Attempting to save feedback to Snowflake...")
|
| 817 |
|
| 818 |
+
# Show spinner while saving to Snowflake (can take 10-15 seconds)
|
| 819 |
+
# This includes: connection establishment (~5s), data preparation, and SQL execution (~5s)
|
| 820 |
+
with st.spinner("πΎ Saving feedback to Snowflake... This may take 10-15 seconds (connecting to database, preparing data, and executing query)"):
|
| 821 |
+
snowflake_success = feedback_manager.save_to_snowflake(feedback_obj)
|
| 822 |
+
|
| 823 |
if snowflake_success:
|
| 824 |
logger.info("β
SNOWFLAKE UI: Successfully saved to Snowflake")
|
| 825 |
print("β
SNOWFLAKE UI: Successfully saved to Snowflake")
|