add limits related to current messages to config
This commit is contained in:
parent
4f4b708ba5
commit
02730ff488
3 changed files with 13 additions and 3 deletions
|
@ -31,4 +31,14 @@ export default class config {
|
||||||
model: "gpt-3.5-turbo",
|
model: "gpt-3.5-turbo",
|
||||||
max_tokens: 384,
|
max_tokens: 384,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** limits for message selection */
|
||||||
|
static readonly limits = {
|
||||||
|
/** maximum time in the past for messages (in miliseconds) */
|
||||||
|
time: 60*60*1000,
|
||||||
|
/** maximum number of messages to select (maximum 100) */
|
||||||
|
messages: 50,
|
||||||
|
/** maximum total token usage for messages */
|
||||||
|
tokens: 2048,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,9 @@ discord.on("messageCreate", async message => {
|
||||||
if (!message.mentions.has(message.client.user)) return;
|
if (!message.mentions.has(message.client.user)) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let messages: DiscordApi.Collection<string, DiscordApi.Message> = await message.channel.messages.fetch({ limit: 50, cache: false });
|
let messages: DiscordApi.Collection<string, DiscordApi.Message> = await message.channel.messages.fetch({ limit: config.limits.messages, cache: false });
|
||||||
|
|
||||||
messages = messages.filter(m => message.createdTimestamp - m.createdTimestamp < 1000*60*60 );
|
messages = messages.filter(m => message.createdTimestamp - m.createdTimestamp < config.limits.time );
|
||||||
|
|
||||||
messages.forEach(m => Moderation.checkMessage(m));
|
messages.forEach(m => Moderation.checkMessage(m));
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ export default function toOpenAIMessages(messages: Collection<string, DiscordMes
|
||||||
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 > 2048) break;
|
if (tokenCount > config.limits.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