summaryrefslogtreecommitdiffstats
path: root/g4f/client.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-04-06 03:10:36 +0200
committerGitHub <noreply@github.com>2024-04-06 03:10:36 +0200
commit9d23ada968d7732317c8d851ba0c5f1295706f4c (patch)
tree60beaccf6b583663d75f9381cfc0395e4b1d3be6 /g4f/client.py
parentMerge pull request #1789 from hlohaus/free (diff)
parentFix unittests (diff)
downloadgpt4free-9d23ada968d7732317c8d851ba0c5f1295706f4c.tar
gpt4free-9d23ada968d7732317c8d851ba0c5f1295706f4c.tar.gz
gpt4free-9d23ada968d7732317c8d851ba0c5f1295706f4c.tar.bz2
gpt4free-9d23ada968d7732317c8d851ba0c5f1295706f4c.tar.lz
gpt4free-9d23ada968d7732317c8d851ba0c5f1295706f4c.tar.xz
gpt4free-9d23ada968d7732317c8d851ba0c5f1295706f4c.tar.zst
gpt4free-9d23ada968d7732317c8d851ba0c5f1295706f4c.zip
Diffstat (limited to 'g4f/client.py')
-rw-r--r--g4f/client.py5
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"