Sometimes even though I wait for the run to be completed there’s still no assistant reply in the thread. The only message in the thread is mine.
How do I fix it?
Here’s my code:
let run = await openai.beta.threads.runs.create(
thread.id,
{ assistant_id: assistant.id }
);
while (run.status === "queued" || run.status === "in_progress") {
run = await openai.beta.threads.runs.retrieve(thread.id, run.id);
}
const threadMessages = await openai.beta.threads.messages.list(thread.id);
const assistantMessage = threadMessages.data.filter(record => record.role === "assistant")[0];
if(!assistantMessage) {
throw new Error("No assistant message");
}