返回提交历史
Modified
g4f/providers/base_provider.py
+10
-6
XFEstudio/gpt4free
Enhance timeout error messaging in Async providers to include provider name for better debugging
671c0fcf
代码差异
1 个文件
+10
-6
@@ -16,7 +16,7 @@ except ImportError:
16
16
17
17
from ..typing import CreateResult, AsyncResult, Messages
18
18
from .types import BaseProvider
19
from .asyncio import get_running_loop, to_sync_generator, to_async_iterator, await_callback
19
from .asyncio import get_running_loop, to_sync_generator, to_async_iterator
20
20
from .response import BaseConversation, AuthResult
21
21
from .helper import concat_chunks
22
22
from ..cookies import get_cookies_dir
@@ -121,9 +121,10 @@ class AbstractProvider(BaseProvider):
121
121
return concat_chunks(cls.create_completion(model, messages, **kwargs))
122
122
try:
123
123
return await asyncio.wait_for(
124
loop.run_in_executor(executor, create_func), timeout=timeout)
124
loop.run_in_executor(executor, create_func), timeout=timeout
125
)
125
126
except TimeoutError as e:
126
raise TimeoutError("The operation timed out after {} seconds".format(timeout)) from e
127
raise TimeoutError("The operation timed out after {} seconds in {}".format(timeout, cls.__name__)) from e
127
128
128
129
@classmethod
129
130
def create_function(cls, *args, **kwargs) -> CreateResult:
@@ -358,7 +359,7 @@ class AsyncGeneratorProvider(AbstractProvider):
358
359
timeout=timeout
359
360
)
360
361
except TimeoutError as e:
361
raise TimeoutError("The operation timed out after {} seconds".format(timeout)) from e
362
raise TimeoutError("The operation timed out after {} seconds in {}".format(timeout, cls.__name__)) from e
362
363
except StopAsyncIteration:
363
364
break
364
365
else:
@@ -525,12 +526,15 @@ class AsyncAuthedProvider(AsyncGeneratorProvider, AuthFileMixin):
525
526
auth_result = cls.get_auth_result()
526
527
response = to_async_iterator(cls.create_authed(model, messages, **kwargs, auth_result=auth_result))
527
528
if "stream_timeout" in kwargs or "timeout" in kwargs:
529
timeout = kwargs.get("stream_timeout") if cls.use_stream_timeout else kwargs.get("timeout")
528
530
while True:
529
531
try:
530
yield await await_callback(
532
yield await asyncio.wait_for(
531
533
response.__anext__(),
532
timeout=kwargs.get("stream_timeout") if cls.use_stream_timeout else kwargs.get("timeout")
534
timeout=timeout
533
535
)
536
except TimeoutError as e:
537
raise TimeoutError("The operation timed out after {} seconds in {}".format(timeout, cls.__name__)) from e
534
538
except StopAsyncIteration:
535
539
break
536
540
else: