refactor: 将MAX_FAILURES配置移至settings并更新KeyManager以使用该配置

This commit is contained in:
yinpeng
2025-02-04 21:51:11 +08:00
parent 97e601a176
commit b465fd1598
2 changed files with 3 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ class Settings(BaseSettings):
SHOW_SEARCH_LINK: bool = True
SHOW_THINKING_PROCESS: bool = True
AUTH_TOKEN: str = ""
MAX_FAILURES: int = 3
def __init__(self):
super().__init__()

View File

@@ -2,6 +2,7 @@ import asyncio
from itertools import cycle
from typing import Dict
from app.core.logger import get_key_manager_logger
from app.core.config import settings
logger = get_key_manager_logger()
@@ -13,7 +14,7 @@ class KeyManager:
self.key_cycle_lock = asyncio.Lock()
self.failure_count_lock = asyncio.Lock()
self.key_failure_counts: Dict[str, int] = {key: 0 for key in api_keys}
self.MAX_FAILURES = 10
self.MAX_FAILURES = settings.MAX_FAILURES
async def get_next_key(self) -> str:
"""获取下一个API key"""