Skip to content

Commit

Permalink
chore: autopublish 2024-04-20T11:31:42Z
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Apr 20, 2024
1 parent fec9e75 commit ff3e0c7
Showing 1 changed file with 46 additions and 26 deletions.
72 changes: 46 additions & 26 deletions streamlit_app/app_utils/rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,33 @@ def initialize_rag_query_tab(
similar_docs = []

if not similar_docs:
st.error("❌ User has chosen not to provide documents from the knowledge base!")
st.error(
"❌ User has chosen not to provide documents from the knowledge base!"
)
else:
with st.expander(
"Used **:green[Relevent Documents]** in Context", expanded=False
"Used **:green[Relevent Documents]** in Context",
expanded=False,
):
for doc in similar_docs:
st.info(doc)

# Prepare context-enhanced prompt
with st.spinner("Preparing context-enhanced prompt..."):
if len(similar_docs) == 0:
similar_docs = ['No documents found related to user query! Use your external knowledge or search the internet if possible']
context_enhanced_prompt, expertise_area_cost, identified_expertise_area = (
query_pipeline.determine_expertise_and_prepare_prompt(
user_query=user_query,
similar_docs=similar_docs,
inference_model=selected_llm_name,
max_completion_tokens=selected_llm_tokens_limit,
temperature=selected_llm_temp,
)
similar_docs = [
"No documents found related to user query! Use your external knowledge or search the internet if possible"
]
(
context_enhanced_prompt,
expertise_area_cost,
identified_expertise_area,
) = query_pipeline.determine_expertise_and_prepare_prompt(
user_query=user_query,
similar_docs=similar_docs,
inference_model=selected_llm_name,
max_completion_tokens=selected_llm_tokens_limit,
temperature=selected_llm_temp,
)
with st.expander("RAG Prompt", expanded=True):
st.info(
Expand All @@ -83,7 +90,9 @@ def initialize_rag_query_tab(
)

# Display message
st.chat_message("assistant").write_stream(stream_response(contextual_response))
st.chat_message("assistant").write_stream(
stream_response(contextual_response)
)

# Display summary of costs and steps with enhanced visual and detailed tooltips
with st.expander("📊 Detailed Summary of Inference", expanded=True):
Expand All @@ -107,7 +116,9 @@ def initialize_rag_query_tab(
st.markdown(detailed_summary_table, unsafe_allow_html=True)
else:
# Display basic info about the Knowledge Base
st.markdown(f"> Total Documents in Knowledge Base `{total_docs_in_knowledge_base}`")
st.markdown(
f"> Total Documents in Knowledge Base `{total_docs_in_knowledge_base}`"
)

# Ensure there are documents in the knowledge base
if total_docs_in_knowledge_base == 0:
Expand Down Expand Up @@ -140,34 +151,41 @@ def initialize_rag_query_tab(
start_time = time.time()
with st.spinner("Finding similar documents..."):
query_pipeline.set_model(selected_embedding_model_name)
if (num_results != 0):
if num_results != 0:
similar_docs = query_pipeline.find_similar_documents(
query_text=user_query, num_results=num_results
)
else:
similar_docs = []

if not similar_docs:
st.error("❌ User has chosen not to provide documents from the knowledge base!")
st.error(
"❌ User has chosen not to provide documents from the knowledge base!"
)
else:
with st.expander(
"Used **:green[Relevent Documents]** in Context", expanded=False
"Used **:green[Relevent Documents]** in Context",
expanded=False,
):
for doc in similar_docs:
st.info(doc)

# Prepare context-enhanced prompt
with st.spinner("Preparing context-enhanced prompt..."):
if len(similar_docs) == 0:
similar_docs = ['No documents found related to user query! Use your external knowledge or search the internet if possible']
context_enhanced_prompt, expertise_area_cost, identified_expertise_area = (
query_pipeline.determine_expertise_and_prepare_prompt(
user_query=user_query,
similar_docs=similar_docs,
inference_model=selected_llm_name,
max_completion_tokens=selected_llm_tokens_limit,
temperature=selected_llm_temp,
)
similar_docs = [
"No documents found related to user query! Use your external knowledge or search the internet if possible"
]
(
context_enhanced_prompt,
expertise_area_cost,
identified_expertise_area,
) = query_pipeline.determine_expertise_and_prepare_prompt(
user_query=user_query,
similar_docs=similar_docs,
inference_model=selected_llm_name,
max_completion_tokens=selected_llm_tokens_limit,
temperature=selected_llm_temp,
)
with st.expander("RAG Prompt", expanded=True):
st.info(
Expand All @@ -191,7 +209,9 @@ def initialize_rag_query_tab(
)

# Display message
st.chat_message("assistant").write_stream(stream_response(contextual_response))
st.chat_message("assistant").write_stream(
stream_response(contextual_response)
)

# Display summary of costs and steps with enhanced visual and detailed tooltips
with st.expander("📊 Detailed Summary of Inference", expanded=True):
Expand Down

0 comments on commit ff3e0c7

Please sign in to comment.