improves quota display

This commit is contained in:
nai-degen 2023-04-10 04:16:14 -07:00 committed by nai-degen
parent 4200d8203d
commit 6b47c1cdc5
3 changed files with 15 additions and 4 deletions

View File

@ -24,11 +24,11 @@ RUN apt-get update && \
apt-get install -y git apt-get install -y git
RUN git clone https://github.com/nai-degen/oai-reverse-proxy.git /app RUN git clone https://github.com/nai-degen/oai-reverse-proxy.git /app
WORKDIR /app WORKDIR /app
ENV NODE_ENV=production
RUN npm install RUN npm install
COPY . . COPY Dockerfile .env* ./
RUN npm run build RUN npm run build
EXPOSE 7860 EXPOSE 7860
ENV NODE_ENV=production
CMD [ "npm", "start" ] CMD [ "npm", "start" ]
``` ```
- Click "Commit new file to `main`" to save the Dockerfile. - Click "Commit new file to `main`" to save the Dockerfile.

View File

@ -26,11 +26,17 @@ function getInfoPageHtml(host: string) {
status: `Still checking ${uncheckedKeys.length} keys...`, status: `Still checking ${uncheckedKeys.length} keys...`,
}; };
} else if (config.checkKeys) { } else if (config.checkKeys) {
const hasGpt4 = keys.some((k) => k.isGpt4);
keyInfo = { keyInfo = {
...keyInfo, ...keyInfo,
trial: keys.filter((k) => k.isTrial).length, trial: keys.filter((k) => k.isTrial).length,
gpt4: keys.filter((k) => k.isGpt4).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)}%` }
: {}),
},
}; };
} }

View File

@ -121,9 +121,14 @@ export class KeyPool {
return { ...oldestKey }; return { ...oldestKey };
} }
/** Called by the key checker to update key information. */
public update(keyHash: string, update: KeyUpdate) { public update(keyHash: string, update: KeyUpdate) {
const keyFromPool = this.keys.find((k) => k.hash === keyHash)!; const keyFromPool = this.keys.find((k) => k.hash === keyHash)!;
Object.assign(keyFromPool, { ...update, lastChecked: Date.now() }); 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) { public disable(key: Key) {
@ -158,7 +163,7 @@ export class KeyPool {
} }
/** Returns the remaining aggregate quota for all keys as a percentage. */ /** 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); const keys = this.keys.filter((k) => !gpt4Only || k.isGpt4);
if (keys.length === 0) return 0; if (keys.length === 0) return 0;