summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/retry_provider.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--g4f/Provider/retry_provider.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/g4f/Provider/retry_provider.py b/g4f/Provider/retry_provider.py
index ee342315..5979e15b 100644
--- a/g4f/Provider/retry_provider.py
+++ b/g4f/Provider/retry_provider.py
@@ -5,13 +5,13 @@ import random
from typing import List, Type, Dict
from ..typing import CreateResult, Messages
from .base_provider import BaseProvider, AsyncProvider
+from .. import debug
class RetryProvider(AsyncProvider):
__name__: str = "RetryProvider"
working: bool = True
supports_stream: bool = True
- logging: bool = False
def __init__(
self,
@@ -39,7 +39,7 @@ class RetryProvider(AsyncProvider):
started: bool = False
for provider in providers:
try:
- if self.logging:
+ if debug.logging:
print(f"Using {provider.__name__} provider")
for token in provider.create_completion(model, messages, stream, **kwargs):
@@ -51,7 +51,7 @@ class RetryProvider(AsyncProvider):
except Exception as e:
self.exceptions[provider.__name__] = e
- if self.logging:
+ if debug.logging:
print(f"{provider.__name__}: {e.__class__.__name__}: {e}")
if started:
raise e
@@ -71,22 +71,21 @@ class RetryProvider(AsyncProvider):
self.exceptions: Dict[str, Exception] = {}
for provider in providers:
try:
- return await asyncio.wait_for(provider.create_async(model, messages, **kwargs), timeout=60)
- except asyncio.TimeoutError as e:
- self.exceptions[provider.__name__] = e
- if self.logging:
- print(f"{provider.__name__}: TimeoutError: {e}")
+ return await asyncio.wait_for(
+ provider.create_async(model, messages, **kwargs),
+ timeout=kwargs.get("timeout", 60)
+ )
except Exception as e:
self.exceptions[provider.__name__] = e
- if self.logging:
+ if debug.logging:
print(f"{provider.__name__}: {e.__class__.__name__}: {e}")
self.raise_exceptions()
def raise_exceptions(self) -> None:
if self.exceptions:
- raise RuntimeError("\n".join(["All providers failed:"] + [
+ raise RuntimeError("\n".join(["RetryProvider failed:"] + [
f"{p}: {self.exceptions[p].__class__.__name__}: {self.exceptions[p]}" for p in self.exceptions
]))
- raise RuntimeError("No provider found") \ No newline at end of file
+ raise RuntimeError("RetryProvider: No provider found") \ No newline at end of file