From 1500cdd206389a6c7a31c5dc24943bfbea625435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2EP=2E=20P=C3=A9rez=20Tejada?= Date: Sun, 14 Jun 2026 02:50:53 -0600 Subject: [PATCH 1/2] Handle error messages using ChromaDB --- GnosisPages.py | 4 +++- gnosis/search.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/GnosisPages.py b/GnosisPages.py index dd1ce54..06e8eed 100644 --- a/GnosisPages.py +++ b/GnosisPages.py @@ -24,9 +24,11 @@ if "wk_button" not in st.session_state: st.session_state.wk_button = False +if "chroma_db" not in st.session_state: + st.session_state.chroma_db = ChromaDB(openai.api_key) # Build settings -chroma_db = ChromaDB(openai.api_key) +chroma_db = st.session_state.chroma_db collection = settings.build(chroma_db) # Sidebar diff --git a/gnosis/search.py b/gnosis/search.py index 5eb10b0..c74c431 100644 --- a/gnosis/search.py +++ b/gnosis/search.py @@ -1,4 +1,5 @@ """Search Tool""" +import streamlit as st class Search: @@ -10,7 +11,18 @@ def __init__(self, chroma_db): def run(self, query: str): """Run the Agent""" + if not self.chroma_db.api_key: + return "No API key set. Please add your OpenAI API key in the sidebar." + collection = self.chroma_db.get_collection("pdf-explainer") + + # get_collection returns a Streamlit object if something went wrong + if not hasattr(collection, "query"): + return "Could not access the collection. Please check your API key." + + if collection.count() == 0: + return "No documents found. Please upload a PDF first." + results = collection.query(query_texts=[query], n_results=5)["documents"][0] return "\n\n---\n\n".join(results) From 82b23b89dd23a4edf4b4792464bbeb9f19d6f46a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Paulo=20P=C3=A9rez-Tejada?= Date: Sun, 14 Jun 2026 02:57:10 -0600 Subject: [PATCH 2/2] Remove unused Streamlit import from search.py Removed unused import of Streamlit. --- gnosis/search.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/gnosis/search.py b/gnosis/search.py index c74c431..8a1f344 100644 --- a/gnosis/search.py +++ b/gnosis/search.py @@ -1,6 +1,4 @@ """Search Tool""" -import streamlit as st - class Search: """Search Tool"""