diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-02-09 05:53:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-09 05:53:47 +0100 |
commit | 999bc2d617a70ad70d185ba59c108d01794f9b5f (patch) | |
tree | d27a53d1549b352c8ab723680d51f01db6ae9d5c /g4f/__init__.py | |
parent | Merge pull request #1554 from Masha/patch-1 (diff) | |
parent | Add example for Image Upload & Generation (diff) | |
download | gpt4free-999bc2d617a70ad70d185ba59c108d01794f9b5f.tar gpt4free-999bc2d617a70ad70d185ba59c108d01794f9b5f.tar.gz gpt4free-999bc2d617a70ad70d185ba59c108d01794f9b5f.tar.bz2 gpt4free-999bc2d617a70ad70d185ba59c108d01794f9b5f.tar.lz gpt4free-999bc2d617a70ad70d185ba59c108d01794f9b5f.tar.xz gpt4free-999bc2d617a70ad70d185ba59c108d01794f9b5f.tar.zst gpt4free-999bc2d617a70ad70d185ba59c108d01794f9b5f.zip |
Diffstat (limited to 'g4f/__init__.py')
-rw-r--r-- | g4f/__init__.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/g4f/__init__.py b/g4f/__init__.py index 173a1688..34c8aa19 100644 --- a/g4f/__init__.py +++ b/g4f/__init__.py @@ -91,7 +91,7 @@ class ChatCompletion: auth : Union[str, None] = None, ignored : list[str] = None, ignore_working: bool = False, - ignore_stream_and_auth: bool = False, + ignore_stream: bool = False, patch_provider: callable = None, **kwargs) -> Union[CreateResult, str]: """ @@ -105,7 +105,7 @@ class ChatCompletion: auth (Union[str, None], optional): Authentication token or credentials, if required. ignored (list[str], optional): List of provider names to be ignored. ignore_working (bool, optional): If True, ignores the working status of the provider. - ignore_stream_and_auth (bool, optional): If True, ignores the stream and authentication requirement checks. + ignore_stream (bool, optional): If True, ignores the stream and authentication requirement checks. patch_provider (callable, optional): Function to modify the provider. **kwargs: Additional keyword arguments. @@ -118,10 +118,11 @@ class ChatCompletion: ProviderNotWorkingError: If the provider is not operational. StreamNotSupportedError: If streaming is requested but not supported by the provider. """ - model, provider = get_model_and_provider(model, provider, stream, ignored, ignore_working, ignore_stream_and_auth) - - if not ignore_stream_and_auth and provider.needs_auth and not auth: - raise AuthenticationRequiredError(f'{provider.__name__} requires authentication (use auth=\'cookie or token or jwt ...\' param)') + model, provider = get_model_and_provider( + model, provider, stream, + ignored, ignore_working, + ignore_stream or kwargs.get("ignore_stream_and_auth") + ) if auth: kwargs['auth'] = auth @@ -135,7 +136,7 @@ class ChatCompletion: provider = patch_provider(provider) result = provider.create_completion(model, messages, stream, **kwargs) - return result if stream else ''.join(result) + return result if stream else ''.join([str(chunk) for chunk in result]) @staticmethod def create_async(model : Union[Model, str], |