Skip to content

Commit 0914ce7

Browse files
fix: fixed admin config issue (#1379)
1 parent c42053a commit 0914ce7

2 files changed

Lines changed: 91 additions & 77 deletions

File tree

code/backend/batch/utilities/helpers/config/config_helper.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,8 @@ def __init__(self, config: dict):
2929
self.document_processors = [
3030
EmbeddingConfig(
3131
document_type=c["document_type"],
32-
chunking=(
33-
ChunkingSettings(c["chunking"])
34-
if c.get("use_advanced_image_processing", False) is False
35-
else None
36-
),
37-
loading=(
38-
LoadingSettings(c["loading"])
39-
if c.get("use_advanced_image_processing", False) is False
40-
else None
41-
),
32+
chunking=ChunkingSettings(c["chunking"]),
33+
loading=LoadingSettings(c["loading"]),
4234
use_advanced_image_processing=c.get(
4335
"use_advanced_image_processing", False
4436
),

code/backend/pages/04_Configuration.py

Lines changed: 89 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,14 @@ def validate_documents():
333333
lambda x: {
334334
"document_type": x.document_type,
335335
"chunking_strategy": (
336-
x.chunking.chunking_strategy.value if x.chunking else None
336+
x.chunking.chunking_strategy.value if x.chunking else "layout"
337337
),
338338
"chunking_size": x.chunking.chunk_size if x.chunking else None,
339339
"chunking_overlap": (
340340
x.chunking.chunk_overlap if x.chunking else None
341341
),
342342
"loading_strategy": (
343-
x.loading.loading_strategy.value if x.loading else None
343+
x.loading.loading_strategy.value if x.loading else "layout"
344344
),
345345
"use_advanced_image_processing": x.use_advanced_image_processing,
346346
},
@@ -391,74 +391,96 @@ def validate_documents():
391391
st.checkbox("Log tokens", key="log_tokens")
392392

393393
if st.form_submit_button("Save configuration"):
394-
document_processors = (
395-
list(
396-
map(
397-
lambda x: {
398-
"document_type": x["document_type"],
399-
"chunking": {
400-
"strategy": x["chunking_strategy"],
401-
"size": x["chunking_size"],
402-
"overlap": x["chunking_overlap"],
403-
},
404-
"loading": {
405-
"strategy": x["loading_strategy"],
394+
valid = all(
395+
row["document_type"]
396+
and row["chunking_strategy"]
397+
and row["loading_strategy"]
398+
for row in edited_document_processors
399+
)
400+
401+
if not valid:
402+
st.error(
403+
"Please ensure all fields are selected and not left blank in Document processing configuration."
404+
)
405+
else:
406+
document_processors = (
407+
list(
408+
map(
409+
lambda x: {
410+
"document_type": x["document_type"],
411+
"chunking": {
412+
"strategy": x["chunking_strategy"],
413+
"size": x["chunking_size"],
414+
"overlap": x["chunking_overlap"],
415+
},
416+
"loading": {
417+
"strategy": x["loading_strategy"],
418+
},
419+
"use_advanced_image_processing": x[
420+
"use_advanced_image_processing"
421+
],
406422
},
407-
"use_advanced_image_processing": x[
408-
"use_advanced_image_processing"
409-
],
410-
},
411-
edited_document_processors,
423+
edited_document_processors,
424+
)
412425
)
426+
if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION is False
427+
else []
428+
)
429+
current_config = {
430+
"prompts": {
431+
"condense_question_prompt": "", # st.session_state['condense_question_prompt'],
432+
"answering_system_prompt": st.session_state[
433+
"answering_system_prompt"
434+
],
435+
"answering_user_prompt": st.session_state[
436+
"answering_user_prompt"
437+
],
438+
"use_on_your_data_format": st.session_state[
439+
"use_on_your_data_format"
440+
],
441+
"post_answering_prompt": st.session_state[
442+
"post_answering_prompt"
443+
],
444+
"enable_post_answering_prompt": st.session_state[
445+
"enable_post_answering_prompt"
446+
],
447+
"enable_content_safety": st.session_state[
448+
"enable_content_safety"
449+
],
450+
"ai_assistant_type": st.session_state["ai_assistant_type"],
451+
"conversational_flow": st.session_state["conversational_flow"],
452+
},
453+
"messages": {
454+
"post_answering_filter": st.session_state[
455+
"post_answering_filter_message"
456+
]
457+
},
458+
"example": {
459+
"documents": st.session_state["example_documents"],
460+
"user_question": st.session_state["example_user_question"],
461+
"answer": st.session_state["example_answer"],
462+
},
463+
"document_processors": document_processors,
464+
"logging": {
465+
"log_user_interactions": st.session_state[
466+
"log_user_interactions"
467+
],
468+
"log_tokens": st.session_state["log_tokens"],
469+
},
470+
"orchestrator": {
471+
"strategy": st.session_state["orchestrator_strategy"]
472+
},
473+
"integrated_vectorization_config": (
474+
integrated_vectorization_config
475+
if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION
476+
else None
477+
),
478+
"enable_chat_history": st.session_state["enable_chat_history"],
479+
}
480+
ConfigHelper.save_config_as_active(current_config)
481+
st.success(
482+
"Configuration saved successfully! Please restart the chat service for these changes to take effect."
413483
)
414-
if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION is False
415-
else []
416-
)
417-
current_config = {
418-
"prompts": {
419-
"condense_question_prompt": "", # st.session_state['condense_question_prompt'],
420-
"answering_system_prompt": st.session_state[
421-
"answering_system_prompt"
422-
],
423-
"answering_user_prompt": st.session_state["answering_user_prompt"],
424-
"use_on_your_data_format": st.session_state[
425-
"use_on_your_data_format"
426-
],
427-
"post_answering_prompt": st.session_state["post_answering_prompt"],
428-
"enable_post_answering_prompt": st.session_state[
429-
"enable_post_answering_prompt"
430-
],
431-
"enable_content_safety": st.session_state["enable_content_safety"],
432-
"ai_assistant_type": st.session_state["ai_assistant_type"],
433-
"conversational_flow": st.session_state["conversational_flow"],
434-
},
435-
"messages": {
436-
"post_answering_filter": st.session_state[
437-
"post_answering_filter_message"
438-
]
439-
},
440-
"example": {
441-
"documents": st.session_state["example_documents"],
442-
"user_question": st.session_state["example_user_question"],
443-
"answer": st.session_state["example_answer"],
444-
},
445-
"document_processors": document_processors,
446-
"logging": {
447-
"log_user_interactions": st.session_state["log_user_interactions"],
448-
"log_tokens": st.session_state["log_tokens"],
449-
},
450-
"orchestrator": {"strategy": st.session_state["orchestrator_strategy"]},
451-
"integrated_vectorization_config": (
452-
integrated_vectorization_config
453-
if env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION
454-
else None
455-
),
456-
"enable_chat_history": st.session_state["enable_chat_history"],
457-
}
458-
ConfigHelper.save_config_as_active(current_config)
459-
st.success(
460-
"Configuration saved successfully! Please restart the chat service for these changes to take effect."
461-
)
462484

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

0 commit comments

Comments
 (0)