diff --git a/docs/huggingface.md b/docs/huggingface.md index 7d3419d..f96a1b5 100644 --- a/docs/huggingface.md +++ b/docs/huggingface.md @@ -24,11 +24,11 @@ RUN apt-get update && \ apt-get install -y git RUN git clone https://github.com/nai-degen/oai-reverse-proxy.git /app WORKDIR /app -ENV NODE_ENV=production RUN npm install -COPY . . +COPY Dockerfile .env* ./ RUN npm run build EXPOSE 7860 +ENV NODE_ENV=production CMD [ "npm", "start" ] ``` - Click "Commit new file to `main`" to save the Dockerfile. diff --git a/src/info-page.ts b/src/info-page.ts index 7e349bf..cf2fc4b 100644 --- a/src/info-page.ts +++ b/src/info-page.ts @@ -26,11 +26,17 @@ function getInfoPageHtml(host: string) { status: `Still checking ${uncheckedKeys.length} keys...`, }; } else if (config.checkKeys) { + const hasGpt4 = keys.some((k) => k.isGpt4); keyInfo = { ...keyInfo, trial: keys.filter((k) => k.isTrial).length, gpt4: keys.filter((k) => k.isGpt4).length, - remainingQuota: `${Math.round(keyPool.calculateRemainingQuota() * 100)}%`, + quotaLeft: { + all: `${Math.round(keyPool.remainingQuota() * 100)}%`, + ...(hasGpt4 + ? { gpt4: `${Math.round(keyPool.remainingQuota(true) * 100)}%` } + : {}), + }, }; } diff --git a/src/key-management/key-pool.ts b/src/key-management/key-pool.ts index 6d5ee68..bbaf4df 100644 --- a/src/key-management/key-pool.ts +++ b/src/key-management/key-pool.ts @@ -121,9 +121,14 @@ export class KeyPool { return { ...oldestKey }; } + /** Called by the key checker to update key information. */ public update(keyHash: string, update: KeyUpdate) { const keyFromPool = this.keys.find((k) => k.hash === keyHash)!; Object.assign(keyFromPool, { ...update, lastChecked: Date.now() }); + // Disable the key if it's over the hard limit, provi + if (update.usage && keyFromPool.usage >= keyFromPool.hardLimit) { + this.disable(keyFromPool); + } } public disable(key: Key) { @@ -158,7 +163,7 @@ export class KeyPool { } /** Returns the remaining aggregate quota for all keys as a percentage. */ - public calculateRemainingQuota(gpt4Only = false) { + public remainingQuota(gpt4Only = false) { const keys = this.keys.filter((k) => !gpt4Only || k.isGpt4); if (keys.length === 0) return 0;