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

Solve the problem of displaying repeated words during the streaming process in Chinese and other languages. #1552

Merged
merged 1 commit into from
Mar 23, 2024

Conversation

xycjscs
Copy link

@xycjscs xycjscs commented Mar 11, 2024

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):
Screenshot 2024-03-11 at 8 22 17 PM
Finished, (repeated words are corrected after finishing):
Screenshot 2024-03-11 at 8 22 38 PM

After this commit:
During streaming, (no more issues):
Screenshot 2024-03-11 at 8 23 30 PM
There is no more repeated words.

If after this commit other developers still encounter the same problem, please comment.

…treaming output process in Chinese and other languages.
@mckaywrigley
Copy link
Owner

Looks good!

@mckaywrigley mckaywrigley merged commit 2b06b99 into mckaywrigley:main Mar 23, 2024
Chr96er pushed a commit to Chr96er/chatbot-ui that referenced this pull request May 26, 2024
…treaming output process in Chinese and other languages. (mckaywrigley#1552)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants