#assistant runs not completing

1 messages · Page 1 of 1 (latest)

sturdy spindle
#

My runs are not completing
API
Bugs
kinzinzombe07
8h

I am following the steps outlined in the OpenAI documentation when it comes to assistants, I am creating a thread, adding messages to it and so on…however when I try to access the run’s status via a loop, it never leaves the “in_progress” status, I’ve run this code for 20 minutes and the status remains the same.
Here is my code:

const prompt = async (content) => {
// See: https://platform.openai.com/docs/assistants/overview?lang=node.js

const assistant = await openai.beta.assistants.retrieve("asstistant");

// Create a thread
const thread = await openai.beta.threads.create();

// Add a message to the thread
const message = await openai.beta.threads.messages.create(
thread.id,
{
role: "user",
content
}
)

// Create a run
const run = await openai.beta.threads.runs.create(
thread.id,
{ assistant_id: "some default value" }
)

console.log(run);

// Check run status
const runStatus = await openai.beta.threads.runs.retrieve(
thread.id,
run.id
)

// See: Step 5 of assistants API page on the openai docs
for (let attempts = 0;;attempts++){
if(runStatus.status === "queued" || runStatus.status === "in_progress"){
console.log(Run status: ${runStatus.status})
} else {
console.log(runStatus);

    // Display Assistant's response    
    const messages = await openai.beta.threads.messages.list(thread.id);
    console.log(messages.data)

    break;
}

}

}

prompt(“Hello there”)

sick hollyBOT
#

Hi @sturdy spindle. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the extracts, it seems like you're following the correct steps to create a run and check its status. However, there are a few things you might want to consider:

  1. Run Status Polling: In your code, you're checking the run status only once before entering the loop. The run status should be checked inside the loop to get the updated status. Here's how you can modify your loop:
let runStatus = await openai.beta.threads.runs.retrieve(thread.id, run.id);
while(runStatus.status === "queued" || runStatus.status ===  "in_progress"){
    console.log(`Run status: ${runStatus.status}`);
    await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for 1 second
    runStatus = await openai.beta.threads.runs.retrieve(thread.id, run.id);
}
console.log(runStatus);
  1. Assistant ID: Make sure you're using the correct assistant ID when creating a run. In your code, you're using a placeholder value "some default value". You should replace this with the actual ID of your assistant.

  2. API Errors: If the run status is not changing from "in_progress", it might be due to an error in the API. Check if there are any error messages in the run status response.

  3. API Load: If the OpenAI API is under heavy load, it might take longer for the run to complete. However, it shouldn't take as long as 20 minutes. If this is the case, you might want to contact OpenAI support.

Please refer to the OpenAI Cookbook (https://github.com/openai/openai-cookbook/blob/main/examples/Assistants_API_overview_python.ipynb) and OpenAI Community (https://community.openai.com/t/479817) for more details.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: