You will need your Assistant’s id e.g. asst_58fDQ7d8AJHDJy8dv
.
From the doc, jump to Step 2, Create a thread
// create thread
const thread = client.beta.threads.create()
// add your message to the thread
const message = client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content="I need to solve the equation `3x + 11 = 14`. Can you help me?"
)
// create run
const run = client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id="asst_58fDQ7d8AJHDJy8dv", // <-- your Assistant id
additional_instructions ="Please address the user as Jane Doe. The user has a premium account."
)
// do polling
let isCompleted = false
do {
const check_run = client.beta.threads.runs.retrieve(
thread_id=thread.id,
run_id=run.id
)
if(check_run.status === "completed") {
// get the messages
const list_messages = client.beta.threads.messages.list(thread_id=thread.id)
// get the new messages
isCompleted = true
} else if(check_run.status === "requires_action") {
// handle function calling
} else {
// handle other status
}
if(!isCompleted) {
await sleep(1000)
}
} while(!isCompleted)