saad-sust commited on
Commit
fadef5a
Β·
verified Β·
1 Parent(s): c7bc61f

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -3
app.py CHANGED
@@ -637,6 +637,16 @@ def ask_ai_streaming(problem: str, sympy_info: dict, history: list) -> str:
637
  return full_response
638
 
639
 
 
 
 
 
 
 
 
 
 
 
640
  # ════════════════════════════════════════════════════════════════════
641
  # SIDEBAR
642
  # ════════════════════════════════════════════════════════════════════
@@ -644,6 +654,12 @@ with st.sidebar:
644
  st.markdown("### 🧠 Saad.AI")
645
  st.caption("B.Sc. Mathematics Engine")
646
  st.markdown("Deterministic calculations with AI-powered explanations.")
 
 
 
 
 
 
647
  st.divider()
648
 
649
  # ── New Chat Button ──────────────────────────────────────────
@@ -908,8 +924,10 @@ for i, msg in enumerate(st.session_state.messages):
908
  with st.chat_message(msg["role"], avatar=avatar):
909
  st.markdown(msg["content"])
910
  if msg["role"] == "assistant":
911
- if msg.get("verified"):
912
- st.caption("βœ“ SymPy verified computation")
 
 
913
  else:
914
  st.caption("AI-generated explanation β€” deterministic verification was unavailable for this request.")
915
  with st.expander("Solution tools"):
@@ -1181,7 +1199,10 @@ if problem and problem != st.session_state.last_submitted:
1181
  if is_casual:
1182
  st.caption("AI response")
1183
  elif sympy_result.get("result") and sympy_result.get("result") not in ("matrix_detected", "mod_detected"):
1184
- st.caption("βœ“ SymPy verified computation")
 
 
 
1185
  else:
1186
  st.caption("AI-generated explanation β€” deterministic verification was unavailable for this request.")
1187
 
 
637
  return full_response
638
 
639
 
640
+ def _has_ai_explanation(answer: str) -> bool:
641
+ """Return False for deterministic-only or explicit provider-failure responses."""
642
+ normalized = (answer or "").lstrip()
643
+ return bool(normalized) and not normalized.startswith((
644
+ "βœ… **SymPy Verified**",
645
+ "⚠️ **AI explanation unavailable",
646
+ "⚠️ **No AI provider",
647
+ ))
648
+
649
+
650
  # ════════════════════════════════════════════════════════════════════
651
  # SIDEBAR
652
  # ════════════════════════════════════════════════════════════════════
 
654
  st.markdown("### 🧠 Saad.AI")
655
  st.caption("B.Sc. Mathematics Engine")
656
  st.markdown("Deterministic calculations with AI-powered explanations.")
657
+ if settings.any_text_provider_enabled:
658
+ st.success("AI explanations enabled")
659
+ st.caption("Providers explain the verified SymPy result step by step.")
660
+ else:
661
+ st.info("SymPy-only mode")
662
+ st.caption("Deterministic calculations work; add a provider secret for AI explanations.")
663
  st.divider()
664
 
665
  # ── New Chat Button ──────────────────────────────────────────
 
924
  with st.chat_message(msg["role"], avatar=avatar):
925
  st.markdown(msg["content"])
926
  if msg["role"] == "assistant":
927
+ if msg.get("verified") and _has_ai_explanation(msg["content"]):
928
+ st.caption("βœ“ AI explanation Β· SymPy verified computation")
929
+ elif msg.get("verified"):
930
+ st.caption("βœ“ SymPy verified Β· AI explanation unavailable for this response")
931
  else:
932
  st.caption("AI-generated explanation β€” deterministic verification was unavailable for this request.")
933
  with st.expander("Solution tools"):
 
1199
  if is_casual:
1200
  st.caption("AI response")
1201
  elif sympy_result.get("result") and sympy_result.get("result") not in ("matrix_detected", "mod_detected"):
1202
+ if _has_ai_explanation(answer):
1203
+ st.caption("βœ“ AI explanation Β· SymPy verified computation")
1204
+ else:
1205
+ st.caption("βœ“ SymPy verified Β· AI explanation unavailable for this response")
1206
  else:
1207
  st.caption("AI-generated explanation β€” deterministic verification was unavailable for this request.")
1208