Added word limit to chat bot.
This commit is contained in:
@@ -58,6 +58,26 @@ function setHistory(value, context) {
|
||||
context.logger.info(`Chat history must be a valid number between 0 and 10, ${context.user.prefixedUsername}`);
|
||||
}
|
||||
|
||||
function setReplyWordLimit(value, context) {
|
||||
if (!value) {
|
||||
context.sendMessage(`Chat reply word limit is set to ${style.bold(settings.replyWordLimit)}`, context.room.id, { label: false });
|
||||
return;
|
||||
}
|
||||
|
||||
const newReplyWordLimit = Number(value);
|
||||
|
||||
if (!Number.isNaN(newReplyWordLimit) && newReplyWordLimit > 3 && newReplyWordLimit <= 200) {
|
||||
settings.replyWordLimit = newReplyWordLimit;
|
||||
|
||||
context.logger.info(`Chat reply word limit set to ${newReplyWordLimit} by ${context.user.username}`);
|
||||
context.sendMessage(`Chat reply word limit set to ${style.bold(newReplyWordLimit)} by ${context.user.prefixedUsername}`, context.room.id, { label: false });
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
context.logger.info(`Chat reply word limit must be a valid number between 3 and 200, ${context.user.prefixedUsername}`);
|
||||
}
|
||||
|
||||
function setTemperature(value, context) {
|
||||
if (!value) {
|
||||
context.sendMessage(`Chat temperature is set to ${style.bold(settings.temperature)}`, context.room.id, { label: false });
|
||||
@@ -154,6 +174,11 @@ async function onCommand(args, context) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (['limit', 'words'].includes(context.subcommand) && (config.chat.replyWordLimitPublic || config.operators.includes(context.user.username))) {
|
||||
setReplyWordLimit(args[0], context);
|
||||
return;
|
||||
}
|
||||
|
||||
if (['tokens', 'credit'].includes(context.subcommand || context.command)) {
|
||||
const username = args[0] ? args[0].replace(new RegExp(`^${config.usernamePrefix}`), '') : context.user.username;
|
||||
const tokens = await getTokens(username);
|
||||
@@ -177,7 +202,7 @@ async function onCommand(args, context) {
|
||||
|
||||
const message = {
|
||||
role: 'user',
|
||||
content: `Answer as if you're ${settings.rule}. ${prompt}`,
|
||||
content: `Using ${settings.replyWordLimit} words or fewer, answer as if you're ${settings.rule}. ${prompt}`,
|
||||
};
|
||||
|
||||
const userHistory = (history.get(context.user.username) || []).concat(message);
|
||||
|
||||
Reference in New Issue
Block a user