Skip to content

Commit 9ecf2b7

Browse files
fix: Admin config page refresh issue fix (#1330)
1 parent 9b3dc39 commit 9ecf2b7

File tree

1 file changed

+119
-110
lines changed

1 file changed

+119
-110
lines changed

code/backend/pages/04_Configuration.py

Lines changed: 119 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -306,125 +306,134 @@ def validate_documents():
306306
disabled=not st.session_state["use_on_your_data_format"],
307307
)
308308

309-
document_processors = list(
310-
map(
311-
lambda x: {
312-
"document_type": x.document_type,
313-
"chunking_strategy": (
314-
x.chunking.chunking_strategy.value if x.chunking else None
315-
),
316-
"chunking_size": x.chunking.chunk_size if x.chunking else None,
317-
"chunking_overlap": x.chunking.chunk_overlap if x.chunking else None,
318-
"loading_strategy": (
319-
x.loading.loading_strategy.value if x.loading else None
320-
),
321-
"use_advanced_image_processing": x.use_advanced_image_processing,
322-
},
323-
config.document_processors,
324-
)
325-
)
326-
327-
if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION:
328-
with st.expander("Integrated Vectorization configuration", expanded=True):
329-
st.text_input("Max Page Length", key="max_page_length")
330-
st.text_input("Page Overlap Length", key="page_overlap_length")
331-
integrated_vectorization_config = {
332-
"max_page_length": st.session_state["max_page_length"],
333-
"page_overlap_length": st.session_state["page_overlap_length"],
334-
}
335-
336-
else:
337-
with st.expander("Document processing configuration", expanded=True):
338-
edited_document_processors = st.data_editor(
339-
data=document_processors,
340-
use_container_width=True,
341-
num_rows="dynamic",
342-
column_config={
343-
"document_type": st.column_config.SelectboxColumn(
344-
options=config.get_available_document_types()
309+
with st.form("config_form", border=False):
310+
document_processors = list(
311+
map(
312+
lambda x: {
313+
"document_type": x.document_type,
314+
"chunking_strategy": (
315+
x.chunking.chunking_strategy.value if x.chunking else None
345316
),
346-
"chunking_strategy": st.column_config.SelectboxColumn(
347-
options=[
348-
cs for cs in config.get_available_chunking_strategies()
349-
]
317+
"chunking_size": x.chunking.chunk_size if x.chunking else None,
318+
"chunking_overlap": (
319+
x.chunking.chunk_overlap if x.chunking else None
350320
),
351-
"loading_strategy": st.column_config.SelectboxColumn(
352-
options=[ls for ls in config.get_available_loading_strategies()]
321+
"loading_strategy": (
322+
x.loading.loading_strategy.value if x.loading else None
353323
),
324+
"use_advanced_image_processing": x.use_advanced_image_processing,
354325
},
326+
config.document_processors,
355327
)
356-
357-
with st.expander("Logging configuration", expanded=True):
358-
st.checkbox(
359-
"Log user input and output (questions, answers, chat history, sources)",
360-
key="log_user_interactions",
361328
)
362-
st.checkbox("Log tokens", key="log_tokens")
363-
364-
if st.button("Save configuration"):
365-
document_processors = (
366-
list(
367-
map(
368-
lambda x: {
369-
"document_type": x["document_type"],
370-
"chunking": {
371-
"strategy": x["chunking_strategy"],
372-
"size": x["chunking_size"],
373-
"overlap": x["chunking_overlap"],
374-
},
375-
"loading": {
376-
"strategy": x["loading_strategy"],
377-
},
378-
"use_advanced_image_processing": x[
379-
"use_advanced_image_processing"
380-
],
329+
330+
if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION:
331+
with st.expander("Integrated Vectorization configuration", expanded=True):
332+
st.text_input("Max Page Length", key="max_page_length")
333+
st.text_input("Page Overlap Length", key="page_overlap_length")
334+
integrated_vectorization_config = {
335+
"max_page_length": st.session_state["max_page_length"],
336+
"page_overlap_length": st.session_state["page_overlap_length"],
337+
}
338+
339+
else:
340+
with st.expander("Document processing configuration", expanded=True):
341+
edited_document_processors = st.data_editor(
342+
data=document_processors,
343+
use_container_width=True,
344+
num_rows="dynamic",
345+
column_config={
346+
"document_type": st.column_config.SelectboxColumn(
347+
options=config.get_available_document_types()
348+
),
349+
"chunking_strategy": st.column_config.SelectboxColumn(
350+
options=[
351+
cs for cs in config.get_available_chunking_strategies()
352+
]
353+
),
354+
"loading_strategy": st.column_config.SelectboxColumn(
355+
options=[
356+
ls for ls in config.get_available_loading_strategies()
357+
]
358+
),
381359
},
382-
edited_document_processors,
383360
)
361+
362+
with st.expander("Logging configuration", expanded=True):
363+
st.checkbox(
364+
"Log user input and output (questions, answers, chat history, sources)",
365+
key="log_user_interactions",
366+
)
367+
st.checkbox("Log tokens", key="log_tokens")
368+
369+
if st.form_submit_button("Save configuration"):
370+
document_processors = (
371+
list(
372+
map(
373+
lambda x: {
374+
"document_type": x["document_type"],
375+
"chunking": {
376+
"strategy": x["chunking_strategy"],
377+
"size": x["chunking_size"],
378+
"overlap": x["chunking_overlap"],
379+
},
380+
"loading": {
381+
"strategy": x["loading_strategy"],
382+
},
383+
"use_advanced_image_processing": x[
384+
"use_advanced_image_processing"
385+
],
386+
},
387+
edited_document_processors,
388+
)
389+
)
390+
if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION is False
391+
else []
392+
)
393+
current_config = {
394+
"prompts": {
395+
"condense_question_prompt": "", # st.session_state['condense_question_prompt'],
396+
"answering_system_prompt": st.session_state[
397+
"answering_system_prompt"
398+
],
399+
"answering_user_prompt": st.session_state["answering_user_prompt"],
400+
"use_on_your_data_format": st.session_state[
401+
"use_on_your_data_format"
402+
],
403+
"post_answering_prompt": st.session_state["post_answering_prompt"],
404+
"enable_post_answering_prompt": st.session_state[
405+
"enable_post_answering_prompt"
406+
],
407+
"enable_content_safety": st.session_state["enable_content_safety"],
408+
"ai_assistant_type": st.session_state["ai_assistant_type"],
409+
"conversational_flow": st.session_state["conversational_flow"],
410+
},
411+
"messages": {
412+
"post_answering_filter": st.session_state[
413+
"post_answering_filter_message"
414+
]
415+
},
416+
"example": {
417+
"documents": st.session_state["example_documents"],
418+
"user_question": st.session_state["example_user_question"],
419+
"answer": st.session_state["example_answer"],
420+
},
421+
"document_processors": document_processors,
422+
"logging": {
423+
"log_user_interactions": st.session_state["log_user_interactions"],
424+
"log_tokens": st.session_state["log_tokens"],
425+
},
426+
"orchestrator": {"strategy": st.session_state["orchestrator_strategy"]},
427+
"integrated_vectorization_config": (
428+
integrated_vectorization_config
429+
if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION
430+
else None
431+
),
432+
}
433+
ConfigHelper.save_config_as_active(current_config)
434+
st.success(
435+
"Configuration saved successfully! Please restart the chat service for these changes to take effect."
384436
)
385-
if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION is False
386-
else []
387-
)
388-
current_config = {
389-
"prompts": {
390-
"condense_question_prompt": "", # st.session_state['condense_question_prompt'],
391-
"answering_system_prompt": st.session_state["answering_system_prompt"],
392-
"answering_user_prompt": st.session_state["answering_user_prompt"],
393-
"use_on_your_data_format": st.session_state["use_on_your_data_format"],
394-
"post_answering_prompt": st.session_state["post_answering_prompt"],
395-
"enable_post_answering_prompt": st.session_state[
396-
"enable_post_answering_prompt"
397-
],
398-
"enable_content_safety": st.session_state["enable_content_safety"],
399-
"ai_assistant_type": st.session_state["ai_assistant_type"],
400-
"conversational_flow": st.session_state["conversational_flow"],
401-
},
402-
"messages": {
403-
"post_answering_filter": st.session_state[
404-
"post_answering_filter_message"
405-
]
406-
},
407-
"example": {
408-
"documents": st.session_state["example_documents"],
409-
"user_question": st.session_state["example_user_question"],
410-
"answer": st.session_state["example_answer"],
411-
},
412-
"document_processors": document_processors,
413-
"logging": {
414-
"log_user_interactions": st.session_state["log_user_interactions"],
415-
"log_tokens": st.session_state["log_tokens"],
416-
},
417-
"orchestrator": {"strategy": st.session_state["orchestrator_strategy"]},
418-
"integrated_vectorization_config": (
419-
integrated_vectorization_config
420-
if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION
421-
else None
422-
),
423-
}
424-
ConfigHelper.save_config_as_active(current_config)
425-
st.success(
426-
"Configuration saved successfully! Please restart the chat service for these changes to take effect."
427-
)
428437

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

0 commit comments

Comments
 (0)