feat: 不再预先计算前文token数而是在报错时提醒用户重置

This commit is contained in:
RockChinQ
2024-03-12 16:04:11 +08:00
parent a398c6f311
commit 1d963d0f0c
16 changed files with 25 additions and 144 deletions
+27
View File
@@ -0,0 +1,27 @@
from __future__ import annotations
import typing
import pydantic
class TokenManager():
"""鉴权 Token 管理器
"""
provider: str
tokens: list[str]
using_token_index: typing.Optional[int] = 0
def __init__(self, provider: str, tokens: list[str]):
self.provider = provider
self.tokens = tokens
self.using_token_index = 0
def get_token(self) -> str:
return self.tokens[self.using_token_index]
def next_token(self):
self.using_token_index = (self.using_token_index + 1) % len(self.tokens)