Solve the problem of displaying repeated words during the streaming process in Chinese and other languages. #1552
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When I generate Chinese characters, during streaming process, words occasionally repeats itself or neighbor chunks. When generation is finished, the full content will fresh and saved to database. This happened frequently on the vercel deployments and sometimes on the local deployments, across all types of models hosted outside Asia (openai, mistral, anthropic, openrouter).
It is not too painful to wait until it finished. However, new models like claude-3 can generate really good and pretty long content, this issue got higher priority.
I checked how the processResponse function behaves. Streaming outputs are updated by
content: chatMessage.message.content + contentToAdd
This is pretty clear and straight. However it may increase potential critical computation latency, considering the content will be displayed immediately. I update this content by the fullText directly as
content: fullText
,because fullText variable keeps accumulating contentToAdd, behaving the same way as the original
content: chatMessage.message.content + contentToAdd
.Problem example:
During streaming, (repeated words happened):
Finished, (repeated words are corrected after finishing):
After this commit:
During streaming, (no more issues):
There is no more repeated words.
If after this commit other developers still encounter the same problem, please comment.