Quota: Refactor how Quotas are being handled
also renamed limits to quota I believe this new approach would allow me and bot hosters to add, implement or change the quota behavior more easily. Reimplemented the currently existing "Message count" limit to use the new IQuota, refactoring a code *a little*.
This commit is contained in:
parent
46bb5c867d
commit
339ef06ff9
5 changed files with 214 additions and 107 deletions
|
@ -4,6 +4,9 @@ import {
|
|||
CreateChatCompletionRequest as ChatCompletionRequestData,
|
||||
} from "openai";
|
||||
|
||||
import IQuota from "./IQuota";
|
||||
import MessageCount from "./quota/messageCount";
|
||||
|
||||
export interface IConfigRequired {
|
||||
readonly calendarParams: Intl.DateTimeFormatOptions;
|
||||
/** Tokens to authentiate with */
|
||||
|
@ -24,11 +27,11 @@ export interface IConfigRequired {
|
|||
/** Maximum total token usage for messages (counted locally) */
|
||||
readonly tokens: number;
|
||||
};
|
||||
/** Default limits for user inteacting with the bot */
|
||||
readonly userLimits: {
|
||||
/** How much requests can an user make if it's not overriden in a database entry */
|
||||
readonly requests: number;
|
||||
};
|
||||
/**
|
||||
* Quota parameters to use when checking limits
|
||||
* you can find some in `./quota`
|
||||
*/
|
||||
readonly quota: IQuota;
|
||||
}
|
||||
|
||||
export type IConfig = Partial<IConfigRequired>;
|
||||
|
@ -85,7 +88,5 @@ const defaultConfig: IConfigRequired = {
|
|||
messages: envAsNumber("READ_LIMITS__MESSAGES") ?? 50,
|
||||
tokens: envAsNumber("READ_LIMITS__TOKENS") ?? 2048,
|
||||
},
|
||||
userLimits: {
|
||||
requests: envAsNumber("USER_LIMITS__REQUESTS") ?? 25,
|
||||
},
|
||||
quota: new MessageCount(envAsNumber("QUOTA__DEFAULT_QUOTA"), envAsNumber("QUOTA__LOOKBACK"))
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue