Skip to content

Commit

Permalink
~ | Merge pull request xtekky#1092 from ostix360/main
Browse files Browse the repository at this point in the history
Add timeout
  • Loading branch information
xtekky authored Oct 18, 2023
2 parents 2e68a4b + 24f7495 commit 591e60e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion g4f/Provider/retry_provider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
import random
from typing import List, Type, Dict
from ..typing import CreateResult, Messages
Expand Down Expand Up @@ -68,7 +69,11 @@ async def create_async(
self.exceptions: Dict[str, Exception] = {}
for provider in providers:
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:
self.exceptions[provider.__name__] = e
if logging:
Expand Down

0 comments on commit 591e60e

Please sign in to comment.