fix(settings): improve suggest feedback for empty/failed LLM results

- Catch all exceptions (not just RuntimeError) so FileNotFoundError,
  connection errors, etc. surface as error messages rather than crashing
  the page silently
- Show "No new suggestions found" info message when the LLM returns
  empty arrays — previously the spinner completed with no UI feedback
- Hint to upload resume when RESUME_PATH is missing (new users)
- Only rerun() when there are actual results to display
This commit is contained in:
pyr0ball 2026-04-01 07:17:21 -07:00
parent 98754cbe43
commit 2959abb3da

View file

@ -401,21 +401,31 @@ with tab_search:
with st.spinner("Asking LLM for suggestions…"): with st.spinner("Asking LLM for suggestions…"):
try: try:
suggestions = _suggest_search_terms(_current_titles, RESUME_PATH, _blocklist, _user_profile) suggestions = _suggest_search_terms(_current_titles, RESUME_PATH, _blocklist, _user_profile)
except RuntimeError as _e: except Exception as _e:
_err_msg = str(_e)
if "exhausted" in _err_msg.lower() or isinstance(_e, RuntimeError):
st.warning( st.warning(
f"No LLM backend available: {_e}. " f"No LLM backend available: {_err_msg}. "
"Check that Ollama is running and has GPU access, or enable a cloud backend in Settings → System → LLM.", "Check that Ollama is running and has GPU access, or enable a cloud backend in Settings → System → LLM.",
icon="⚠️", icon="⚠️",
) )
else:
st.error(f"Suggestion failed: {_err_msg}", icon="🚨")
suggestions = None suggestions = None
if suggestions is not None: if suggestions is not None:
# Add suggested titles to options list (not auto-selected — user picks from dropdown) # Add suggested titles to options list (not auto-selected — user picks from dropdown)
_opts = list(st.session_state.get("_sp_title_options", [])) _opts = list(st.session_state.get("_sp_title_options", []))
for _t in suggestions.get("suggested_titles", []): _new_titles = [_t for _t in suggestions.get("suggested_titles", []) if _t not in _opts]
if _t not in _opts: _opts.extend(_new_titles)
_opts.append(_t)
st.session_state["_sp_title_options"] = _opts st.session_state["_sp_title_options"] = _opts
st.session_state["_sp_suggestions"] = suggestions st.session_state["_sp_suggestions"] = suggestions
if not _new_titles and not suggestions.get("suggested_excludes"):
_resume_hint = " Upload your resume in Settings → Resume Profile for better results." if not RESUME_PATH.exists() else ""
st.info(
f"No new suggestions found — the LLM didn't generate anything new for these titles.{_resume_hint}",
icon="",
)
else:
st.rerun() st.rerun()
if st.session_state.get("_sp_suggestions"): if st.session_state.get("_sp_suggestions"):