From ed5327b08c2961cd3ac51a23d9e1e3ef13ac3adb Mon Sep 17 00:00:00 2001 From: wangshuo16 Date: Fri, 25 Oct 2024 12:21:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E5=91=BD=E4=BB=A4=E4=BB=A5=E5=85=A8=E5=B1=80=E8=AE=BE?= =?UTF-8?q?=E7=BD=AEOpenAI=E7=9A=84api=5Fbase=E3=80=81api=5Fkey=E5=92=8CGP?= =?UTF-8?q?T=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/godcmd/godcmd.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/plugins/godcmd/godcmd.py b/plugins/godcmd/godcmd.py index d6383bfa8..768df8f51 100644 --- a/plugins/godcmd/godcmd.py +++ b/plugins/godcmd/godcmd.py @@ -131,6 +131,20 @@ "alias": ["debug", "调试模式", "DEBUG"], "desc": "开启机器调试日志", }, + "admin_set_openai_api_base": { + "alias": ["admin_set_openai_api_base"], + "args": ["api_key"], + "desc": "全局设置OpenAI的api_base", + }, + "admin_set_openai_api_key": { + "alias": ["admin_set_openai_api_key"], + "args": ["api_key"], + "desc": "全局设置OpenAI的api_key", + }, + "admin_set_gpt_model": { + "alias": ["admin_set_gpt_model"], + "desc": "全局设置模型", + }, } @@ -336,7 +350,7 @@ def on_handle_context(self, e_context: EventContext): ok, result = True, "服务已恢复" elif cmd == "reconf": load_config() - ok, result = True, "配置已重载" + ok, result = True, "配置已重载(私有or管理配置,需要重新设置)" elif cmd == "resetall": if bottype in [const.OPEN_AI, const.CHATGPT, const.CHATGPTONAZURE, const.LINKAI, const.BAIDU, const.XUNFEI, const.QWEN, const.GEMINI, const.ZHIPU_AI, const.MOONSHOT]: @@ -418,6 +432,25 @@ def on_handle_context(self, e_context: EventContext): ok, result = False, "请提供插件名" else: ok, result = PluginManager().update_plugin(args[0]) + elif cmd == "admin_set_openai_api_base": + if len(args) == 1: + conf()["open_ai_api_base"] = args[0] + ok, result = True, "全局设置OpenAI的api_base为" + args[0] + else: + ok, result = False, "请提供一个api_base" + elif cmd == "admin_set_openai_api_key": + if len(args) == 1: + conf()["open_ai_api_key"] = args[0] + ok, result = True, "全局设置OpenAI的api_key为" + args[0] + else: + ok, result = False, "请提供一个api_key" + elif cmd == "admin_set_gpt_model": + if len(args) == 1: + conf()["model"] = self.model_mapping(args[0]) + Bridge().reset_bot() + ok, result = True, "全局设置GPT模型为" + args[0] + else: + ok, result = False, "请提供一个GPT模型" logger.debug("[Godcmd] admin command: %s by %s" % (cmd, user)) else: ok, result = False, "需要管理员权限才能执行该指令"