Skip to content

Commit

Permalink
fix: Error cuased by container
Browse files Browse the repository at this point in the history
  • Loading branch information
Maclenn77 committed Dec 10, 2023
1 parent 094cc8d commit c24f4cd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 28 deletions.
19 changes: 9 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def click_wk_button():

# Build settings
chroma_db = ChromaDB(openai.api_key)
openai_client, collection = settings.build(chroma_db)
collection = settings.build(chroma_db)

# Sidebar
with st.sidebar:
Expand Down Expand Up @@ -84,11 +84,11 @@ def click_wk_button():
st.subheader("Create your knowledge base")

## Uploader
container = st.container()
container.write(

st.write(
"Upload, extract and consult the content of PDF Files for builiding your knowledge base!"
)
pdf = container.file_uploader("Upload a file", type="pdf")
pdf = st.file_uploader("Upload a file", type="pdf")

if pdf is not None:
with fitz.open(stream=pdf.read(), filetype="pdf") as doc: # open document
Expand All @@ -108,13 +108,12 @@ def click_wk_button():
ids=[pdf.name + str(idx)],
)
else:
container.write("Please upload a file of type: pdf")
st.write("Please upload a file of type: pdf")

st.subheader("Consult your knowledge base")

chatbox = st.container()

prompt = chatbox.chat_input()
prompt = st.chat_input()

if prompt:
# Create Agent
Expand All @@ -133,8 +132,8 @@ def click_wk_button():
except Exception: # pylint: disable=broad-exception-caught
st.warning("Missing OpenAI API Key.")

chatbox.chat_message("user").write(prompt)
with chatbox.chat_message("assistant"):
st.chat_message("user").write(prompt)
with st.chat_message("assistant"):
st_callback = StreamlitCallbackHandler(st.container())
response = agent.run(prompt, callbacks=[st_callback])
chatbox.write(response)
st.write(response)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ tiktoken
langchain
pymupdf
pypdf
duckduckgo-search
wikipedia
chromadb>='0.4.18'
sentence_transformers
streamlit
2 changes: 1 addition & 1 deletion src/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, llm, chroma_db, extra_tools=False):
self.tools = [
Tool.from_function(
func=search.run,
name="Search DB",
name="Search on ChromaDB",
description="Useful when you need more context for answering a question.",
handle_parsing_errors=True,
)
Expand Down
13 changes: 0 additions & 13 deletions src/openai_client.py

This file was deleted.

4 changes: 1 addition & 3 deletions src/settings.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""Build settings for the app."""
from src.openai_client import create_client


def build(chroma_db):
"""Build the app."""
openai_client = create_client(chroma_db.api_key)
collection = chroma_db.create_collection("pdf-explainer")

return openai_client, collection
return collection

0 comments on commit c24f4cd

Please sign in to comment.