Update app.py
Browse files
app.py
CHANGED
|
@@ -42,12 +42,10 @@ def query_index(index, similarity_top_k=3, streaming=True):
|
|
| 42 |
Given this context, please respond to the following user query:
|
| 43 |
{query_str}
|
| 44 |
Your response should:
|
| 45 |
-
|
| 46 |
Directly address the query using information from the context
|
| 47 |
Include relevant code examples or direct quotes if applicable
|
| 48 |
Mention specific sections or pages of the documentation
|
| 49 |
Highlight any best practices or potential pitfalls related to the query
|
| 50 |
-
|
| 51 |
After your response, suggest 3 follow-up questions based on the context that the user might find helpful for deeper understanding.
|
| 52 |
Your response:"""
|
| 53 |
),
|
|
@@ -66,6 +64,16 @@ def ingest_documents(url):
|
|
| 66 |
# Streamlit app
|
| 67 |
st.title("Talk to Software Documentation")
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
# Initialize session state
|
| 70 |
if 'chat_engine' not in st.session_state:
|
| 71 |
st.session_state['chat_engine'] = None
|
|
@@ -76,32 +84,23 @@ if 'chat_history' not in st.session_state:
|
|
| 76 |
if 'last_response' not in st.session_state:
|
| 77 |
st.session_state['last_response'] = None
|
| 78 |
|
| 79 |
-
|
| 80 |
# URL input for document ingestion
|
| 81 |
url = st.text_input("Enter URL to crawl and ingest documents:")
|
| 82 |
|
| 83 |
-
# Ingest
|
| 84 |
-
if st.button("Ingest
|
| 85 |
if url:
|
| 86 |
-
with st.spinner("Crawling and
|
| 87 |
st.session_state['documents'] = ingest_documents(url)
|
| 88 |
-
st.success(f"Documents ingested from {url}")
|
| 89 |
-
else:
|
| 90 |
-
st.error("Please enter a URL")
|
| 91 |
-
|
| 92 |
-
# Setup button
|
| 93 |
-
if st.button("Setup Query Engine"):
|
| 94 |
-
if st.session_state['documents'] is None:
|
| 95 |
-
st.error("Please ingest documents first")
|
| 96 |
-
else:
|
| 97 |
-
with st.spinner("Setting up query engine..."):
|
| 98 |
embed_setup()
|
| 99 |
client = qdrant_setup()
|
| 100 |
llm = llm_setup()
|
| 101 |
vector_store = QdrantVectorStore(client=client, collection_name=os.getenv("COLLECTION_NAME"))
|
| 102 |
index = VectorStoreIndex.from_documents(st.session_state['documents'], vector_store=vector_store)
|
| 103 |
st.session_state['chat_engine'] = query_index(index)
|
| 104 |
-
st.success("
|
|
|
|
|
|
|
| 105 |
|
| 106 |
# Query input
|
| 107 |
query = st.text_input("Enter your query:")
|
|
@@ -124,12 +123,12 @@ if st.button("Search"):
|
|
| 124 |
else:
|
| 125 |
st.error("Please enter a query")
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
|
| 132 |
-
# Clear chat history button
|
| 133 |
-
if st.button("Clear Chat History"):
|
| 134 |
st.session_state['chat_history'] = []
|
| 135 |
-
st.success("Chat history cleared!")
|
|
|
|
| 42 |
Given this context, please respond to the following user query:
|
| 43 |
{query_str}
|
| 44 |
Your response should:
|
|
|
|
| 45 |
Directly address the query using information from the context
|
| 46 |
Include relevant code examples or direct quotes if applicable
|
| 47 |
Mention specific sections or pages of the documentation
|
| 48 |
Highlight any best practices or potential pitfalls related to the query
|
|
|
|
| 49 |
After your response, suggest 3 follow-up questions based on the context that the user might find helpful for deeper understanding.
|
| 50 |
Your response:"""
|
| 51 |
),
|
|
|
|
| 64 |
# Streamlit app
|
| 65 |
st.title("Talk to Software Documentation")
|
| 66 |
|
| 67 |
+
st.markdown("""
|
| 68 |
+
This tool allows you to chat with software documentation. Here's how to use it:
|
| 69 |
+
|
| 70 |
+
1. Enter the URL of the documentation you want to chat about.
|
| 71 |
+
2. Click the "Ingest and Setup" button to crawl the documentation and set up the query engine.
|
| 72 |
+
3. Once setup is complete, enter your query in the text box.
|
| 73 |
+
4. Click "Search" to get a response based on the documentation.
|
| 74 |
+
5. View your chat history in the sidebar.
|
| 75 |
+
""")
|
| 76 |
+
|
| 77 |
# Initialize session state
|
| 78 |
if 'chat_engine' not in st.session_state:
|
| 79 |
st.session_state['chat_engine'] = None
|
|
|
|
| 84 |
if 'last_response' not in st.session_state:
|
| 85 |
st.session_state['last_response'] = None
|
| 86 |
|
|
|
|
| 87 |
# URL input for document ingestion
|
| 88 |
url = st.text_input("Enter URL to crawl and ingest documents:")
|
| 89 |
|
| 90 |
+
# Combined Ingest and Setup button
|
| 91 |
+
if st.button("Ingest and Setup"):
|
| 92 |
if url:
|
| 93 |
+
with st.spinner("Crawling, ingesting documents, and setting up query engine..."):
|
| 94 |
st.session_state['documents'] = ingest_documents(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
embed_setup()
|
| 96 |
client = qdrant_setup()
|
| 97 |
llm = llm_setup()
|
| 98 |
vector_store = QdrantVectorStore(client=client, collection_name=os.getenv("COLLECTION_NAME"))
|
| 99 |
index = VectorStoreIndex.from_documents(st.session_state['documents'], vector_store=vector_store)
|
| 100 |
st.session_state['chat_engine'] = query_index(index)
|
| 101 |
+
st.success(f"Documents ingested from {url} and query engine setup completed successfully!")
|
| 102 |
+
else:
|
| 103 |
+
st.error("Please enter a URL")
|
| 104 |
|
| 105 |
# Query input
|
| 106 |
query = st.text_input("Enter your query:")
|
|
|
|
| 123 |
else:
|
| 124 |
st.error("Please enter a query")
|
| 125 |
|
| 126 |
+
# Sidebar for chat history
|
| 127 |
+
st.sidebar.title("Chat History")
|
| 128 |
+
for role, message in st.session_state['chat_history']:
|
| 129 |
+
st.sidebar.text(f"{role}: {message}")
|
| 130 |
|
| 131 |
+
# Clear chat history button in sidebar
|
| 132 |
+
if st.sidebar.button("Clear Chat History"):
|
| 133 |
st.session_state['chat_history'] = []
|
| 134 |
+
st.sidebar.success("Chat history cleared!")
|