From 36c8a5846d382dc073b68ff07c8a8bcfb48baf15 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Mon, 2 Jan 2023 21:03:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=8E=B0=E5=9C=A8=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E4=B8=8D=E8=87=AA=E5=8A=A8=E6=A0=B9=E6=8D=AE=E4=BC=B0=E7=AE=97?= =?UTF-8?q?=E7=9A=84=E8=B4=B9=E7=94=A8=E5=88=87=E6=8D=A2apikey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config-template.py | 4 ++++ pkg/openai/keymgr.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config-template.py b/config-template.py index 06367cda..b1025463 100644 --- a/config-template.py +++ b/config-template.py @@ -60,6 +60,10 @@ response_rules = { # 单位:美元 api_key_fee_threshold = 18.0 +# 是否根据估算的使用费用切换api-key +# 设置为False将只在接口报错超额时自动切换 +auto_switch_api_key = False + # 敏感词过滤开关,以同样数量的*代替敏感词回复 # 请在sensitive.json中添加敏感词 sensitive_word_filter = True diff --git a/pkg/openai/keymgr.py b/pkg/openai/keymgr.py index a9d95243..2b1a52e4 100644 --- a/pkg/openai/keymgr.py +++ b/pkg/openai/keymgr.py @@ -86,7 +86,8 @@ class KeysManager: self.fee[md5] += fee - if self.fee[md5] >= self.api_key_fee_threshold: + if self.fee[md5] >= self.api_key_fee_threshold and \ + hasattr(config, 'auto_switch_api_key') and config.auto_switch_api_key: switch_result, key_name = self.auto_switch() # 检查是否切换到新的