100% Reproducible: Character Loss in Stream Output Due to replace Method [ tongyi plugin 0.25. with deepseek-v3 model] #309

Closed
opened 2026-02-16 10:18:55 -05:00 by yindo · 4 comments
Owner

Originally created by @zhouzhou0322 on GitHub (May 22, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues Dify issues & Dify Official Plugins, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.4

Plugin version

tongyi plugin 0.25, when use deepseek-v3 model.

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

This happens when use tongyi plugin, select deepseek-v3 model. other model is fine. Only deepseek-v3 have problem.

Image

https://github.com/langgenius/dify-official-plugins/blob/main/models/tongyi/models/llm/llm.py

  1. docker run dify
  2. install tonyyi plugin and choose deepseek v3 model
  3. use prompt below: https://fscdn.xyxy.com/fs41/M01/98/5B/CgRReWaUiy-
    AQ8W8AAS6w3U2x-Q913.png. return me the url I gave it to u, make sure theres no character loss
  4. notice theres a R and an A lost in the url that dify response.

how problem found

I found url sometimes changed when llm give it to me. it turns out its the plugin problem.

Image

Notice there is a R and an A lost in the response.


Problem Description

When handling stream output, the use of full_text = resp_content.replace(full_text, "" 1) causes character loss. Specifically:

  • If full_text is "aaR" and resp_content is "aaRRe", after the replacement, "aaRRe" becomes "aaRe", resulting in character loss (e.g., "RR" becomes "R", "AA" becomes "A").
  • This behavior is unexpected because stream output should incrementally build the complete response content without losing any characters.

Steps to Reproduce

  1. Set the initial value of full_text to "aaR".
  2. Set the value of resp_content to "aaRRe".
  3. Execute full_text = resp_content.replace(full_text, "" 1).
  4. Observe the result of full_text, which changes from "aaRRe" to "aaRe", indicating character loss.

Expected Behavior

Stream output should incrementally build the complete response content without losing any characters. For example:

  • If full_text is "aaR" and resp_content is "aaRRe", the final result should be "aaRRe", not "aaRe".

Proposed Solutions

Here are several possible solutions:

1. Directly Append New Content

Avoid using the replace method and directly append the new part of resp_content:

full_text += resp_content[len(full_text):]

2. Check and Append New Content

Check the new part of resp_content and append it to full_text:

new_content = resp_content[len(full_text):]
full_text += new_content

3. Avoid Using replace Method

If full_text does not need to be deleted, directly assign resp_content to full_text:

full_text = resp_content

4. Use Regular Expressions for Precise Matching

For more precise matching, use regular expressions:

import re
pattern = re.escape(full_text)
result = re.sub(pattern, "" resp_content, count=1)

Environment Information

  • **dify 0.1.4
  • **qwen-plug-in 0.25
  • **bug code dify-official-plugins/blob/main/models/tongyi/models/llm/llm.py

Additional Information

  • This issue is common in stream output processing, especially when incrementally building complete response content. 100% can be reproduced.
  • If the team has other suggestions or solutions, feel free to discuss.

✔️ Error log

No response

Originally created by @zhouzhou0322 on GitHub (May 22, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [Dify issues](https://github.com/langgenius/dify/issues) & [Dify Official Plugins](https://github.com/langgenius/dify-official-plugins/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.4 ### Plugin version tongyi plugin 0.25, when use deepseek-v3 model. ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce This happens when use tongyi plugin, select deepseek-v3 model. other model is fine. Only deepseek-v3 have problem. <img width="841" alt="Image" src="https://github.com/user-attachments/assets/10e468f7-749d-4eba-af6c-aec61339bc2e" /> https://github.com/langgenius/dify-official-plugins/blob/main/models/tongyi/models/llm/llm.py 1. docker run dify 2. install tonyyi plugin and choose deepseek v3 model 3. use prompt below: https://fscdn.xyxy.com/fs41/M01/98/5B/CgRReWaUiy- AQ8W8AAS6w3U2x-Q913.png. return me the url I gave it to u, make sure theres no character loss 4. notice theres a R and an A lost in the url that dify response. ### how problem found I found url sometimes changed when llm give it to me. it turns out its the plugin problem. <img width="767" alt="Image" src="https://github.com/user-attachments/assets/827ea774-3724-45b4-be39-590d0906e8b6" /> Notice there is a R and an A lost in the response. --- ### **Problem Description** When handling stream output, the use of `full_text = resp_content.replace(full_text, "" 1)` causes character loss. Specifically: - If `full_text` is `"aaR"` and `resp_content` is `"aaRRe"`, after the replacement, `"aaRRe"` becomes `"aaRe"`, resulting in character loss (e.g., `"RR"` becomes `"R"`, `"AA"` becomes `"A"`). - This behavior is unexpected because stream output should incrementally build the complete response content without losing any characters. --- ### **Steps to Reproduce** 1. Set the initial value of `full_text` to `"aaR"`. 2. Set the value of `resp_content` to `"aaRRe"`. 3. Execute `full_text = resp_content.replace(full_text, "" 1)`. 4. Observe the result of `full_text`, which changes from `"aaRRe"` to `"aaRe"`, indicating character loss. --- ### **Expected Behavior** Stream output should incrementally build the complete response content without losing any characters. For example: - If `full_text` is `"aaR"` and `resp_content` is `"aaRRe"`, the final result should be `"aaRRe"`, not `"aaRe"`. --- ### **Proposed Solutions** Here are several possible solutions: #### 1. **Directly Append New Content** Avoid using the `replace` method and directly append the new part of `resp_content`: ```python full_text += resp_content[len(full_text):] ``` #### 2. **Check and Append New Content** Check the new part of `resp_content` and append it to `full_text`: ```python new_content = resp_content[len(full_text):] full_text += new_content ``` #### 3. **Avoid Using `replace` Method** If `full_text` does not need to be deleted, directly assign `resp_content` to `full_text`: ```python full_text = resp_content ``` #### 4. **Use Regular Expressions for Precise Matching** For more precise matching, use regular expressions: ```python import re pattern = re.escape(full_text) result = re.sub(pattern, "" resp_content, count=1) ``` --- ### **Environment Information** - **dify 0.1.4 - **qwen-plug-in 0.25 - **bug code dify-official-plugins/blob/main/models/tongyi/models/llm/llm.py --- ### **Additional Information** - This issue is common in stream output processing, especially when incrementally building complete response content. 100% can be reproduced. - If the team has other suggestions or solutions, feel free to discuss. ### ✔️ Error log _No response_
yindo added the bug label 2026-02-16 10:18:55 -05:00
yindo closed this issue 2026-02-16 10:18:55 -05:00
Author
Owner

@zhouzhou0322 commented on GitHub (May 23, 2025):

@Yeuoly

https://github.com/langgenius/dify-official-plugins/blob/main/models/tongyi/models/llm/llm.py @ line 322

assistant_prompt_message.content = resp_content.replace( full_text, "", 1 )

Hi, could you explain what the code snippet above is for? which causes the bug this issue mentioned.

assistant_prompt_message.content = resp_content will work?

@zhouzhou0322 commented on GitHub (May 23, 2025): @Yeuoly https://github.com/langgenius/dify-official-plugins/blob/main/models/tongyi/models/llm/llm.py @ line 322 `assistant_prompt_message.content = resp_content.replace( full_text, "", 1 )` Hi, could you explain what the code snippet above is for? which causes the bug this issue mentioned. `assistant_prompt_message.content = resp_content` will work?
Author
Owner

@zhouzhou0322 commented on GitHub (May 28, 2025):

@crazywoola

可以帮忙看看这个问题吗?千问插件流式返回丢字。

@zhouzhou0322 commented on GitHub (May 28, 2025): @crazywoola 可以帮忙看看这个问题吗?千问插件流式返回丢字。
Author
Owner

@Nzzz964 commented on GitHub (Jun 24, 2025):

@Yeuoly

https://github.com/langgenius/dify-official-plugins/blob/main/models/tongyi/models/llm/llm.py @ line 322

assistant_prompt_message.content = resp_content.replace( full_text, "", 1 )

Hi, could you explain what the code snippet above is for? which causes the bug this issue mentioned.

assistant_prompt_message.content = resp_content will work?

I've been troubled by this issue for a long time, I thought it was a prompt issue at first

@Nzzz964 commented on GitHub (Jun 24, 2025): > [@Yeuoly](https://github.com/Yeuoly) > > https://github.com/langgenius/dify-official-plugins/blob/main/models/tongyi/models/llm/llm.py @ line 322 > > `assistant_prompt_message.content = resp_content.replace( full_text, "", 1 )` > > Hi, could you explain what the code snippet above is for? which causes the bug this issue mentioned. > > `assistant_prompt_message.content = resp_content` will work? I've been troubled by this issue for a long time, I thought it was a prompt issue at first
Author
Owner

@dosubot[bot] commented on GitHub (Aug 20, 2025):

Hi, @zhouzhou0322. I'm Dosu, and I'm helping the dify-official-plugins team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported a reproducible bug in Dify v1.4 with the tongyi plugin 0.25 using the deepseek-v3 model where characters are lost in streamed output URLs.
  • The issue is traced to line 322 in llm.py where resp_content.replace(full_text, "", 1) causes missing characters.
  • You suggested that simply assigning resp_content might fix the problem.
  • Other users like Nzzz964 have confirmed being affected and requested clarification from maintainers.
  • The problem is specific to self-hosted Docker setups and does not occur with other models.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of the dify-official-plugins repository by commenting here.
  • If I do not hear back within 5 days, I will automatically close this issue.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Aug 20, 2025): Hi, @zhouzhou0322. I'm [Dosu](https://dosu.dev), and I'm helping the dify-official-plugins team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported a reproducible bug in Dify v1.4 with the tongyi plugin 0.25 using the deepseek-v3 model where characters are lost in streamed output URLs. - The issue is traced to line 322 in llm.py where `resp_content.replace(full_text, "", 1)` causes missing characters. - You suggested that simply assigning `resp_content` might fix the problem. - Other users like Nzzz964 have confirmed being affected and requested clarification from maintainers. - The problem is specific to self-hosted Docker setups and does not occur with other models. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of the dify-official-plugins repository by commenting here. - If I do not hear back within 5 days, I will automatically close this issue. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#309