Increased default chat cut-off.

This commit is contained in:
Niels Simenon 2023-04-09 15:45:41 +02:00
parent 6469a7b660
commit ad7f1f548e
2 changed files with 29 additions and 14 deletions

View File

@ -3,9 +3,11 @@
module.exports = {
platform: 'schat',
user: {
id: 'aisha',
username: 'Aisha',
realName: 'Aisha',
id: 'clive',
username: 'Clive',
realName: 'Clive',
avatar: null,
key: null,
},
style: {
// color: 'var(--message-56)',
@ -18,7 +20,7 @@ module.exports = {
reconnectDelay: 10, // seconds
prefix: '~',
labels: true,
greeting: 'Hi, I am aisha, your game host!',
greeting: 'Hi, I am Clive, your game host!',
usernamePrefix: '@',
channels: ['GamesNight'],
games: [
@ -70,7 +72,7 @@ module.exports = {
'gpt-4',
],
model: 'gpt-3.5-turbo',
replyTokenLimit: 200,
replyTokenLimit: 1000,
userTokenLimit: 20000, // daily, roughly 100+ messages or $0.04 per user
userTokenPeriod: 24, // hours
temperature: 1,

View File

@ -35,7 +35,7 @@ async function onStart(context) {
.where('created', '<=', knex.raw(`datetime('now', '-${config.chat.userTokenPeriod} hour')`))
.delete();
context.logger.info(`Purged ${purgeResult} expired chat token totals from databae`);
context.logger.info(`Purged ${purgeResult} expired chat token totals from database`);
}
function setHistory(value, context) {
@ -123,6 +123,16 @@ function setRule(rule, context) {
context.sendMessage(`Chat rule must be at least 3 characters long, ${context.user.prefixedUsername}`, context.room.id, { label: false });
}
async function getTokens(context) {
const { used_tokens: usedTokens } = await knex('chat_tokens')
.sum('tokens as used_tokens')
.where('user_id', context.user.id)
.where('created', '>', knex.raw(`datetime('now', '-${config.chat.userTokenPeriod} hour')`)) // 1 day ago
.first();
return usedTokens || 0;
}
async function onCommand(args, context) {
if (context.subcommand === 'history' && config.operators.includes(context.user.username)) {
setHistory(args[0], context);
@ -139,23 +149,26 @@ async function onCommand(args, context) {
return;
}
if (['rule', 'is', 'reset'].includes(context.subcommand) && (config.chat.rulePublic || config.operators.includes(context.user.username))) {
if (['rule', 'is', 'be', 'ur', 'reset'].includes(context.subcommand) && (config.chat.rulePublic || config.operators.includes(context.user.username))) {
setRule(context.subcommand === 'reset' ? 'reset' : args.join(' '), context);
return;
}
if (['tokens', 'credit'].includes(context.subcommand)) {
const tokens = await getTokens(context);
context.sendMessage(`You have used ${config.chat.userTokenLimit - tokens} chat tokens remaining. They will be returned gradually over ${config.chat.userTokenPeriod} hours.`, context.room.id, { label: false });
return;
}
const prompt = args.join(' ');
try {
const { used_tokens: usedTokens } = await knex('chat_tokens')
.sum('tokens as used_tokens')
.where('user_id', context.user.id)
.where('created', '>', knex.raw(`datetime('now', '-${config.chat.userTokenPeriod} hour')`)) // 1 day ago
.first();
const usedTokens = await getTokens(context);
if (usedTokens >= config.chat.userTokenLimit) {
context.logger.info(`${context.user.username} was rate limited at usedTokens: ${prompt}`);
context.sendMessage(`Sorry, I love talking with you ${context.user.prefixedUsername}, but I need to take a break :(`, context.room.id, { label: false });
context.logger.info(`${context.user.username} was rate limited at ${usedTokens}: ${prompt}`);
context.sendMessage(`Sorry, I love talking with you ${context.user.prefixedUsername}, but I need to take a break :( Check ${config.prefix}chat:tokens for more information.`, context.room.id, { label: false });
return;
}