My answer was about streaming the API response in real time.
Let me show you an example for my approach using python, the openai python SDK and the Django framework.
from openai import OpenAI
client = OpenAI()
stream = client.beta.threads.runs.create(
thread_id="thread_123",
assistant_id="asst_123",
stream=True
)
def my_iterator():
for event in stream:
yield event
return StreamingHttpResponse(my_iterator())
this is only an example as you would need to add more code so you can extract the text value from each stream event.
Then you can read the stream of data using the javascript Streams API on the client side.