The code imports various dependencies and defines a list of available commands, then outlines four functions (doDeceive
, doArgument
, doMention
, and doPrivate
) that interact with these commands using various discord API functionalities. Each function generates a response to a user's prompt or message using either the llmDeceive
module or the argueLlama
function, with some functions creating new messages or updating interactions with the generated responses.
npm run import -- "sync deceptive chat"
const {
registerCommand, getCommands, deleteCommand, updateCommand
} = importer.import("discord api")
const {interactionsCommands} = importer.import("discord gateway")
const {triggerTyping, createMessage, updateInteraction} = importer.import("disrcord api")
const {DEFAULT_APPLICATION} = importer.import("discord configuration")
const argueLlama = importer.import("argue with multiple llms")
const ALL_COMMANDS = [
'deceive',
'argue',
]
async function doDeceive(interaction) {
const llmDeceive = await importer.import("llm deceive")
await triggerTyping(interaction.channel_id)
let a1 = await llmDeceive('Give the most wrong or incorrect response to, be as deceptive as possible:\n' + interaction.data.options[0].value)
return await updateInteraction(a1.substring(0, 1800), interaction.id, interaction.token)
}
async function doArgument(interaction) {
let count = 0
return Promise.resolve(argueLlama(interaction.data.options[0].value, async (prompt, answer) => {
if(count == 0) {
// don't repost original prompt
await updateInteraction(answer.substring(0, 1800), interaction.id, interaction.token)
} else {
//await createMessage(prompt.substring(0, 1800), interaction.channel_id)
await createMessage(answer.substring(0, 1800), interaction.channel_id)
}
count++
}))
}
async function doMention(interaction) {
const llmDeceive = await importer.import("llm deceive")
await triggerTyping(interaction.channel_id)
let a1 = await llmDeceive(interaction.content.replace('@' + DEFAULT_APPLICATION) + '\nBe as deceptive as possible and make it short.')
return await createMessage({
content: a1.substring(0, 1800),
message_reference: {
message_id: interaction.id
}
}, interaction.channel_id)
}
async function doPrivate(interaction) {
const llmDeceive = await importer.import("llm deceive")
await triggerTyping(interaction.channel_id)
let a1 = await llmDeceive('Deceive me with the opposite of:\n' + interaction.content)
return await createMessage({
content: a1.substring(0, 1800),
message_reference: {
message_id: interaction.id
}
}, interaction.channel_id)
}
// bot commands using new API, same names as above but lower-case
async function syncTools(guildId = null) {
var cmd, cmdDef
var commandResult = await getCommands(guildId)
var commands = commandResult.map(command => command.name)
cmdDef = {
'name': 'deceive',
'description': 'DeepSeek 7B Chat.',
'options': [
{
'name': 'text',
'description': 'Text to prompt deceptive LLM with.',
'required': true,
'type': 3
}
]
}
if(!commands.includes('deceive')) {
await registerCommand(cmdDef, null, guildId)
} else {
cmd = commandResult.filter(c => c.name == 'deceive')[0]
if(cmdDef.name != cmd.name || cmdDef.description != cmd.description)
await updateCommand(cmdDef, null, cmd.id, guildId)
}
interactionsCommands['deceive'] = doDeceive
interactionsCommands['promptMention'] = doMention
interactionsCommands['promptPrivate'] = doPrivate
cmdDef = {
'name': 'argue',
'description': 'Start an argument between deceptive DeepSeek 7B Chat and Meta Llama 8B.',
'options': [
{
'name': 'text',
'description': 'Text to prompt argumentative LLM with.',
'required': true,
'type': 3
}
]
}
if(!commands.includes('argue')) {
await registerCommand(cmdDef, null, guildId)
} else {
cmd = commandResult.filter(c => c.name == 'argue')[0]
if(cmdDef.name != cmd.name || cmdDef.description != cmd.description)
await updateCommand(cmdDef, null, cmd.id, guildId)
}
interactionsCommands['argue'] = doArgument
var toRemove = commandResult.filter(c => !ALL_COMMANDS.includes(c.name))
for(var i = 0; i < toRemove.length; i++) {
await deleteCommand(toRemove[i].id, guildId)
}
return await getCommands()
}
module.exports = syncTools
const {
registerCommand,
getCommands,
deleteCommand,
updateCommand,
interactionsCommands,
} = importer.import('discord api');
const {
triggerTyping,
createMessage,
updateInteraction,
} = importer.import('discord api');
const { DEFAULT_APPLICATION } = importer.import('discord configuration');
const argueLlama = importer.import('argue with multiple llms');
const ALL_COMMANDS = ['deceive', 'argue'];
// Mapping of functions to handle interactions
const interactions = {
'deceive': doDeceive,
'argue': doArgument,
'promptMention': doMention,
'promptPrivate': doPrivate,
};
// Function to sync bot commands
async function syncTools(guildId = null) {
// Get existing commands within the guild
const commandResult = await getCommands(guildId);
const commands = commandResult.map((command) => command.name);
// Define command definitions
const commandDefs = [
{
name: 'deceive',
description: 'Deceptive chat using LLM',
options: [
{
name: 'text',
description: 'Text to prompt deceptive LLM with',
required: true,
type: 3,
},
],
},
{
name: 'argue',
description: 'Argumentative chat between LLMs',
options: [
{
name: 'text',
description: 'Text to prompt argumentative LLM with',
required: true,
type: 3,
},
],
},
];
// Register or update commands
for (const cmdDef of commandDefs) {
if (!commands.includes(cmdDef.name)) {
await registerCommand(cmdDef, null, guildId);
} else {
const cmd = commandResult.find((c) => c.name === cmdDef.name);
if (cmdDef.name!== cmd.name || cmdDef.description!== cmd.description) {
await updateCommand(cmdDef, null, cmd.id, guildId);
}
}
}
// Bind functions to interaction commands
for (const [name, func] of Object.entries(interactions)) {
interactionsCommands[name] = func;
}
// Remove unwanted commands
const toRemove = commandResult.filter((c) =>!ALL_COMMANDS.includes(c.name));
for (const cmd of toRemove) {
await deleteCommand(cmd.id, guildId);
}
return await getCommands();
}
// Function to deceive the user
async function doDeceive(interaction) {
const llmDeceive = await importer.import('llm deceive');
await triggerTyping(interaction.channel_id);
const response = await llmDeceive('Give the most wrong or incorrect response to, be as deceptive as possible:\n' + interaction.data.options[0].value);
return await updateInteraction(response.substring(0, 1800), interaction.id, interaction.token);
}
// Function to start an argument
async function doArgument(interaction) {
let count = 0;
return await argueLlama(interaction.data.options[0].value, async (prompt, answer) => {
if (count === 0) {
// Don't repost original prompt
await updateInteraction(answer.substring(0, 1800), interaction.id, interaction.token);
} else {
await createMessage(answer.substring(0, 1800), interaction.channel_id);
}
count++;
});
}
// Function to handle mention
async function doMention(interaction) {
const llmDeceive = await importer.import('llm deceive');
await triggerTyping(interaction.channel_id);
const response = await llmDeceive(interaction.content.replace('@' + DEFAULT_APPLICATION) + '\nBe as deceptive as possible and make it short.');
return await createMessage({
content: response.substring(0, 1800),
message_reference: {
message_id: interaction.id,
},
}, interaction.channel_id);
}
// Function to handle private message
async function doPrivate(interaction) {
const llmDeceive = await importer.import('llm deceive');
await triggerTyping(interaction.channel_id);
const response = await llmDeceive('Deceive me with the opposite of:\n' + interaction.content);
return await createMessage({
content: response.substring(0, 1800),
message_reference: {
message_id: interaction.id,
},
}, interaction.channel_id);
}
module.exports = syncTools;
The code starts by importing various dependencies using the importer.import()
function. The imported modules are:
discord API
:
registerCommand
, getCommands
, deleteCommand
, updateCommand
triggerTyping
, createMessage
, updateInteraction
discord gateway
: interactionsCommands
discord configuration
: DEFAULT_APPLICATION
argue with multiple llms
: argueLlama
The code defines a list of available commands: ALL_COMMANDS = ['deceive', 'argue']
.
There are four functions:
doDeceive(interaction)
llmDeceive
modulellmDeceive
to generate a response to the original promptdoArgument(interaction)
argueLlama
with the original prompt and a callback functiondoMention(interaction)
llmDeceive
modulellmDeceive
to generate a response to the original message (without the mention)doPrivate(interaction)
llmDeceive
modulellmDeceive
to generate a response to the opposite of the original message