mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-23 11:36:38 +08:00
feature: add system setting service (#12408)
### What problem does this PR solve? #12409 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@ -30,6 +30,7 @@ from api.db.services.knowledgebase_service import KnowledgebaseService
|
||||
from api.db.services.tenant_llm_service import LLMFactoriesService, TenantLLMService
|
||||
from api.db.services.llm_service import LLMService, LLMBundle, get_init_tenant_llm
|
||||
from api.db.services.user_service import TenantService, UserTenantService
|
||||
from api.db.services.system_settings_service import SystemSettingsService
|
||||
from api.db.joint_services.memory_message_service import init_message_id_sequence, init_memory_size_cache
|
||||
from common.constants import LLMType
|
||||
from common.file_utils import get_project_base_directory
|
||||
@ -158,13 +159,15 @@ def add_graph_templates():
|
||||
CanvasTemplateService.save(**cnvs)
|
||||
except Exception:
|
||||
CanvasTemplateService.update_by_id(cnvs["id"], cnvs)
|
||||
except Exception:
|
||||
logging.exception("Add agent templates error: ")
|
||||
except Exception as e:
|
||||
logging.exception(f"Add agent templates error: {e}")
|
||||
|
||||
|
||||
def init_web_data():
|
||||
start_time = time.time()
|
||||
|
||||
init_table()
|
||||
|
||||
init_llm_factory()
|
||||
# if not UserService.get_all().count():
|
||||
# init_superuser()
|
||||
@ -174,6 +177,31 @@ def init_web_data():
|
||||
init_memory_size_cache()
|
||||
logging.info("init web data success:{}".format(time.time() - start_time))
|
||||
|
||||
def init_table():
|
||||
# init system_settings
|
||||
with open(os.path.join(get_project_base_directory(), "conf", "system_settings.json"), "r") as f:
|
||||
records_from_file = json.load(f)["system_settings"]
|
||||
|
||||
record_index = {}
|
||||
records_from_db = SystemSettingsService.get_all()
|
||||
for index, record in enumerate(records_from_db):
|
||||
record_index[record.name] = index
|
||||
|
||||
to_save = []
|
||||
for record in records_from_file:
|
||||
setting_name = record["name"]
|
||||
if setting_name not in record_index:
|
||||
to_save.append(record)
|
||||
|
||||
len_to_save = len(to_save)
|
||||
if len_to_save > 0:
|
||||
# not initialized
|
||||
try:
|
||||
SystemSettingsService.insert_many(to_save, len_to_save)
|
||||
except Exception as e:
|
||||
logging.exception("System settings init error: {}".format(e))
|
||||
raise e
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_web_db()
|
||||
|
||||
Reference in New Issue
Block a user