summaryrefslogtreecommitdiffstats
path: root/g4f/client
diff options
context:
space:
mode:
authorkqlio67 <kqlio67@users.noreply.github.com>2024-10-30 15:25:55 +0100
committerkqlio67 <kqlio67@users.noreply.github.com>2024-10-30 15:25:55 +0100
commite6627d8d30fe7dfcf2a111b444f2abb5c4ead1ac (patch)
tree5a06635657ff1f8d2ab2156898ff0bb1fff025f4 /g4f/client
parentfeat(g4f/models.py): add versioning support for model retrieval (diff)
downloadgpt4free-e6627d8d30fe7dfcf2a111b444f2abb5c4ead1ac.tar
gpt4free-e6627d8d30fe7dfcf2a111b444f2abb5c4ead1ac.tar.gz
gpt4free-e6627d8d30fe7dfcf2a111b444f2abb5c4ead1ac.tar.bz2
gpt4free-e6627d8d30fe7dfcf2a111b444f2abb5c4ead1ac.tar.lz
gpt4free-e6627d8d30fe7dfcf2a111b444f2abb5c4ead1ac.tar.xz
gpt4free-e6627d8d30fe7dfcf2a111b444f2abb5c4ead1ac.tar.zst
gpt4free-e6627d8d30fe7dfcf2a111b444f2abb5c4ead1ac.zip
Diffstat (limited to 'g4f/client')
-rw-r--r--g4f/client/client.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/g4f/client/client.py b/g4f/client/client.py
index 07db107a..8e195213 100644
--- a/g4f/client/client.py
+++ b/g4f/client/client.py
@@ -184,12 +184,8 @@ class Completions:
ignore_stream: bool = False,
**kwargs
) -> Union[ChatCompletion, Iterator[ChatCompletionChunk]]:
- # 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.
+ model, provider = get_model_and_provider(
+ model,
self.provider if provider is None else provider,
stream,
ignored,
@@ -200,8 +196,9 @@ 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_name, # We use a model based on the object.
+ model,
messages,
stream=stream,
**filter_none(
@@ -214,7 +211,7 @@ class Completions:
))
else:
response = provider.create_completion(
- model_name, # We use a model from the object.
+ model,
messages,
stream=stream,
**filter_none(
@@ -228,19 +225,21 @@ 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,