Files
AI_NovelGenerator/config_manager.py
T
YILING0013 2fe5fe1b85 新增功能:自定义知识库、生成指导
允许用户上传自己的知识库(建议在线版API,或上下文长的用户使用)

允许在生成下一章节时加入提前指导

模型Temperature参数支持
2025-01-31 13:50:07 +08:00

24 lines
737 B
Python

# config_manager.py
# -*- coding: utf-8 -*-
import json
import os
def load_config(config_file: str) -> dict:
"""从指定的 config_file 加载配置,若不存在则返回空字典。"""
if os.path.exists(config_file):
try:
with open(config_file, 'r', encoding='utf-8') as f:
return json.load(f)
except:
pass
return {}
def save_config(config_data: dict, config_file: str) -> bool:
"""将 config_data 保存到 config_file 中,返回 True/False 表示是否成功。"""
try:
with open(config_file, 'w', encoding='utf-8') as f:
json.dump(config_data, f, ensure_ascii=False, indent=4)
return True
except:
return False