Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gemini system prompt with variable raise error #11946

Merged
merged 9 commits into from
Dec 21, 2024

Conversation

hjlarry
Copy link
Contributor

@hjlarry hjlarry commented Dec 21, 2024

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

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Dec 21, 2024
Copy link
Member

@laipz8200 laipz8200 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 21, 2024
@laipz8200 laipz8200 merged commit 366857c into langgenius:main Dec 21, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants