Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout #1092

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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