#Can I Run 2 "Runs" Simultaneously on two different threads of Assistant API?
1 messages · Page 1 of 1 (latest)
Hi @bold hornet. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes, you can run multiple threads simultaneously on a single assistant using the Assistant API. Each thread represents a separate conversation, and you can create as many threads as you need.
In the example provided in the OpenAI Cookbook (https://github.com/openai/openai-cookbook/blob/main/examples/Assistants_API_overview_python.ipynb), multiple threads are created and run concurrently. Here's the relevant code snippet:
def create_thread_and_run(user_input):
thread = client.beta.threads.create()
run = submit_message(MATH_ASSISTANT_ID, thread, user_input)
return thread, run
# Emulating concurrent user requests
thread1, run1 = create_thread_and_run(
"I need to solve the equation `3x + 11 = 14`. Can you help me?"
)
thread2, run2 = create_thread_and_run("Could you explain linear algebra to me?")
thread3, run3 = create_thread_and_run("I don't like math. What can I do?")
In this example, three threads are created and run simultaneously. Each thread is associated with a different user request. The create_thread_and_run function creates a new thread and submits a user message to it, starting a new run.
Remember to manage your threads properly. As mentioned in a forum post (https://community.openai.com/t/496041), there is no automatic thread management, so you need to store the thread id on your side to a database. You can then fetch it with openai.beta.threads.retrieve(thread_id). If it doesn’t exist, then create a new thread.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@bold hornet kapa.ai is still learning and improving, please let us know how it did by reacting below