Hey there! I’m trying out the new assistant API and wondering if I’m missing something very basic - how do I trigger some action to get the thread contents on the end of a run automatically? I’ve set up my Assistant, and can create messages and runs. When I poll, eventually I get the updated thread. But I suspect there’s a more elegant way to do this than pulling every [n] milliseconds to look for an updated Thread object…
Apologies if this is elemental, I’m fairly new to this.
while run.status != "completed":
run = client.beta.threads.runs.retrieve(
thread_id=thread.id,
run_id=run.id
)
time.sleep(3)
Could this be a good solution?
1 Like
@mehmet.koca thank you! In the end this is very close to what I wrote - wondering if there is a non-polling strategy for this 
But for the time being, this is working well and I’m unblocked. Cheers!
I’m also curious about a better solution 
+1 for callbacks on run complete instead of polling.
because it’s not just polling right? it’s polling followed by another call to thread messages to get the actual results. so its:
- create and run thread (thank goodness these can be combined)
- poll for run results
- retrieve messages from the thread
a little bit rube goldberg, right?
Thanks for the feedback! We plan to improve this via streaming and webhooks for the Assistants API, but they are not quite ready in the beta right now. Working on it, and will share more as we ship these features.
5 Likes