From c16b153fd2503120ca6690759342917b3b1fa095 Mon Sep 17 00:00:00 2001 From: Aleh Date: Sat, 9 Nov 2024 10:33:15 +0300 Subject: added unexpected finishReason handler --- g4f/Provider/GeminiPro.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'g4f') diff --git a/g4f/Provider/GeminiPro.py b/g4f/Provider/GeminiPro.py index 06bf69ee..e7174c59 100644 --- a/g4f/Provider/GeminiPro.py +++ b/g4f/Provider/GeminiPro.py @@ -104,4 +104,8 @@ class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin): lines.append(chunk) else: data = await response.json() - yield data["candidates"][0]["content"]["parts"][0]["text"] \ No newline at end of file + candidate = data["candidates"][0] + if candidate["finishReason"] == "STOP": + yield candidate["content"]["parts"][0]["text"] + else: + yield candidate["finishReason"] + ' ' + candidate["safetyRatings"] \ No newline at end of file -- cgit v1.2.3