Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion GnosisPages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion gnosis/search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Search Tool"""


class Search:
"""Search Tool"""

Expand All @@ -10,7 +9,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)

Expand Down
Loading