fix: optimize sidebar configuration by reducing unnecessary file writes and improving widget creation efficiency
This commit is contained in:
18
alwrity.py
18
alwrity.py
@@ -103,15 +103,16 @@ def check_llm_environs():
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def save_config(config):
|
def save_config(config, save_now=False):
|
||||||
"""
|
"""
|
||||||
Saves the provided configuration dictionary to a JSON file specified by the environment variable.
|
Saves the provided configuration dictionary to a JSON file specified by the environment variable.
|
||||||
"""
|
"""
|
||||||
try:
|
if save_now:
|
||||||
with open(os.getenv("ALWRITY_CONFIG"), "w") as config_file:
|
try:
|
||||||
json.dump(config, config_file, indent=4)
|
with open(os.getenv("ALWRITY_CONFIG"), "w") as config_file:
|
||||||
except Exception as e:
|
json.dump(config, config_file, indent=4)
|
||||||
st.error(f"An error occurred while saving the configuration: {e}")
|
except Exception as e:
|
||||||
|
st.error(f"An error occurred while saving the configuration: {e}")
|
||||||
|
|
||||||
|
|
||||||
# Sidebar configuration
|
# Sidebar configuration
|
||||||
@@ -284,8 +285,9 @@ def sidebar_configuration():
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Writing the configuration to a file whenever a change is made
|
# Option to save the configuration explicitly
|
||||||
save_config(config)
|
if st.sidebar.button("Save Configuration"):
|
||||||
|
save_config(config, save_now=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user