fix: optimize sidebar configuration by reducing unnecessary file writes and improving widget creation efficiency

This commit is contained in:
ajaysi (aider)
2024-09-14 21:30:18 +05:30
parent 891455149e
commit d4c20d0798

View File

@@ -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)