summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/retry_provider.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-10-07 22:03:50 +0200
committerGitHub <noreply@github.com>2023-10-07 22:03:50 +0200
commit6334dac211898fb607d0281e9f23176172de4feb (patch)
tree45fad72c866cb03db744ae53e2993a4f31b29f0d /g4f/Provider/retry_provider.py
parent ~ | g4f `v-0.1.5.4` [new gui & interference] (diff)
parentRemove Aivvm from working providers (diff)
downloadgpt4free-6334dac211898fb607d0281e9f23176172de4feb.tar
gpt4free-6334dac211898fb607d0281e9f23176172de4feb.tar.gz
gpt4free-6334dac211898fb607d0281e9f23176172de4feb.tar.bz2
gpt4free-6334dac211898fb607d0281e9f23176172de4feb.tar.lz
gpt4free-6334dac211898fb607d0281e9f23176172de4feb.tar.xz
gpt4free-6334dac211898fb607d0281e9f23176172de4feb.tar.zst
gpt4free-6334dac211898fb607d0281e9f23176172de4feb.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/retry_provider.py32
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