diff options
author | kqlio67 <kqlio67@users.noreply.github.com> | 2024-10-30 13:09:16 +0100 |
---|---|---|
committer | kqlio67 <kqlio67@users.noreply.github.com> | 2024-10-30 13:09:16 +0100 |
commit | b11cf3ab4babb0493856c194a542b7b70d1a7728 (patch) | |
tree | 42d214123956bc2200215a23a1da063c26144cb3 /g4f | |
parent | Update (docs/) (diff) | |
download | gpt4free-b11cf3ab4babb0493856c194a542b7b70d1a7728.tar gpt4free-b11cf3ab4babb0493856c194a542b7b70d1a7728.tar.gz gpt4free-b11cf3ab4babb0493856c194a542b7b70d1a7728.tar.bz2 gpt4free-b11cf3ab4babb0493856c194a542b7b70d1a7728.tar.lz gpt4free-b11cf3ab4babb0493856c194a542b7b70d1a7728.tar.xz gpt4free-b11cf3ab4babb0493856c194a542b7b70d1a7728.tar.zst gpt4free-b11cf3ab4babb0493856c194a542b7b70d1a7728.zip |
Diffstat (limited to 'g4f')
-rw-r--r-- | g4f/client/client.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/g4f/client/client.py b/g4f/client/client.py index 8e195213..07db107a 100644 --- a/g4f/client/client.py +++ b/g4f/client/client.py @@ -184,8 +184,12 @@ class Completions: ignore_stream: bool = False, **kwargs ) -> Union[ChatCompletion, Iterator[ChatCompletionChunk]]: - model, provider = get_model_and_provider( - model, + # We use ModelUtils to obtain the model object. + model_instance = ModelUtils.get_model(model) + + # We receive the model and the provider. + model_name, provider = get_model_and_provider( + model_instance.name, # We use the model name from the object. self.provider if provider is None else provider, stream, ignored, @@ -196,9 +200,8 @@ class Completions: stop = [stop] if isinstance(stop, str) else stop if asyncio.iscoroutinefunction(provider.create_completion): - # Run the asynchronous function in an event loop response = asyncio.run(provider.create_completion( - model, + model_name, # We use a model based on the object. messages, stream=stream, **filter_none( @@ -211,7 +214,7 @@ class Completions: )) else: response = provider.create_completion( - model, + model_name, # We use a model from the object. messages, stream=stream, **filter_none( @@ -225,21 +228,19 @@ class Completions: if stream: if hasattr(response, '__aiter__'): - # It's an async generator, wrap it into a sync iterator response = to_sync_iter(response) - # Now 'response' is an iterator response = iter_response(response, stream, response_format, max_tokens, stop) response = iter_append_model_and_provider(response) return response else: if hasattr(response, '__aiter__'): - # If response is an async generator, collect it into a list response = list(to_sync_iter(response)) response = iter_response(response, stream, response_format, max_tokens, stop) response = iter_append_model_and_provider(response) return next(response) + async def async_create( self, messages: Messages, |