File size: 807 Bytes
5c6d006
 
 
 
5f703f9
5c6d006
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5f703f9
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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()