further increases OpenAI rate limit backoff
This commit is contained in:
parent
20c064394a
commit
4a68c14477
|
@ -1,33 +1,20 @@
|
|||
|
||||
type ImageHistory = {
|
||||
url: string;
|
||||
prompt: string;
|
||||
}
|
||||
|
||||
const IMAGE_HISTORY_SIZE = 30;
|
||||
const imageHistory = new Array<ImageHistory>(IMAGE_HISTORY_SIZE);
|
||||
let imageHistoryIndex = 0;
|
||||
let index = 0;
|
||||
|
||||
export function getImageHistory() {
|
||||
return imageHistory.filter((url) => url);
|
||||
}
|
||||
type ImageHistory = { url: string; prompt: string };
|
||||
|
||||
export function addToImageHistory(image: ImageHistory) {
|
||||
imageHistory[imageHistoryIndex] = image;
|
||||
imageHistoryIndex = (imageHistoryIndex + 1) % IMAGE_HISTORY_SIZE;
|
||||
imageHistory[index] = image;
|
||||
index = (index + 1) % IMAGE_HISTORY_SIZE;
|
||||
}
|
||||
|
||||
export function getLastNImages(n: number) {
|
||||
const result: ImageHistory[] = [];
|
||||
let currentIndex = (imageHistoryIndex - 1 + IMAGE_HISTORY_SIZE) % IMAGE_HISTORY_SIZE;
|
||||
let currentIndex = (index - 1 + IMAGE_HISTORY_SIZE) % IMAGE_HISTORY_SIZE;
|
||||
|
||||
for (let i = 0; i < n; i++) {
|
||||
// Check if the current index is valid (not undefined).
|
||||
if (imageHistory[currentIndex]) {
|
||||
result.unshift(imageHistory[currentIndex]);
|
||||
}
|
||||
|
||||
// Move to the previous item, wrapping around if necessary.
|
||||
if (imageHistory[currentIndex]) result.unshift(imageHistory[currentIndex]);
|
||||
currentIndex = (currentIndex - 1 + IMAGE_HISTORY_SIZE) % IMAGE_HISTORY_SIZE;
|
||||
}
|
||||
|
||||
|
|
|
@ -305,7 +305,7 @@ export class OpenAIKeyProvider implements KeyProvider<OpenAIKey> {
|
|||
key.rateLimitRequestsReset,
|
||||
key.rateLimitTokensReset
|
||||
);
|
||||
return now < key.rateLimitedAt + Math.min(10000, resetTime);
|
||||
return now < key.rateLimitedAt + Math.min(20000, resetTime);
|
||||
}).length;
|
||||
const anyNotRateLimited = rateLimitedKeys < activeKeys.length;
|
||||
|
||||
|
@ -323,7 +323,7 @@ export class OpenAIKeyProvider implements KeyProvider<OpenAIKey> {
|
|||
key.rateLimitRequestsReset,
|
||||
key.rateLimitTokensReset
|
||||
);
|
||||
return key.rateLimitedAt + Math.min(10000, resetTime) - now;
|
||||
return key.rateLimitedAt + Math.min(20000, resetTime) - now;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@ -335,7 +335,7 @@ export class OpenAIKeyProvider implements KeyProvider<OpenAIKey> {
|
|||
// DALL-E requests do not send headers telling us when the rate limit will
|
||||
// be reset so we need to set a fallback value here. Other models will have
|
||||
// this overwritten by the `updateRateLimits` method.
|
||||
key.rateLimitRequestsReset = 5000;
|
||||
key.rateLimitRequestsReset = 20000;
|
||||
}
|
||||
|
||||
public incrementUsage(keyHash: string, model: string, tokens: number) {
|
||||
|
|
Loading…
Reference in New Issue