I am getting error in the api for retrieving the run:
await openai.beta.threads.runs.retrieve(currentThreadId, run.id);
Here is my code:
console.log(`Backend Debug: Polling for run status on thread ID: ${currentThreadId}, run ID: ${run.id}`);
if (!currentThreadId || typeof currentThreadId !== 'string' || !currentThreadId.startsWith('thread_')) {
throw new Error(`Invalid thread ID: ${currentThreadId}`);
}
let runStatus = await openai.beta.threads.runs.retrieve(currentThreadId, run.id);
console.log(runStatus.status)
while (runStatus.status !== 'completed') {
if (['failed', 'cancelled', 'expired'].includes(runStatus.status)) {
throw new Error(`Run ended with status: ${runStatus.status}`);
}
await new Promise(resolve => setTimeout(resolve, 1000));
runStatus = await openai.beta.threads.runs.retrieve(thread_id = currentThreadId, run.id);
}
EDIT: My code runs fine now, referring to the runs.mjs
in openai module:
retrieve(runID, params, options) {
const { thread_id } = params;
return this._client.get(path `/threads/${thread_id}/runs/${runID}`, {
...options,
headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),
});
}
This expects a named thread_id
param, so changed my code to:
openai.beta.threads.runs.retrieve(run.id, { thread_id : currentThreadId})