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!

2 Likes

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: