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

View File

@ -35,7 +35,7 @@ async function onStart(context) {
.where('created', '<=', knex.raw(`datetime('now', '-${config.chat.userTokenPeriod} hour')`)) .where('created', '<=', knex.raw(`datetime('now', '-${config.chat.userTokenPeriod} hour')`))
.delete(); .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) { 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 }); 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) { async function onCommand(args, context) {
if (context.subcommand === 'history' && config.operators.includes(context.user.username)) { if (context.subcommand === 'history' && config.operators.includes(context.user.username)) {
setHistory(args[0], context); setHistory(args[0], context);
@ -139,23 +149,26 @@ async function onCommand(args, context) {
return; 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); setRule(context.subcommand === 'reset' ? 'reset' : args.join(' '), context);
return; 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(' '); const prompt = args.join(' ');
try { try {
const { used_tokens: usedTokens } = await knex('chat_tokens') const usedTokens = await getTokens(context);
.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();
if (usedTokens >= config.chat.userTokenLimit) { if (usedTokens >= config.chat.userTokenLimit) {
context.logger.info(`${context.user.username} was rate limited at usedTokens: ${prompt}`); 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.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; return;
} }