Spaces:
Sleeping
Sleeping
| import json | |
| import os | |
| CONFIG_PATH = "config.json" | |
| PROMPT_PATH = "assets/prompt/init.txt" | |
| def load_config(path=CONFIG_PATH) -> dict: | |
| if not os.path.exists(path): | |
| return {} | |
| with open(path, "r", encoding="utf-8") as f: | |
| return json.load(f) | |
| def load_cha_config(path=CONFIG_PATH) -> dict: | |
| config = load_config(path) | |
| return config.get("cha", {}) | |
| def load_llm_config(path=CONFIG_PATH) -> dict: | |
| config = load_config(path) | |
| return config.get("llm", {}) | |
| def save_config(config: dict, path=CONFIG_PATH): | |
| with open(path, "w", encoding="utf-8") as f: | |
| json.dump(config, f, indent=4, ensure_ascii=False) | |
| def load_prompt_txt(path=PROMPT_PATH): | |
| if not os.path.exists(path): | |
| return "" | |
| with open(path, "r", encoding="utf-8") as f: | |
| return f.read() |