add user request limit to config, rename previous limit to read limit
This commit is contained in:
parent
0931fe103d
commit
e6d6764e34
4 changed files with 11 additions and 6 deletions
|
@ -33,7 +33,7 @@ export default class config {
|
||||||
};
|
};
|
||||||
|
|
||||||
/** limits for message selection */
|
/** limits for message selection */
|
||||||
static readonly limits = {
|
static readonly readLimits = {
|
||||||
/** maximum time in the past for messages (in miliseconds) */
|
/** maximum time in the past for messages (in miliseconds) */
|
||||||
time: 60*60*1000,
|
time: 60*60*1000,
|
||||||
/** maximum number of messages to select (maximum 100) */
|
/** maximum number of messages to select (maximum 100) */
|
||||||
|
@ -41,4 +41,9 @@ export default class config {
|
||||||
/** maximum total token usage for messages */
|
/** maximum total token usage for messages */
|
||||||
tokens: 2048,
|
tokens: 2048,
|
||||||
};
|
};
|
||||||
|
/** default user limits */
|
||||||
|
static readonly userLimits = {
|
||||||
|
/** how much requests can an user make if it's not overriden in database entry */
|
||||||
|
requests: 25,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ export async function getUserLimit(user: string | { id: string }, requestTimesta
|
||||||
},
|
},
|
||||||
}))._all;
|
}))._all;
|
||||||
|
|
||||||
if (!userLimits || !userLimits.limit) return {limit: 25, remaining: 25 - usedLimit};
|
if (!userLimits || !userLimits.limit) return {limit: config.userLimits.requests, remaining: config.userLimits.requests - usedLimit};
|
||||||
|
|
||||||
return {limit: userLimits.limit, remaining: userLimits.limit - usedLimit};
|
return {limit: userLimits.limit, remaining: userLimits.limit - usedLimit};
|
||||||
}
|
}
|
||||||
|
@ -261,9 +261,9 @@ async function executeFromQueue(channel: string) {
|
||||||
if (!canReplyToRequest(message)) return;
|
if (!canReplyToRequest(message)) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let messages: DiscordApi.Collection<string, DiscordApi.Message> = await message.channel.messages.fetch({ limit: config.limits.messages, cache: false });
|
let messages: DiscordApi.Collection<string, DiscordApi.Message> = await message.channel.messages.fetch({ limit: config.readLimits.messages, cache: false });
|
||||||
|
|
||||||
messages = messages.filter(m => message.createdTimestamp - m.createdTimestamp < config.limits.time );
|
messages = messages.filter(m => message.createdTimestamp - m.createdTimestamp < config.readLimits.time );
|
||||||
|
|
||||||
messages.forEach(m => { Moderation.checkMessageNoReturn(m); });
|
messages.forEach(m => { Moderation.checkMessageNoReturn(m); });
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ export default class Moderation {
|
||||||
public static removeExpiredCacheEntries() {
|
public static removeExpiredCacheEntries() {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
for (const i of this.cache.keys()) {
|
for (const i of this.cache.keys()) {
|
||||||
if (now - SnowflakeUtil.timestampFrom(i) >= config.limits.time * 2) {
|
if (now - SnowflakeUtil.timestampFrom(i) >= config.readLimits.time * 2) {
|
||||||
this.cache.delete(i);
|
this.cache.delete(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ export default function toOpenAIMessages(
|
||||||
const content = formatMessage(message);
|
const content = formatMessage(message);
|
||||||
// FIXME: tokens are not being counted properly (it's lower than it is) but it's enough for me for now.
|
// FIXME: tokens are not being counted properly (it's lower than it is) but it's enough for me for now.
|
||||||
tokenCount += countTokens(content);
|
tokenCount += countTokens(content);
|
||||||
if (tokenCount > config.limits.tokens) break;
|
if (tokenCount > config.readLimits.tokens) break;
|
||||||
rvalue.push({
|
rvalue.push({
|
||||||
role: message.author.id === message.client.user.id ? "assistant" : "user",
|
role: message.author.id === message.client.user.id ? "assistant" : "user",
|
||||||
content: content,
|
content: content,
|
||||||
|
|
Loading…
Reference in a new issue