From ccb8c7227f45610e6fae8cda1138a39df14113f2 Mon Sep 17 00:00:00 2001 From: 6vision Date: Mon, 28 Oct 2024 00:32:05 +0800 Subject: [PATCH] Support setting base URL and proxy for Claude model. Also support reset command. --- bot/claudeapi/claude_api_bot.py | 13 +++++-------- plugins/godcmd/godcmd.py | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/bot/claudeapi/claude_api_bot.py b/bot/claudeapi/claude_api_bot.py index cd20800f7..e3e7a2b58 100644 --- a/bot/claudeapi/claude_api_bot.py +++ b/bot/claudeapi/claude_api_bot.py @@ -23,16 +23,13 @@ class ClaudeAPIBot(Bot, OpenAIImage): def __init__(self): super().__init__() + proxy = conf().get("proxy", None) + base_url = conf().get("open_ai_api_base", None) # 复用"open_ai_api_base"参数作为base_url self.claudeClient = anthropic.Anthropic( - api_key=conf().get("claude_api_key") + api_key=conf().get("claude_api_key"), + proxies=proxy if proxy else None, + base_url=base_url if base_url else None ) - openai.api_key = conf().get("open_ai_api_key") - if conf().get("open_ai_api_base"): - openai.api_base = conf().get("open_ai_api_base") - proxy = conf().get("proxy") - if proxy: - openai.proxy = proxy - self.sessions = SessionManager(BaiduWenxinSession, model=conf().get("model") or "text-davinci-003") def reply(self, query, context=None): diff --git a/plugins/godcmd/godcmd.py b/plugins/godcmd/godcmd.py index d6383bfa8..3e9d3eabd 100644 --- a/plugins/godcmd/godcmd.py +++ b/plugins/godcmd/godcmd.py @@ -313,7 +313,7 @@ def on_handle_context(self, e_context: EventContext): except Exception as e: ok, result = False, "你没有设置私有GPT模型" elif cmd == "reset": - if bottype in [const.OPEN_AI, const.CHATGPT, const.CHATGPTONAZURE, const.LINKAI, const.BAIDU, const.XUNFEI, const.QWEN, const.GEMINI, const.ZHIPU_AI]: + if bottype in [const.OPEN_AI, const.CHATGPT, const.CHATGPTONAZURE, const.LINKAI, const.BAIDU, const.XUNFEI, const.QWEN, const.GEMINI, const.ZHIPU_AI, const.CLAUDEAPI]: bot.sessions.clear_session(session_id) if Bridge().chat_bots.get(bottype): Bridge().chat_bots.get(bottype).sessions.clear_session(session_id)