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() # 检查是否切换到新的