From 94992743e86dd8f4eabe22e77dca532f989d2dd6 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Thu, 21 Sep 2023 21:51:03 +0200 Subject: [PATCH] quota/tokenCount: fix "null from a database" --- src/quota/tokenCount.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/quota/tokenCount.ts b/src/quota/tokenCount.ts index 263ba13..47e9e99 100644 --- a/src/quota/tokenCount.ts +++ b/src/quota/tokenCount.ts @@ -51,12 +51,13 @@ export default class tokenCount implements IQuota { } }))._sum; - if (!usedTokens.usageRequest || !usedTokens.usageResponse) throw new Error("Null from a database!! (tokenCount Quota)"); + const usageRequest = usedTokens.usageRequest === null ? 0 : usedTokens.usageRequest; + const usageResponse = usedTokens.usageResponse === null ? 0 : usedTokens.usageResponse; const usedUnits = (() => { if (this.considerInputTokensAsHalf) - return usedTokens.usageResponse + usedTokens.usageRequest / 2; - return usedTokens.usageResponse + usedTokens.usageRequest; + return usageResponse + usageRequest / 2; + return usageResponse + usageRequest; })(); if (userQuota?.vip) return this.createUserQuotaData(Infinity, usedUnits);