tries to handle exhausted trials a bit better

This commit is contained in:
nai-degen 2023-04-10 03:11:14 -07:00 committed by nai-degen
parent de5833e1e5
commit 75e004d2b1
2 changed files with 6 additions and 4 deletions

View File

@ -198,10 +198,10 @@ export class KeyChecker {
// For paid keys, the limit resets every month, so we can use the current
// month as the start date.
// For trial keys, the limit does not reset, so we need to use the start
// date of the trial. We don't know that but it can be at most 90 days ago.
// date of the trial. We use 100 days ago because that is the maximum.
const today = new Date();
const startDate = isTrial
? new Date(today.getTime() - 90 * 24 * 60 * 60 * 1000)
? new Date(today.getTime() - 100 * 24 * 60 * 60 * 1000)
: new Date(today.getFullYear(), today.getMonth(), 1);
return `start_date=${startDate.toISOString().split("T")[0]}&end_date=${
today.toISOString().split("T")[0]

View File

@ -130,6 +130,9 @@ export class KeyPool {
const keyFromPool = this.keys.find((k) => k.key === key.key)!;
if (keyFromPool.isDisabled) return;
keyFromPool.isDisabled = true;
// If it's disabled just set the usage to the hard limit so it doesn't
// mess with the aggregate usage.
keyFromPool.usage = keyFromPool.hardLimit;
this.log.warn({ key: key.hash }, "Key disabled");
}
@ -156,8 +159,7 @@ export class KeyPool {
/** Returns the remaining aggregate quota for all keys as a percentage. */
public calculateRemainingQuota(gpt4Only = false) {
const keys = gpt4Only ? this.keys.filter((k) => k.isGpt4) : this.keys;
const keys = this.keys.filter((k) => !gpt4Only || k.isGpt4);
if (keys.length === 0) return 0;
const totalUsage = keys.reduce((acc, key) => {