summaryrefslogtreecommitdiffstats
path: root/g4f/__init__.py
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner@lohaus.eu>2023-09-12 04:40:10 +0200
committerHeiner Lohaus <heiner@lohaus.eu>2023-09-12 04:40:10 +0200
commit618addd001077d9e4ed4d2a7aa03769a0ee0901b (patch)
tree0a1f1eb3639c34472884d8d3d7bd102b12c891ff /g4f/__init__.py
parentUpdate Readme (diff)
downloadgpt4free-618addd001077d9e4ed4d2a7aa03769a0ee0901b.tar
gpt4free-618addd001077d9e4ed4d2a7aa03769a0ee0901b.tar.gz
gpt4free-618addd001077d9e4ed4d2a7aa03769a0ee0901b.tar.bz2
gpt4free-618addd001077d9e4ed4d2a7aa03769a0ee0901b.tar.lz
gpt4free-618addd001077d9e4ed4d2a7aa03769a0ee0901b.tar.xz
gpt4free-618addd001077d9e4ed4d2a7aa03769a0ee0901b.tar.zst
gpt4free-618addd001077d9e4ed4d2a7aa03769a0ee0901b.zip
Diffstat (limited to 'g4f/__init__.py')
-rw-r--r--g4f/__init__.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/g4f/__init__.py b/g4f/__init__.py
index 065acee6..90b05c85 100644
--- a/g4f/__init__.py
+++ b/g4f/__init__.py
@@ -2,6 +2,7 @@ from __future__ import annotations
from . import models
from .Provider import BaseProvider
from .typing import Any, CreateResult, Union
+import random
logging = False
@@ -13,14 +14,22 @@ class ChatCompletion:
provider : Union[type[BaseProvider], None] = None,
stream : bool = False,
auth : Union[str, None] = None, **kwargs: Any) -> Union[CreateResult, str]:
-
+
if isinstance(model, str):
try:
model = models.ModelUtils.convert[model]
except KeyError:
raise Exception(f'The model: {model} does not exist')
- provider = model.best_provider if provider == None else provider
+
+ if not provider:
+ if isinstance(model.best_provider, tuple):
+ provider = random.choice(model.best_provider)
+ else:
+ provider = model.best_provider
+
+ if not provider:
+ raise Exception(f'No provider found')
if not provider.working:
raise Exception(f'{provider.__name__} is not working')