The app streams from the server and then parses out the Server Side Events in a ReactJS component. I’m not using any special libraries. Feedback welcomed and appreciated!
to update - i pivoted to using the vercel ai sdk and could get the streaming working brilliantly. I am still curious why I could not get the websocket to return the stream, but have moved to the vercel way of doing it (for now).
I would love to hear an update, if the websocket streaming is working with a frontned… thx
Hi - I will go and check my python code again, as would really like to get this working, and really appreciate the pointers. I did pivot to using the vercel ai sdk and got a working streaming in < 10 minutes.
I will give your suggestions a try and come back with an update.
How to save this messages history. I was using run.id to retrieve, but now I can’t find out id for each run.
if prompt := st.chat_input("How can I help you?"):
# Add user message to the state and display on the screen
st.session_state.messages.append({"role": "user", "content": prompt})
if prompt:
run=client.beta.threads.runs.create_and_stream(
thread_id=thread_id,
assistant_id=assistant_id,
model="gpt-4-turbo-preview",
)
with run as stream:
with st.chat_message("assistant"):
response = st.write_stream(stream.text_deltas)
stream.until_done()
with st.chat_message("user"):
st.markdown(prompt)
I’m trying to build a streaming app with openAI assistants where there are two assistants that communicate with each other. I want to stream the interaction between the two back to the frontend, without the end user having to do anything. Do you have any examples of that?
Hi smiith – you should be able to adapt the OpenAI Assistant Starter Kit code to run threads associated with two different assistants by modifying the server-side code in the route.ts file.
Still waiting on documentation of the AssistantEventHandler. I see various examples floating around, some of which override certain events, while others do not. It’s unclear when that is necessary, or even what a complete list of the events are. GPT itself doesn’t know either.
with client.beta.threads.runs.stream(
thread_id=thread_id,
assistant_id=ASS_ID,
) as stream:
With the above, I get this error: AttributeError: 'Runs' object has no attribute 'stream', meanwhile it is there.
When I decide to use the AssistantEventHandler, I get this AttributeError: 'Runs' object has no attribute 'stream'.
Meanwhile, when I import AssistantEventHandler to a Jupyter notebook, it imports, but in my script, I get that error.
I’m on version 1.45.1, I downgraded to 1.42.0 but got the same errors.