Soulter / AstrBot

QQ、Telegram等多平台兼容的支持 LLM 聊天的机器人平台。支持自定义插件扩展。
GNU Affero General Public License v3.0
608 stars 59 forks source link

更易读的配置格式和平台、LLM多实例 #184

Closed Soulter closed 1 month ago

Soulter commented 2 months ago

What's Changed

新配置文件模板

DEFAULT_CONFIG_VERSION_2 = {
    "config_version": 2,
    "platform": [
        {
            "name": "qq_official",
            "enable": False,
            "appid": "",
            "secret": "",
            "enable_group_c2c": True,
            "enable_guild_direct_message": True,
        },
        {
            "name": "nakuru",
            "enable": False,
            "host": "172.0.0.1",
            "port": 5700,
            "websocket_port": 6700,
            "enable_group": True,
            "enable_guild": True,
            "enable_direct_message": True,
            "enable_group_increase": True,
        },
        {
            "name": "aiocqhttp",
            "enable": False,
            "ws_reverse_host": "",
            "ws_reverse_port": 6199,
        }
    ],
    "platform_settings": {
        "unique_session": False,
        "welcome_message_when_join": "",
        "rate_limit": {
            "time": 60,
            "count": 30,
        },
        "reply_prefix": "",
        "forward_threshold": 200, # 转发消息的阈值
    },
    "llm": [
        {
            "name": "openai",
            "enable": True,
            "key": [],
            "api_base": "",
            "prompt_prefix": "",
            "default_personality": "",
            "model_config": {
                "model": "gpt-4o",
                "max_tokens": 6000,
                "temperature": 0.9,
                "top_p": 1,
                "frequency_penalty": 0,
                "presence_penalty": 0,
            },
            "image_generation_model_config": {
                "enable": True,
                "model": "dall-e-3",
                "size": "1024x1024",
                "style": "vivid",
                "quality": "standard",
            }
        },
    ],
    "llm_settings": {
        "wake_prefix": "",
        "web_search": False,
    },
    "content_safety": {
        "baidu_aip": {
            "enable": False,
            "app_id": "",
            "api_key": "",
            "secret_key": "",
        },
        "internal_keywords": {
            "enable": True,
            "extra_keywords": [],
        }
    },
    "wake_prefix": [],
    "t2i": True,
    "dump_history_interval": 10,
    "admins_id": [],
    "https_proxy": "",
    "http_proxy": "",
    "dashboard": {
        "enable": True,
        "username": "",
        "password": "",
    },
}

映射表

MAPPINGS_1_2 = [
    [["qqbot", "enable"], ["platform", 0, "enable"]],
    [["qqbot", "appid"], ["platform", 0, "appid"]],
    [["qqbot", "token"], ["platform", 0, "secret"]],
    [["qqofficial_enable_group_message"], ["platform", 0, "enable_group_c2c"]],
    [["direct_message_mode"], ["platform", 0, "enable_guild_direct_message"]],
    [["gocqbot", "enable"], ["platform", 1, "enable"]],
    [["gocq_host"], ["platform", 1, "host"]],
    [["gocq_http_port"], ["platform", 1, "port"]],
    [["gocq_websocket_port"], ["platform", 1, "websocket_port"]],
    [["gocq_react_group"], ["platform", 1, "enable_group"]],
    [["gocq_react_guild"], ["platform", 1, "enable_guild"]],
    [["gocq_react_friend"], ["platform", 1, "enable_direct_message"]],
    [["gocq_react_group_increase"], ["platform", 1, "enable_group_increase"]],
    [["aiocqhttp", "enable"], ["platform", 2, "enable"]],
    [["aiocqhttp", "ws_reverse_host"], ["platform", 2, "ws_reverse_host"]],
    [["aiocqhttp", "ws_reverse_port"], ["platform", 2, "ws_reverse_port"]],
    [["uniqueSessionMode"], ["platform_settings", "unique_session"]],
    [["qq_welcome"], ["platform_settings", "welcome_message_when_join"]],
    [["limit", "time"], ["platform_settings", "rate_limit", "time"]],
    [["limit", "count"], ["platform_settings", "rate_limit", "count"]],
    [["reply_prefix"], ["platform_settings", "reply_prefix"]],
    [["qq_forward_threshold"], ["platform_settings", "forward_threshold"]],

    [["openai", "key"], ["llm", 0, "key"]],
    [["openai", "api_base"], ["llm", 0, "api_base"]],
    [["openai", "chatGPTConfigs", "model"], ["llm", 0, "model_config", "model"]],
    [["openai", "chatGPTConfigs", "max_tokens"], ["llm", 0, "model_config", "max_tokens"]],
    [["openai", "chatGPTConfigs", "temperature"], ["llm", 0, "model_config", "temperature"]],
    [["openai", "chatGPTConfigs", "top_p"], ["llm", 0, "model_config", "top_p"]],
    [["openai", "chatGPTConfigs", "frequency_penalty"], ["llm", 0, "model_config", "frequency_penalty"]],
    [["openai", "chatGPTConfigs", "presence_penalty"], ["llm", 0, "model_config", "presence_penalty"]],    

    [["default_personality_str"], ["llm", 0, "default_personality"]],
    [["llm_env_prompt"], ["llm", 0, "prompt_prefix"]],
    [["openai_image_generate", "model"], ["llm", 0, "image_generation_model_config", "model"]],
    [["openai_image_generate", "size"], ["llm", 0, "image_generation_model_config", "size"]],
    [["openai_image_generate", "style"], ["llm", 0, "image_generation_model_config", "style"]],
    [["openai_image_generate", "quality"], ["llm", 0, "image_generation_model_config", "quality"]],

    [["llm_wake_prefix"], ["llm_settings", "wake_prefix"]],

    [["baidu_aip", "enable"], ["content_safety", "baidu_aip", "enable"]],
    [["baidu_aip", "app_id"], ["content_safety", "baidu_aip", "app_id"]],
    [["baidu_aip", "api_key"], ["content_safety", "baidu_aip", "api_key"]],
    [["baidu_aip", "secret_key"], ["content_safety", "baidu_aip", "secret_key"]],

    [["qq_pic_mode"], ["t2i"]],
    [["dump_history_interval"], ["dump_history_interval"]],
    [["other_admins"], ["admins_id"]],
    [["http_proxy"], ["http_proxy"]],
    [["https_proxy"], ["https_proxy"]],
    [["dashboard_username"], ["dashboard", "username"]],
    [["dashboard_password"], ["dashboard", "password"]],
    [["nick_qq"], ["wake_prefix"]],
]
Soulter commented 1 month ago

LGTM