Skip to content

Commit

Permalink
fix: Admin config page refresh issue fix (#1330)
Browse files Browse the repository at this point in the history
  • Loading branch information
AjitPadhi-Microsoft authored Sep 18, 2024
1 parent 9b3dc39 commit 9ecf2b7
Showing 1 changed file with 119 additions and 110 deletions.
229 changes: 119 additions & 110 deletions code/backend/pages/04_Configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,125 +306,134 @@ def validate_documents():
disabled=not st.session_state["use_on_your_data_format"],
)

document_processors = list(
map(
lambda x: {
"document_type": x.document_type,
"chunking_strategy": (
x.chunking.chunking_strategy.value if x.chunking else None
),
"chunking_size": x.chunking.chunk_size if x.chunking else None,
"chunking_overlap": x.chunking.chunk_overlap if x.chunking else None,
"loading_strategy": (
x.loading.loading_strategy.value if x.loading else None
),
"use_advanced_image_processing": x.use_advanced_image_processing,
},
config.document_processors,
)
)

if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION:
with st.expander("Integrated Vectorization configuration", expanded=True):
st.text_input("Max Page Length", key="max_page_length")
st.text_input("Page Overlap Length", key="page_overlap_length")
integrated_vectorization_config = {
"max_page_length": st.session_state["max_page_length"],
"page_overlap_length": st.session_state["page_overlap_length"],
}

else:
with st.expander("Document processing configuration", expanded=True):
edited_document_processors = st.data_editor(
data=document_processors,
use_container_width=True,
num_rows="dynamic",
column_config={
"document_type": st.column_config.SelectboxColumn(
options=config.get_available_document_types()
with st.form("config_form", border=False):
document_processors = list(
map(
lambda x: {
"document_type": x.document_type,
"chunking_strategy": (
x.chunking.chunking_strategy.value if x.chunking else None
),
"chunking_strategy": st.column_config.SelectboxColumn(
options=[
cs for cs in config.get_available_chunking_strategies()
]
"chunking_size": x.chunking.chunk_size if x.chunking else None,
"chunking_overlap": (
x.chunking.chunk_overlap if x.chunking else None
),
"loading_strategy": st.column_config.SelectboxColumn(
options=[ls for ls in config.get_available_loading_strategies()]
"loading_strategy": (
x.loading.loading_strategy.value if x.loading else None
),
"use_advanced_image_processing": x.use_advanced_image_processing,
},
config.document_processors,
)

with st.expander("Logging configuration", expanded=True):
st.checkbox(
"Log user input and output (questions, answers, chat history, sources)",
key="log_user_interactions",
)
st.checkbox("Log tokens", key="log_tokens")

if st.button("Save configuration"):
document_processors = (
list(
map(
lambda x: {
"document_type": x["document_type"],
"chunking": {
"strategy": x["chunking_strategy"],
"size": x["chunking_size"],
"overlap": x["chunking_overlap"],
},
"loading": {
"strategy": x["loading_strategy"],
},
"use_advanced_image_processing": x[
"use_advanced_image_processing"
],

if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION:
with st.expander("Integrated Vectorization configuration", expanded=True):
st.text_input("Max Page Length", key="max_page_length")
st.text_input("Page Overlap Length", key="page_overlap_length")
integrated_vectorization_config = {
"max_page_length": st.session_state["max_page_length"],
"page_overlap_length": st.session_state["page_overlap_length"],
}

else:
with st.expander("Document processing configuration", expanded=True):
edited_document_processors = st.data_editor(
data=document_processors,
use_container_width=True,
num_rows="dynamic",
column_config={
"document_type": st.column_config.SelectboxColumn(
options=config.get_available_document_types()
),
"chunking_strategy": st.column_config.SelectboxColumn(
options=[
cs for cs in config.get_available_chunking_strategies()
]
),
"loading_strategy": st.column_config.SelectboxColumn(
options=[
ls for ls in config.get_available_loading_strategies()
]
),
},
edited_document_processors,
)

with st.expander("Logging configuration", expanded=True):
st.checkbox(
"Log user input and output (questions, answers, chat history, sources)",
key="log_user_interactions",
)
st.checkbox("Log tokens", key="log_tokens")

if st.form_submit_button("Save configuration"):
document_processors = (
list(
map(
lambda x: {
"document_type": x["document_type"],
"chunking": {
"strategy": x["chunking_strategy"],
"size": x["chunking_size"],
"overlap": x["chunking_overlap"],
},
"loading": {
"strategy": x["loading_strategy"],
},
"use_advanced_image_processing": x[
"use_advanced_image_processing"
],
},
edited_document_processors,
)
)
if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION is False
else []
)
current_config = {
"prompts": {
"condense_question_prompt": "", # st.session_state['condense_question_prompt'],
"answering_system_prompt": st.session_state[
"answering_system_prompt"
],
"answering_user_prompt": st.session_state["answering_user_prompt"],
"use_on_your_data_format": st.session_state[
"use_on_your_data_format"
],
"post_answering_prompt": st.session_state["post_answering_prompt"],
"enable_post_answering_prompt": st.session_state[
"enable_post_answering_prompt"
],
"enable_content_safety": st.session_state["enable_content_safety"],
"ai_assistant_type": st.session_state["ai_assistant_type"],
"conversational_flow": st.session_state["conversational_flow"],
},
"messages": {
"post_answering_filter": st.session_state[
"post_answering_filter_message"
]
},
"example": {
"documents": st.session_state["example_documents"],
"user_question": st.session_state["example_user_question"],
"answer": st.session_state["example_answer"],
},
"document_processors": document_processors,
"logging": {
"log_user_interactions": st.session_state["log_user_interactions"],
"log_tokens": st.session_state["log_tokens"],
},
"orchestrator": {"strategy": st.session_state["orchestrator_strategy"]},
"integrated_vectorization_config": (
integrated_vectorization_config
if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION
else None
),
}
ConfigHelper.save_config_as_active(current_config)
st.success(
"Configuration saved successfully! Please restart the chat service for these changes to take effect."
)
if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION is False
else []
)
current_config = {
"prompts": {
"condense_question_prompt": "", # st.session_state['condense_question_prompt'],
"answering_system_prompt": st.session_state["answering_system_prompt"],
"answering_user_prompt": st.session_state["answering_user_prompt"],
"use_on_your_data_format": st.session_state["use_on_your_data_format"],
"post_answering_prompt": st.session_state["post_answering_prompt"],
"enable_post_answering_prompt": st.session_state[
"enable_post_answering_prompt"
],
"enable_content_safety": st.session_state["enable_content_safety"],
"ai_assistant_type": st.session_state["ai_assistant_type"],
"conversational_flow": st.session_state["conversational_flow"],
},
"messages": {
"post_answering_filter": st.session_state[
"post_answering_filter_message"
]
},
"example": {
"documents": st.session_state["example_documents"],
"user_question": st.session_state["example_user_question"],
"answer": st.session_state["example_answer"],
},
"document_processors": document_processors,
"logging": {
"log_user_interactions": st.session_state["log_user_interactions"],
"log_tokens": st.session_state["log_tokens"],
},
"orchestrator": {"strategy": st.session_state["orchestrator_strategy"]},
"integrated_vectorization_config": (
integrated_vectorization_config
if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION
else None
),
}
ConfigHelper.save_config_as_active(current_config)
st.success(
"Configuration saved successfully! Please restart the chat service for these changes to take effect."
)

with st.popover(":red[Reset configuration to defaults]"):

Expand Down

0 comments on commit 9ecf2b7

Please sign in to comment.