const startPolling = async (runId: string, threadId: string) => {
if (!threadId) return;
console.log("Start polling");
let baseTimeout = 30000; // Initial timeout duration
let currentTimeout = baseTimeout; // Current timeout duration
while (true) {
try {
const response = await openai.beta.threads.runs.retrieve(threadId, runId);
console.log(response);
if (
["cancelled", "failed", "completed", "expired"].includes(
response.status
)
) {
const completion = await openai.beta.threads.messages.list(threadId);
console.log(completion.data);
return completion.data[0].content;
}
// If status is "in_progress", double the timeout duration
if (response.status === "in_progress") {
currentTimeout *= 2;
} else {
// Reset the timeout duration to the base value if not "in_progress"
currentTimeout = baseTimeout;
}
// Wait for 5 second before checking the status again
await new Promise((resolve) => setTimeout(resolve, currentTimeout));
} catch (error) {
console.error("Error polling run status:", error);
return "Error polling run status";
}
}
};
Even with an initial delay of 30s and incrementing the delay by doubling it after every last call, I am still getting this error.
Rate limit reached for gpt-3.5-turbo-1106 in organization org-aG27TwnZI6bnQGOJHrooU6LF on requests per min (RPM): Limit 3, Used 3, Requested 1. Please try again in 20s. Visit https://platform.openai.com/account/rate-limits to learn more. You can increase your rate limit by adding a payment method to your account at https://platform.openai.com/account/billing.
How can I get through this error? Also to note, I am on free tier plan of OpenAI.