Improve options management (#2078)

- `/sdapi/v1/options` GET now calls `get_config()` from **sysinfo** module, instead of from its own version of the function.

- Defined a new, flexible and more robust `set_config()` function in **sysinfo** module, which:
  - obsoletes redundant code
  - skips updating values that are unchanged
  - has flexible args for both API and UI use

- `/sdapi/v1/options` POST and `override_settings` now use the new `set_config()` function.  `set_config()` could possibly obsolete additional functions, but I'm not going to get into that just yet.

- Options for `forge_additional_modules` can now be provided either as the file path, or just the module name.

- Most importantly, `refresh_model_loading_parameters()` is now only called ONCE per request, and **only** if necessary.

- It is now much easier to call `shared.opts.save()` as needed
This commit is contained in:
altoiddealer
2024-10-16 06:21:54 -04:00
committed by GitHub
parent cce30d3340
commit 2c543719e3
4 changed files with 69 additions and 75 deletions

View File

@@ -239,28 +239,35 @@ def refresh_model_loading_parameters():
return
def checkpoint_change(ckpt_name, refresh_params=True):
def checkpoint_change(ckpt_name:str, save=True, refresh=True):
shared.opts.set('sd_model_checkpoint', ckpt_name)
shared.opts.save(shared.config_filename)
if refresh_params:
if save:
shared.opts.save(shared.config_filename)
if refresh:
refresh_model_loading_parameters()
return
def modules_change(module_names, refresh_params=True):
def modules_change(module_values:list, save=True, refresh=True) -> bool:
""" module values may be provided as file paths or as simply the module names """
modules = []
for n in module_names:
if n in module_list:
modules.append(module_list[n])
for v in module_values:
module_name = os.path.basename(v) # If the input is a filepath, extract the file name
if module_name in module_list:
modules.append(module_list[module_name])
# skip further processing if value unchanged
if modules == shared.opts.data.get('forge_additional_modules'):
return False
shared.opts.set('forge_additional_modules', modules)
shared.opts.save(shared.config_filename)
if refresh_params:
if save:
shared.opts.save(shared.config_filename)
if refresh:
refresh_model_loading_parameters()
return
return True
def get_a1111_ui_component(tab, label):