diff options
Diffstat (limited to '')
-rw-r--r-- | g4f/Provider/retry_provider.py | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/g4f/Provider/retry_provider.py b/g4f/Provider/retry_provider.py index c1672aba..b49020b2 100644 --- a/g4f/Provider/retry_provider.py +++ b/g4f/Provider/retry_provider.py @@ -1,33 +1,33 @@ from __future__ import annotations import random - +from typing import List, Type, Dict from ..typing import CreateResult from .base_provider import BaseProvider, AsyncProvider from ..debug import logging class RetryProvider(AsyncProvider): - __name__ = "RetryProvider" - working = True - needs_auth = False - supports_stream = True - supports_gpt_35_turbo = False - supports_gpt_4 = False + __name__: str = "RetryProvider" + working: bool = True + needs_auth: bool = False + supports_stream: bool = True + supports_gpt_35_turbo: bool = False + supports_gpt_4: bool = False def __init__( self, - providers: list[type[BaseProvider]], + providers: List[Type[BaseProvider]], shuffle: bool = True ) -> None: - self.providers = providers - self.shuffle = shuffle + self.providers: List[Type[BaseProvider]] = providers + self.shuffle: bool = shuffle def create_completion( self, model: str, - messages: list[dict[str, str]], + messages: List[Dict[str, str]], stream: bool = False, **kwargs ) -> CreateResult: @@ -38,8 +38,8 @@ class RetryProvider(AsyncProvider): if self.shuffle: random.shuffle(providers) - self.exceptions = {} - started = False + self.exceptions: Dict[str, Exception] = {} + started: bool = False for provider in providers: try: if logging: @@ -61,14 +61,14 @@ class RetryProvider(AsyncProvider): async def create_async( self, model: str, - messages: list[dict[str, str]], + messages: List[Dict[str, str]], **kwargs ) -> str: providers = [provider for provider in self.providers] if self.shuffle: random.shuffle(providers) - self.exceptions = {} + self.exceptions: Dict[str, Exception] = {} for provider in providers: try: return await provider.create_async(model, messages, **kwargs) @@ -79,7 +79,7 @@ class RetryProvider(AsyncProvider): self.raise_exceptions() - def raise_exceptions(self): + def raise_exceptions(self) -> None: if self.exceptions: raise RuntimeError("\n".join(["All providers failed:"] + [ f"{p}: {self.exceptions[p].__class__.__name__}: {self.exceptions[p]}" for p in self.exceptions |