[PR #11946] fix: gemini system prompt with variable raise error #27428

Closed
opened 2026-02-21 20:41:30 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/11946

State: closed
Merged: Yes


Summary

Tip

Close issue syntax: Fixes #<issue number> or Resolves #<issue number>, see documentation for more details.

when add variables into system prompt of LLM node will raise error:

[on_llm_invoke_error]
2024-12-21 12:42:11,077.077 ERROR [Thread-574 (_generate_worker)] [logging_callback.py:169] - Could not create `Blob`, expected `Blob`, `dict` or an `Image` type(`PIL.Image.Image` or `IPython.display.Image`).
Got a: <class 'list'>
Value: [TextPromptMessageContent(type=<PromptMessageContentType.TEXT: 'text'>, data='你是一个友好的AI助理'), TextPromptMessageContent(type=<PromptMessageContentType.TEXT: 'text'>, data='2024-12-21 12:42:11')]
Traceback (most recent call last):
  File "/home/njue/software/code/dify/api/core/model_runtime/model_providers/__base/large_language_model.py", line 110, in invoke
    result = self._invoke(
             ^^^^^^^^^^^^^
  File "/home/njue/software/code/dify/api/core/model_runtime/model_providers/google/llm/llm.py", line 66, in _invoke
    return self._generate(model, credentials, prompt_messages, model_parameters, tools, stop, stream, user)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/njue/software/code/dify/api/core/model_runtime/model_providers/google/llm/llm.py", line 195, in _generate
    content = self._format_message_to_glm_content(msg)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/njue/software/code/dify/api/core/model_runtime/model_providers/google/llm/llm.py", line 407, in _format_message_to_glm_content
    return {"role": "user", "parts": [to_part(message.content)]}
                                      ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/njue/anaconda3/envs/dify/lib/python3.12/site-packages/google/generativeai/types/content_types.py", line 249, in to_part
    return protos.Part(inline_data=to_blob(part))
                                   ^^^^^^^^^^^^^
  File "/home/njue/anaconda3/envs/dify/lib/python3.12/site-packages/google/generativeai/types/content_types.py", line 195, in to_blob
    raise TypeError(
TypeError: Could not create `Blob`, expected `Blob`, `dict` or an `Image` type(`PIL.Image.Image` or `IPython.display.Image`).
Got a: 

also make the system prompt message to google's system_instructions.

Screenshots

Before After
... ...

Checklist

Important

Please review the checklist below before submitting your pull request.

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/11946 **State:** closed **Merged:** Yes --- # Summary > [!Tip] > Close issue syntax: `Fixes #<issue number>` or `Resolves #<issue number>`, see [documentation](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) for more details. when add variables into system prompt of LLM node will raise error: ``` [on_llm_invoke_error] 2024-12-21 12:42:11,077.077 ERROR [Thread-574 (_generate_worker)] [logging_callback.py:169] - Could not create `Blob`, expected `Blob`, `dict` or an `Image` type(`PIL.Image.Image` or `IPython.display.Image`). Got a: <class 'list'> Value: [TextPromptMessageContent(type=<PromptMessageContentType.TEXT: 'text'>, data='你是一个友好的AI助理'), TextPromptMessageContent(type=<PromptMessageContentType.TEXT: 'text'>, data='2024-12-21 12:42:11')] Traceback (most recent call last): File "/home/njue/software/code/dify/api/core/model_runtime/model_providers/__base/large_language_model.py", line 110, in invoke result = self._invoke( ^^^^^^^^^^^^^ File "/home/njue/software/code/dify/api/core/model_runtime/model_providers/google/llm/llm.py", line 66, in _invoke return self._generate(model, credentials, prompt_messages, model_parameters, tools, stop, stream, user) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/njue/software/code/dify/api/core/model_runtime/model_providers/google/llm/llm.py", line 195, in _generate content = self._format_message_to_glm_content(msg) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/njue/software/code/dify/api/core/model_runtime/model_providers/google/llm/llm.py", line 407, in _format_message_to_glm_content return {"role": "user", "parts": [to_part(message.content)]} ^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/njue/anaconda3/envs/dify/lib/python3.12/site-packages/google/generativeai/types/content_types.py", line 249, in to_part return protos.Part(inline_data=to_blob(part)) ^^^^^^^^^^^^^ File "/home/njue/anaconda3/envs/dify/lib/python3.12/site-packages/google/generativeai/types/content_types.py", line 195, in to_blob raise TypeError( TypeError: Could not create `Blob`, expected `Blob`, `dict` or an `Image` type(`PIL.Image.Image` or `IPython.display.Image`). Got a: ``` also make the system prompt message to google's system_instructions. # Screenshots | Before | After | |--------|-------| | ... | ... | # Checklist > [!IMPORTANT] > Please review the checklist below before submitting your pull request. - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:41:30 -05:00
yindo closed this issue 2026-02-21 20:41:30 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#27428