mirror of
https://github.com/ParisNeo/lollms.git
synced 2025-04-20 00:20:47 +00:00
upgraded load_config
This commit is contained in:
parent
24c99b0d77
commit
8a7038fe95
@ -98,22 +98,53 @@ class APScript:
|
||||
def remove_file(self, path):
|
||||
self.files.remove(path)
|
||||
|
||||
def load_config_file(self, path):
|
||||
def load_config_file(self, path, default_config=None):
|
||||
"""
|
||||
Load the content of local_config.yaml file.
|
||||
|
||||
The function reads the content of the local_config.yaml file and returns it as a Python dictionary.
|
||||
If a default_config is provided, it fills any missing entries in the loaded dictionary.
|
||||
If at least one field from default configuration was not present in the loaded configuration, the updated
|
||||
configuration is saved.
|
||||
|
||||
Args:
|
||||
None
|
||||
path (str): The path to the local_config.yaml file.
|
||||
default_config (dict, optional): A dictionary with default values to fill missing entries.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing the loaded data from the local_config.yaml file.
|
||||
"""
|
||||
dict: A dictionary containing the loaded data from the local_config.yaml file, with missing entries filled
|
||||
by default_config if provided.
|
||||
"""
|
||||
with open(path, 'r') as file:
|
||||
data = yaml.safe_load(file)
|
||||
|
||||
if default_config:
|
||||
updated = False
|
||||
for key, value in default_config.items():
|
||||
if key not in data:
|
||||
data[key] = value
|
||||
updated = True
|
||||
|
||||
if updated:
|
||||
self.save_config_file(path, data)
|
||||
|
||||
return data
|
||||
|
||||
def save_config_file(self, path, data):
|
||||
"""
|
||||
Save the configuration data to a local_config.yaml file.
|
||||
|
||||
Args:
|
||||
path (str): The path to save the local_config.yaml file.
|
||||
data (dict): The configuration data to be saved.
|
||||
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
with open(path, 'w') as file:
|
||||
yaml.dump(data, file)
|
||||
|
||||
|
||||
def remove_text_from_string(self, string, text_to_find):
|
||||
"""
|
||||
Removes everything from the first occurrence of the specified text in the string (case-insensitive).
|
||||
|
2
setup.py
2
setup.py
@ -26,7 +26,7 @@ def get_all_files(path):
|
||||
|
||||
setuptools.setup(
|
||||
name="lollms",
|
||||
version="1.1.62",
|
||||
version="1.1.63",
|
||||
author="Saifeddine ALOUI",
|
||||
author_email="aloui.saifeddine@gmail.com",
|
||||
description="A python library for AI personality definition",
|
||||
|
Loading…
x
Reference in New Issue
Block a user