Skip to content

fix: normalize text-only prompt atoms in deepseek and tongyi#2762

Open
LeekJay wants to merge 2 commits intolanggenius:mainfrom
LeekJay:fix/textpromptmessagecontent-normalization
Open

fix: normalize text-only prompt atoms in deepseek and tongyi#2762
LeekJay wants to merge 2 commits intolanggenius:mainfrom
LeekJay:fix/textpromptmessagecontent-normalization

Conversation

@LeekJay
Copy link
Copy Markdown

@LeekJay LeekJay commented Mar 18, 2026

Summary

This PR normalizes prompt message content in the deepseek and tongyi official plugins before provider-specific conversion runs.

It fixes a compatibility issue where Dify can pass prompt content as list[TextPromptMessageContent], which currently leaks into JSON serialization or provider adapters and causes runtime failures such as:

  • Object of type TextPromptMessageContent is not JSON serializable
  • Unsupported atom data type: <class 'dify_plugin.entities.model.message.TextPromptMessageContent'>

This is the same failure pattern we reproduced on Dify 1.13.1 with:

  • langgenius/deepseek:0.0.11
  • langgenius/tongyi:0.1.33

Related issues:
FIx #2753
Fix #2761

What changed

  • Added _normalize_text_content() helper to deepseek and tongyi LLM implementations.
  • Added _normalize_prompt_messages() helper to copy prompt messages and collapse pure text atom lists into plain strings.
  • Invoked normalization before the existing provider-specific message cleanup / conversion logic.

Why this is safe

The change is intentionally narrow:

  • It only converts content when the message content is a list and every item is TextPromptMessageContent.
  • Mixed multimodal content remains untouched.
  • Existing provider-specific handling for images, audio, video, documents, tool calls, and reasoning content is preserved.

Validation

  • python -m py_compile models/deepseek/models/llm/llm.py models/tongyi/models/llm/llm.py
  • Reproduced the original failure in a live Dify 1.13.1 deployment, applied equivalent hot patches, restarted plugin daemon / workers, and confirmed the workflow stopped producing TextPromptMessageContent, UnsupportedDataType, and PluginInvokeError log entries.

…onversion

This change fixes a plugin compatibility issue where Dify can forward
prompt content as TextPromptMessageContent atoms instead of plain strings.
Without normalization, deepseek and tongyi may pass those objects into
provider serialization paths and fail at runtime.

变更:
- add text-only prompt content normalization in deepseek before invoke cleanup
- add text-only prompt content normalization in tongyi before provider conversion
- keep mixed multimodal content untouched so existing provider handling remains intact

影响:
- prevents TextPromptMessageContent serialization failures in plugin-based llm calls
- reduces runtime PluginInvokeError and UnsupportedDataType failures for deepseek and tongyi workflows
- keeps provider behavior unchanged for non-text and mixed-content prompts
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 18, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a compatibility issue within the Deepseek and Tongyi LLM plugins where TextPromptMessageContent objects were not being correctly serialized or handled by provider adapters, leading to runtime failures. The solution introduces a pre-processing step to normalize prompt message content by converting lists composed exclusively of TextPromptMessageContent into plain strings. This change specifically targets text-only content, preserving multimodal content and existing provider-specific logic, thereby preventing serialization errors without broader impact.

Highlights

  • Text Content Normalization Helper: Introduced a static helper method, _normalize_text_content(), in both Deepseek and Tongyi LLM implementations. This method is responsible for converting lists where every item is a TextPromptMessageContent object into a single concatenated string, extracting the data attribute from each item.
  • Prompt Message Normalization: Implemented _normalize_prompt_messages() to iterate through a list of PromptMessage objects. For each message, it creates a copy and applies the _normalize_text_content() helper to its content, ensuring that only pure text atom lists are converted.
  • Integration into LLM Invocation: The newly created _normalize_prompt_messages() method is now invoked early in the _invoke method for Deepseek and the _generate method for Tongyi. This ensures that prompt messages are normalized before any existing provider-specific message cleanup or conversion logic runs, preventing downstream errors.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot Bot added the bug Something isn't working label Mar 18, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a runtime failure by normalizing text-only prompt atoms in the deepseek and tongyi plugins. The changes involve adding helper functions to convert lists of TextPromptMessageContent into single strings before they are processed by the provider-specific adapters.

My review has identified a couple of areas for improvement:

  • There is significant code duplication between the deepseek and tongyi models. The new helper functions are identical in both files. Consolidating this logic into a shared module or base class would improve maintainability.
  • The new _normalize_text_content function is missing type hints, which is inconsistent with the surrounding code. Adding them would improve code clarity and maintainability.

Overall, the fix is well-described and addresses the issue. The suggested improvements are aimed at enhancing code quality.

Comment thread models/deepseek/models/llm/llm.py
Comment thread models/deepseek/models/llm/llm.py
Comment thread models/tongyi/models/llm/llm.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

2 participants