mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-09-12 08:29:30 -04:00
Add timeout
This commit is contained in:
parent
2e68a4b1d4
commit
24f7495f24
@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import random
|
import random
|
||||||
from typing import List, Type, Dict
|
from typing import List, Type, Dict
|
||||||
from ..typing import CreateResult, Messages
|
from ..typing import CreateResult, Messages
|
||||||
@ -68,7 +69,11 @@ class RetryProvider(AsyncProvider):
|
|||||||
self.exceptions: Dict[str, Exception] = {}
|
self.exceptions: Dict[str, Exception] = {}
|
||||||
for provider in providers:
|
for provider in providers:
|
||||||
try:
|
try:
|
||||||
return await provider.create_async(model, messages, **kwargs)
|
return await asyncio.wait_for(provider.create_async(model, messages, **kwargs), timeout=60)
|
||||||
|
except asyncio.TimeoutError as e:
|
||||||
|
self.exceptions[provider.__name__] = e
|
||||||
|
if logging:
|
||||||
|
print(f"{provider.__name__}: TimeoutError: {e}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.exceptions[provider.__name__] = e
|
self.exceptions[provider.__name__] = e
|
||||||
if logging:
|
if logging:
|
||||||
|
Loading…
Reference in New Issue
Block a user