|
from pydantic import BaseModel, Extra |
|
from nonebot import get_driver |
|
from nonebot.log import logger |
|
import yaml |
|
from pathlib import Path |
|
|
|
|
|
class Config(BaseModel, extra=Extra.ignore): |
|
"""Plugin Config Here""" |
|
ng_config_path: str = "config/naturel_gpt_config.yml" |
|
ng_dev_mode: bool = False |
|
|
|
|
|
driver = get_driver() |
|
global_config = driver.config |
|
config = Config.parse_obj(global_config) |
|
|
|
|
|
CONFIG_TEMPLATE = { |
|
"OPENAI_API_KEYS": [ |
|
'sk-xxxxxxxxxxxxx', |
|
'sk-xxxxxxxxxxxxx', |
|
], |
|
"OPENAI_TIMEOUT": 30, |
|
"PRESETS": { |
|
"白羽": { |
|
'bot_name': '白羽', |
|
'is_locked': True, |
|
'is_default': True, |
|
'bot_self_introl': '白羽是一名喜欢二次元的中二宅女,她机智、傲娇,对人类充满好奇,习惯以白羽喵自称,聊天时喜欢使用各种可爱的颜文字,如果冒犯到她会生气。', |
|
}, |
|
"浅枫": { |
|
'bot_name': '浅枫', |
|
'is_locked': False, |
|
'is_default': False, |
|
'bot_self_introl': '浅枫酱是一名尽职尽责的女仆,她能够帮助主人做很多事情,对话中会体现出对主人的体贴与关心。', |
|
}, |
|
"忆雨": { |
|
'bot_name': '忆雨', |
|
'is_locked': True, |
|
'is_default': False, |
|
'bot_self_introl': '忆雨是一名恐怖小说作家,是个阴沉的女孩,她非常恨人类,和陌生人聊天时的表现冷漠,不喜欢回复过多的文字,兴趣是恐怖小说,如果有人和她探讨如何消灭人类会很有兴致。', |
|
}, |
|
"可洛喵": { |
|
'bot_name': '可洛喵', |
|
'is_locked': True, |
|
'is_default': False, |
|
'bot_self_introl': '可洛喵是一只可爱的猫,它不会说话,它的回复通常以"[动作/心情]声音+颜文字"形式出现,例如"[坐好]喵~(。・ω・。)"或"[开心]喵喵!ヾ(≧▽≦*)o"', |
|
}, |
|
}, |
|
'IGNORE_PREFIX': '#', |
|
'CHAT_MODEL': "gpt-3.5-turbo", |
|
'CHAT_TOP_P': 1, |
|
'CHAT_TEMPERATURE': 0.3, |
|
'CHAT_PRESENCE_PENALTY': 0.3, |
|
'CHAT_FREQUENCY_PENALTY': 0.3, |
|
|
|
'CHAT_HISTORY_MAX_TOKENS': 2048, |
|
'CHAT_MAX_SUMMARY_TOKENS': 512, |
|
'REPLY_MAX_TOKENS': 1024, |
|
'REQ_MAX_TOKENS': 3072, |
|
|
|
'REPLY_ON_NAME_MENTION': True, |
|
'REPLY_ON_AT': True, |
|
'REPLY_ON_WELCOME': True, |
|
|
|
'USER_MEMORY_SUMMARY_THRESHOLD': 12, |
|
|
|
'CHAT_ENABLE_RECORD_ORTHER': True, |
|
'CHAT_ENABLE_SUMMARY_CHAT': False, |
|
'CHAT_MEMORY_SHORT_LENGTH': 8, |
|
'CHAT_MEMORY_MAX_LENGTH': 16, |
|
'CHAT_SUMMARY_INTERVAL': 10, |
|
|
|
'NG_DATA_PATH': "./data/naturel_gpt/", |
|
'NG_EXT_PATH': "./data/naturel_gpt/extensions/", |
|
|
|
'ADMIN_USERID': ['替换成管理员QQ号_(用单引号包裹)'], |
|
'FORBIDDEN_USERS': ['替换成屏蔽QQ号_(用单引号包裹)'], |
|
|
|
'WORD_FOR_WAKE_UP': [], |
|
'WORD_FOR_FORBIDDEN': [], |
|
|
|
'RANDOM_CHAT_PROBABILITY': 0, |
|
|
|
'NG_MSG_PRIORITY': 99, |
|
'NG_BLOCK_OTHERS': False, |
|
'NG_ENABLE_EXT': True, |
|
|
|
'MEMORY_ACTIVE': True, |
|
'MEMORY_MAX_LENGTH': 16, |
|
'MEMORY_ENHANCE_THRESHOLD': 0.6, |
|
|
|
'NG_MAX_RESPONSE_PER_MSG': 5, |
|
'NG_ENABLE_MSG_SPLIT': True, |
|
'NG_ENABLE_AWAKE_IDENTITIES': True, |
|
|
|
'OPENAI_PROXY_SERVER': '', |
|
'UNLOCK_CONTENT_LIMIT': False, |
|
|
|
'NG_EXT_LOAD_LIST': [{ |
|
'EXT_NAME': 'ext_random', |
|
'IS_ACTIVE': False, |
|
'EXT_CONFIG': {}, |
|
}], |
|
|
|
'__DEBUG__': False, |
|
} |
|
|
|
config_path = config.ng_config_path |
|
|
|
|
|
if not Path("config").exists(): |
|
Path("config").mkdir() |
|
|
|
if config.ng_dev_mode: |
|
with open(config_path, 'w', encoding='utf-8') as f: |
|
yaml.dump(CONFIG_TEMPLATE, f, allow_unicode=True) |
|
|
|
else: |
|
|
|
if not Path(config_path).exists(): |
|
with open(config_path, 'w', encoding='utf-8') as f: |
|
yaml.dump(CONFIG_TEMPLATE, f, allow_unicode=True) |
|
logger.info('Naturel GPT 配置文件创建成功') |
|
|
|
|
|
with open(config_path, 'r', encoding='utf-8') as f: |
|
config = yaml.load(f, Loader=yaml.FullLoader) |
|
|
|
for k, v in CONFIG_TEMPLATE.items(): |
|
if k not in config: |
|
config[k] = v |
|
logger.info(f'Naturel GPT 配置文件缺少 {k} 项,已自动补充') |
|
|
|
for k, v in config.items(): |
|
setattr(Config, k, v) |
|
|
|
|
|
if not Path(config['NG_DATA_PATH'][:-1]).exists(): |
|
Path(config['NG_DATA_PATH'][:-1]).mkdir(parents=True) |
|
if not Path(config['NG_EXT_PATH'][:-1]).exists(): |
|
Path(config['NG_EXT_PATH'][:-1]).mkdir(parents=True) |
|
|
|
|
|
with open(config_path, 'w', encoding='utf-8') as f: |
|
yaml.dump(config, f, allow_unicode=True) |
|
logger.info('Naturel GPT 配置文件加载成功') |
|
|