|
-
-
- import json
- import os
- from common.log import logger
-
-
- available_setting ={
-
- "open_ai_api_key": "",
- "open_ai_api_base": "https://api.openai.com/v1",
- "proxy": "",
- "model": "gpt-3.5-turbo",
- "use_azure_chatgpt": False,
-
-
- "single_chat_prefix": ["bot", "@bot"],
- "single_chat_reply_prefix": "[bot] ",
- "group_chat_prefix": ["@bot"],
- "group_chat_reply_prefix": "",
- "group_chat_keyword": [],
- "group_at_off": False,
- "group_name_white_list": ["ChatGPT测试群", "ChatGPT测试群2"],
- "group_name_keyword_white_list": [],
- "group_chat_in_one_session": ["ChatGPT测试群"],
- "image_create_prefix": ["画", "看", "找"],
-
-
- "expires_in_seconds": 3600,
- "character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。",
- "conversation_max_tokens": 1000,
-
-
- "rate_limit_chatgpt": 20,
- "rate_limit_dalle": 50,
-
-
-
- "temperature": 0.9,
- "top_p": 1,
- "frequency_penalty": 0,
- "presence_penalty": 0,
-
-
- "speech_recognition": False,
- "group_speech_recognition": False,
- "voice_reply_voice": False,
- "voice_to_text": "openai",
- "text_to_voice": "baidu",
-
-
- 'baidu_app_id': "",
- 'baidu_api_key': "",
- 'baidu_secret_key': "",
-
-
- "chat_time_module": False,
- "chat_start_time": "00:00",
- "chat_stop_time": "24:00",
-
-
- "hot_reload": False,
-
-
- "wechaty_puppet_service_token": "",
-
-
- "clear_memory_commands": ['#清除记忆'],
-
-
- }
-
- class Config(dict):
- def __getitem__(self, key):
- if key not in available_setting:
- raise Exception("key {} not in available_setting".format(key))
- return super().__getitem__(key)
-
- def __setitem__(self, key, value):
- if key not in available_setting:
- raise Exception("key {} not in available_setting".format(key))
- return super().__setitem__(key, value)
-
- def get(self, key, default=None):
- try :
- return self[key]
- except KeyError as e:
- return default
- except Exception as e:
- raise e
-
- config = Config()
-
- def load_config():
- global config
- config_path = "./config.json"
- if not os.path.exists(config_path):
- logger.info('配置文件不存在,将使用config-template.json模板')
- config_path = "./config-template.json"
-
- config_str = read_file(config_path)
- logger.debug("[INIT] config str: {}".format(config_str))
-
-
- config = Config(json.loads(config_str))
-
-
-
- for name, value in os.environ.items():
- name = name.lower()
- if name in available_setting:
- logger.info("[INIT] override config by environ args: {}={}".format(name, value))
- try:
- config[name] = eval(value)
- except:
- config[name] = value
-
- logger.info("[INIT] load config: {}".format(config))
-
-
-
- def get_root():
- return os.path.dirname(os.path.abspath( __file__ ))
-
-
- def read_file(path):
- with open(path, mode='r', encoding='utf-8') as f:
- return f.read()
-
-
- def conf():
- return config
|