summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/retry_provider.py
diff options
context:
space:
mode:
authorrazrab <razrab@PimoLin>2023-10-23 07:25:46 +0200
committerrazrab <razrab@PimoLin>2023-10-23 07:25:46 +0200
commit2b3bc749b39b0c6f3e8921b9e3b2fc52263c568c (patch)
tree7de51129865bd786bdf7b21fa658725a474a8cd8 /g4f/Provider/retry_provider.py
parentAdded code to ignore certain providers in the API (diff)
parent~ | g4f `v-0.1.7.5` (diff)
downloadgpt4free-2b3bc749b39b0c6f3e8921b9e3b2fc52263c568c.tar
gpt4free-2b3bc749b39b0c6f3e8921b9e3b2fc52263c568c.tar.gz
gpt4free-2b3bc749b39b0c6f3e8921b9e3b2fc52263c568c.tar.bz2
gpt4free-2b3bc749b39b0c6f3e8921b9e3b2fc52263c568c.tar.lz
gpt4free-2b3bc749b39b0c6f3e8921b9e3b2fc52263c568c.tar.xz
gpt4free-2b3bc749b39b0c6f3e8921b9e3b2fc52263c568c.tar.zst
gpt4free-2b3bc749b39b0c6f3e8921b9e3b2fc52263c568c.zip
Diffstat (limited to 'g4f/Provider/retry_provider.py')
-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