Seeking Help to Restore Streaming Mode Text Display in Streamlit After OpenAI Update

Hello Streamlit Community,

I’m reaching out for assistance regarding an issue I’ve encountered with displaying text in a streaming or typewriter effect on Streamlit. Before a major update by OpenAI in November 2023, I was able to implement a streaming mode for text display in my Streamlit applications, where each character of a chatbot’s response would appear sequentially, simulating a live typing effect. This feature significantly enhanced the interactive experience for users by making the chatbot responses feel more dynamic and engaging.

However, following the OpenAI update in November 2023, this functionality has been impacted, and I’m no longer able to achieve the same streaming text display on Streamlit. It seems that changes in the update have affected how text updates can be incrementally displayed in the application.

Could anyone provide guidance, workarounds, or examples on how to restore this streaming text display functionality in Streamlit? I’m looking for a way to simulate the streaming or typewriter effect for chatbot responses, displaying text character by character with a slight delay between each, as it was before the OpenAI update.

Understanding that Streamlit reruns the entire script upon each interaction, I’m particularly interested in any solutions that allow for incremental text updates without requiring the script to rerun fully, or any advice on adapting to the changes brought by the OpenAI update.

I appreciate any suggestions, insights, or advice you can offer to help overcome this challenge and restore the streaming mode for text display in my Streamlit application.

Thank you in advance for your support!

1 Like

Hey @Kazuki_Takahashi,

Have you checked out our new st.write_stream function? Here’s an example of using that function with the OpenAI API to stream responses from GPT.

3 Likes

Thank you for the quick reply!
I’ve checked out the examples that you showed, and I copied that to GitHub.
But I got the error message below.

AttributeError: module ‘streamlit’ has no attribute ‘write_stream’

I already tried “pip install upgrade streamlit”.
Do you know why this error occured?

What do you see if you enter pip show streamlit?

1 Like

Thank you for the reply again!
I saw those below.

Name: streamlit
Version: 1.31.1
Summary: A faster way to build and share data apps
Home-page: https://streamlit.io
Author: Snowflake Inc
Author-email: hello@streamlit.io
License: Apache License 2.0
Location: C:\Users"username"\AppData\Local\Programs\Python\Python311\Lib\site-packages
Requires: altair, blinker, cachetools, click, gitpython, importlib-metadata, numpy, packaging, pandas, pillow, protobuf, pyarrow, pydeck, python-dateutil, requests, rich, tenacity, toml, tornado, typing-extensions, tzlocal, validators, watchdog
Required-by: