Compare commits
6 commits
0a71012709
...
79460e4998
| Author | SHA1 | Date | |
|---|---|---|---|
| 79460e4998 | |||
| 42282ce8cb | |||
| 2611d1bb6d | |||
| 858d127246 | |||
| 307ca38ecc | |||
| 8b5449b1fd |
4 changed files with 8 additions and 14 deletions
|
|
@ -71,9 +71,8 @@ class Provider(ABC):
|
|||
"""Usage percent when provider may switch active account/token."""
|
||||
return None
|
||||
|
||||
def should_prepare_standby(self, usage_percent: int) -> bool:
|
||||
def should_prepare_standby(self) -> bool:
|
||||
"""Whether standby preparation should be triggered for current usage."""
|
||||
_ = usage_percent
|
||||
return False
|
||||
|
||||
async def ensure_standby_account(
|
||||
|
|
|
|||
|
|
@ -122,8 +122,8 @@ class ChatGPTProvider(Provider):
|
|||
return True
|
||||
return await self._create_next_account_under_lock()
|
||||
|
||||
def should_prepare_standby(self, usage_percent: int) -> bool:
|
||||
return usage_percent >= self.prepare_threshold and not bool(load_next_tokens())
|
||||
def should_prepare_standby(self) -> bool:
|
||||
return bool(load_next_tokens())
|
||||
|
||||
async def ensure_standby_account(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ def should_trigger_standby_prepare(provider_name: str, usage_percent: int) -> bo
|
|||
provider = PROVIDERS.get(provider_name)
|
||||
if not provider:
|
||||
return False
|
||||
return provider.should_prepare_standby(usage_percent)
|
||||
return provider.should_prepare_standby()
|
||||
|
||||
|
||||
async def ensure_provider_token_ready(provider_name: str):
|
||||
|
|
@ -88,7 +88,7 @@ async def ensure_standby_task(provider_name: str, usage_percent: int, reason: st
|
|||
if not provider:
|
||||
return
|
||||
|
||||
if not provider.should_prepare_standby(usage_percent):
|
||||
if not provider.should_prepare_standby():
|
||||
return
|
||||
|
||||
try:
|
||||
|
|
@ -212,7 +212,6 @@ async def on_cleanup(app: web.Application):
|
|||
|
||||
|
||||
def create_app() -> web.Application:
|
||||
app = web.Application()
|
||||
app.on_startup.append(on_startup)
|
||||
app.on_cleanup.append(on_cleanup)
|
||||
app.router.add_get("/health", health_handler)
|
||||
|
|
@ -221,7 +220,7 @@ def create_app() -> web.Application:
|
|||
return app
|
||||
|
||||
|
||||
def main():
|
||||
if __name__ == "__main__":
|
||||
logger.info("Starting token service on port %s", PORT)
|
||||
chatgpt_provider = PROVIDERS.get("chatgpt")
|
||||
if chatgpt_provider:
|
||||
|
|
@ -240,7 +239,3 @@ def main():
|
|||
port=PORT,
|
||||
access_log_class=AccessLogger,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ class FakeProvider(Provider):
|
|||
def prepare_threshold(self) -> int:
|
||||
return self._prepare_threshold
|
||||
|
||||
def should_prepare_standby(self, usage_percent: int) -> bool:
|
||||
return usage_percent >= self.prepare_threshold
|
||||
def should_prepare_standby(self) -> bool:
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue