AssistantEventHandler vs Polling a run

I am currently on an older version of the openai-python client and so, I’m using client.beta.threads.runs.poll without a specified poll_interval_ms. I saw that in a newer release, openai-python supports an AssistantEventHandler for streaming an assistant run for updates. How much would our latency reduce by implementing AssistantEventHandler instead? Is it worth the migration?

Not sure what your implementation looks like and depends on whether you’re doing streaming now, but here’s an example from Chainlit that uses this long while loop and god knows how many retrieve calls during the course of a run, and here’s the EventHandler version of it. They’re not quite 1-to-1, but generally speaking I think this EventHandler version is easier to understand, and troubleshoot.

The base EventHandler code from OAI, especially the sse_event_emit function does most of the work for you.

Thank you for your response. I definitely agree that it is cleaner, I’m trying to understand if it is faster than the polling as well and if so, by how much.