Update app.py
Browse files
app.py
CHANGED
|
@@ -87,26 +87,51 @@ with st.container():
|
|
| 87 |
st.metric("Average Response Time (s)", f"{metrics.avg_response_time():.2f}")
|
| 88 |
|
| 89 |
if user_query:
|
| 90 |
-
print(f"
|
| 91 |
start_time = time.time()
|
| 92 |
st.session_state.chat_history.append({"user": user_query})
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
# Clear button
|
| 112 |
if st.button("Clear Chat History"):
|
|
|
|
| 87 |
st.metric("Average Response Time (s)", f"{metrics.avg_response_time():.2f}")
|
| 88 |
|
| 89 |
if user_query:
|
| 90 |
+
print(f"[QUERY] {user_query}")
|
| 91 |
start_time = time.time()
|
| 92 |
st.session_state.chat_history.append({"user": user_query})
|
| 93 |
|
| 94 |
+
try:
|
| 95 |
+
response, tool_used = run_tool(
|
| 96 |
+
user_query,
|
| 97 |
+
model=selected_model,
|
| 98 |
+
use_rag=rag_toggle
|
| 99 |
+
)
|
| 100 |
+
routed_correctly = True
|
| 101 |
+
except Exception as e:
|
| 102 |
+
response = f"Error handling query: {str(e)}"
|
| 103 |
+
tool_used = "ERROR"
|
| 104 |
+
routed_correctly = False
|
| 105 |
+
|
| 106 |
+
end_time = time.time()
|
| 107 |
+
response_time = end_time - start_time
|
| 108 |
+
|
| 109 |
+
# ✅ RECORD METRICS HERE (THIS IS THE CORRECT LOCATION)
|
| 110 |
+
st.session_state.metrics.record_query(
|
| 111 |
+
query=user_query,
|
| 112 |
+
model=selected_model,
|
| 113 |
+
use_rag=rag_toggle,
|
| 114 |
+
tool_name=tool_used,
|
| 115 |
+
routed_correctly=routed_correctly,
|
| 116 |
+
response_time=response_time
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
# Optional: print structured routing log
|
| 120 |
+
print(
|
| 121 |
+
f"""
|
| 122 |
+
=== ROUTING EVENT ===
|
| 123 |
+
Query: {user_query}
|
| 124 |
+
Model: {selected_model}
|
| 125 |
+
RAG Enabled: {rag_toggle}
|
| 126 |
+
Tool Used: {tool_used}
|
| 127 |
+
Response Time: {response_time:.2f}s
|
| 128 |
+
Status: {'SUCCESS' if routed_correctly else 'FAILED'}
|
| 129 |
+
====================
|
| 130 |
+
"""
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
st.session_state.chat_history[-1]["response"] = response
|
| 134 |
+
st.rerun()
|
| 135 |
|
| 136 |
# Clear button
|
| 137 |
if st.button("Clear Chat History"):
|