Couple questions regarding OpenAI, Workflows and App

I'm trying to run some async functions within a workflow to OpenAI but I get the following error:

Any help with this please?

Also - I have tried to create this async function within my app which checks the status of a chat gpt run, when it's completed the function is meant to resolve, however despite the if statement being true, the function will not resolve and gets stuck in a loop. I have tried storing the return values of each get request in a database and querying that and still no luck. Has anyone got any suggestions?

return new Promise(async (resolve, reject) => {
// Polling for status update
const pollStatus = async () => {
try {
await getRunStatus.trigger(); // Trigger status check
const newStatus = getRunStatus.data.status;
console.log('Updated status:', newStatus);

  if (newStatus === 'completed') {
    console.log("resolved");
    resolve(); // Resolve the promise when completed
  } else {
    console.log("poll status");
    setTimeout(pollStatus, 5000); // Recursively poll status after 5 seconds
  }
} catch (error) {
  console.error('Error in pollStatus:', error);
  reject(error); // Reject the promise if an error occurs in pollStatus
}

};

pollStatus(); // Start polling
});

Hey @elliot!

  1. openai error: Looks like you have the openai variable defined on line 49 of the JS setup script as openai, but in your JS query you are using new OpenAI, which is not defined. If you swap the variable on line 49 or the call in your JS query, so that they match, this should work.

  1. Async call. Something like this should work.

// Polling for status update

const pollStatus = async () => {

try {

let results = await getRunStatus(); // Trigger status check

const newStatus = results.data.status;

console.log('Updated status:', newStatus);

if (newStatus === 'completed') {

console.log("resolved");

resolve(); // Resolve the promise when completed

} else {

console.log("poll status");

setTimeout(pollStatus, 5000); // Recursively poll status after 5 seconds

}

}

catch (error) {

//console.error('Error in pollStatus:', error);

reject(error); // Reject the promise if an error occurs in pollStatus

console.log(error)

}

};

pollStatus(); //Start polling

});
​