Skip to content

Commit b9aa7f0

Browse files
authored
fix: fix empty part to call gemini (#2367)
1 parent 5e7947b commit b9aa7f0

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

models/gemini/manifest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ resource:
3434
tool:
3535
enabled: true
3636
type: plugin
37-
version: 0.7.2
37+
version: 0.7.3

models/gemini/models/llm/llm.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,9 @@ def build_parts(
578578

579579
# Handle text content (remove thinking tags)
580580
if message.content:
581-
parts.extend(build_parts(message.content, is_assistant_tree=True))
581+
part = build_parts(message.content, is_assistant_tree=True)
582+
if part:
583+
parts.extend(part)
582584

583585
# Handle tool calls
584586
# https://ai.google.dev/gemini-api/docs/function-calling?hl=zh-cn&example=chart#how-it-works
@@ -590,6 +592,10 @@ def build_parts(
590592
_unsafe_part.thought_signature = DEFAULT_THOUGHT_SIGNATURE
591593
parts.append(_unsafe_part)
592594

595+
# Filter out assistant messages with empty parts to avoid invalid requests
596+
if not parts:
597+
return None
598+
593599
return types.Content(role="model", parts=parts)
594600

595601
elif isinstance(message, SystemPromptMessage):
@@ -709,7 +715,7 @@ def _handle_generate_stream_response(
709715
if (
710716
not chunk.candidates
711717
or not chunk.candidates[0].content
712-
or not chunk.candidates[0].content.parts
718+
or (not chunk.candidates[0].content.parts and not chunk.candidates[0].finish_reason)
713719
):
714720
continue
715721
candidate = chunk.candidates[0]

models/gemini/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ urllib3==2.6.0
184184
# via requests
185185
websockets==15.0.1
186186
# via google-genai
187-
werkzeug==3.1.4
187+
werkzeug>=3.0.3,<3.1.dev0
188188
# via
189189
# dify-plugin
190190
# flask

0 commit comments

Comments
 (0)