mirror of
https://github.com/langgenius/dify-official-plugins.git
synced 2026-07-21 17:45:23 -04:00
100% Reproducible: Character Loss in Stream Output Due to replace Method [ tongyi plugin 0.25. with deepseek-v3 model] #309
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @zhouzhou0322 on GitHub (May 22, 2025).
Self Checks
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.
https://github.com/langgenius/dify-official-plugins/blob/main/models/tongyi/models/llm/llm.py
AQ8W8AAS6w3U2x-Q913.png. return me the url I gave it to u, make sure theres no character loss
how problem found
I found url sometimes changed when llm give it to me. it turns out its the plugin problem.
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:full_textis"aaR"andresp_contentis"aaRRe", after the replacement,"aaRRe"becomes"aaRe", resulting in character loss (e.g.,"RR"becomes"R","AA"becomes"A").Steps to Reproduce
full_textto"aaR".resp_contentto"aaRRe".full_text = resp_content.replace(full_text, "" 1).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:
full_textis"aaR"andresp_contentis"aaRRe", the final result should be"aaRRe", not"aaRe".Proposed Solutions
Here are several possible solutions:
1. Directly Append New Content
Avoid using the
replacemethod and directly append the new part ofresp_content:2. Check and Append New Content
Check the new part of
resp_contentand append it tofull_text:3. Avoid Using
replaceMethodIf
full_textdoes not need to be deleted, directly assignresp_contenttofull_text:4. Use Regular Expressions for Precise Matching
For more precise matching, use regular expressions:
Environment Information
Additional Information
✔️ Error log
No response
@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_contentwill work?@zhouzhou0322 commented on GitHub (May 28, 2025):
@crazywoola
可以帮忙看看这个问题吗?千问插件流式返回丢字。
@Nzzz964 commented on GitHub (Jun 24, 2025):
I've been troubled by this issue for a long time, I thought it was a prompt issue at first
@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:
resp_content.replace(full_text, "", 1)causes missing characters.resp_contentmight fix the problem.Next Steps:
Thank you for your understanding and contribution!