diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-04-06 01:05:00 +0200 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-04-06 01:05:00 +0200 |
commit | d44b39b31c83c6a4bc636bea931275702c700feb (patch) | |
tree | 8967aa34d2e2f9fa7aa1d86131f524ddd3925ad8 /g4f/client.py | |
parent | Add authless OpenaiChat (diff) | |
download | gpt4free-d44b39b31c83c6a4bc636bea931275702c700feb.tar gpt4free-d44b39b31c83c6a4bc636bea931275702c700feb.tar.gz gpt4free-d44b39b31c83c6a4bc636bea931275702c700feb.tar.bz2 gpt4free-d44b39b31c83c6a4bc636bea931275702c700feb.tar.lz gpt4free-d44b39b31c83c6a4bc636bea931275702c700feb.tar.xz gpt4free-d44b39b31c83c6a4bc636bea931275702c700feb.tar.zst gpt4free-d44b39b31c83c6a4bc636bea931275702c700feb.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/client.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/g4f/client.py b/g4f/client.py index d7ceb009..2c4fe788 100644 --- a/g4f/client.py +++ b/g4f/client.py @@ -8,7 +8,7 @@ import string from .stubs import ChatCompletion, ChatCompletionChunk, Image, ImagesResponse from .typing import Union, Iterator, Messages, ImageType -from .providers.types import BaseProvider, ProviderType +from .providers.types import BaseProvider, ProviderType, FinishReason from .image import ImageResponse as ImageProviderResponse from .errors import NoImageResponseError, RateLimitError, MissingAuthError from . import get_model_and_provider, get_last_provider @@ -47,6 +47,9 @@ def iter_response( finish_reason = None completion_id = ''.join(random.choices(string.ascii_letters + string.digits, k=28)) for idx, chunk in enumerate(response): + if isinstance(chunk, FinishReason): + finish_reason = chunk.reason + break content += str(chunk) if max_tokens is not None and idx + 1 >= max_tokens: finish_reason = "length" |