diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-09-12 11:37:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-12 11:37:20 +0200 |
commit | cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba (patch) | |
tree | 0a1f1eb3639c34472884d8d3d7bd102b12c891ff /g4f/__init__.py | |
parent | ~ | 0.0.2.8 (diff) | |
parent | Disable not working providers: (diff) | |
download | gpt4free-cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba.tar gpt4free-cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba.tar.gz gpt4free-cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba.tar.bz2 gpt4free-cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba.tar.lz gpt4free-cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba.tar.xz gpt4free-cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba.tar.zst gpt4free-cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/__init__.py | 13 |
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') |