diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-09-19 00:54:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-19 00:54:28 +0200 |
commit | a54291cb7c9dbaf3d092e62f49e0186ee1be0aee (patch) | |
tree | f901c6b0cada1b04021d1fd62f8bf45029786949 /g4f/__init__.py | |
parent | Merge branch 'main' of https://github.com/xtekky/gpt4free (diff) | |
parent | Check supports_stream in best_providers list (diff) | |
download | gpt4free-a54291cb7c9dbaf3d092e62f49e0186ee1be0aee.tar gpt4free-a54291cb7c9dbaf3d092e62f49e0186ee1be0aee.tar.gz gpt4free-a54291cb7c9dbaf3d092e62f49e0186ee1be0aee.tar.bz2 gpt4free-a54291cb7c9dbaf3d092e62f49e0186ee1be0aee.tar.lz gpt4free-a54291cb7c9dbaf3d092e62f49e0186ee1be0aee.tar.xz gpt4free-a54291cb7c9dbaf3d092e62f49e0186ee1be0aee.tar.zst gpt4free-a54291cb7c9dbaf3d092e62f49e0186ee1be0aee.zip |
Diffstat (limited to 'g4f/__init__.py')
-rw-r--r-- | g4f/__init__.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/g4f/__init__.py b/g4f/__init__.py index d8681297..a49e60e9 100644 --- a/g4f/__init__.py +++ b/g4f/__init__.py @@ -16,14 +16,17 @@ class ChatCompletion: auth : Union[str, None] = None, **kwargs: Any) -> Union[CreateResult, str]: if isinstance(model, str): - try: + if model in models.ModelUtils.convert: model = models.ModelUtils.convert[model] - except KeyError: + else: raise Exception(f'The model: {model} does not exist') if not provider: if isinstance(model.best_provider, list): - provider = random.choice(model.best_provider) + if stream: + provider = random.choice([p for p in model.best_provider if p.supports_stream]) + else: + provider = random.choice(model.best_provider) else: provider = model.best_provider |