Improved system prompt
This commit is contained in:
30
discord.mjs
30
discord.mjs
@@ -81,21 +81,41 @@ const ALLOW_LIST = new Set([
|
|||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
function splitDiscordMessage(text) {
|
function splitDiscordMessage(text) {
|
||||||
const MAX = 1900; // buffer
|
const MAX = 1900; // maximum payload size
|
||||||
|
const MIN = 100; // avoid tiny chunks
|
||||||
const chunks = [];
|
const chunks = [];
|
||||||
let start = 0;
|
let start = 0;
|
||||||
|
|
||||||
while (start < text.length) {
|
while (start < text.length) {
|
||||||
let end = Math.min(start + MAX, text.length);
|
let end = Math.min(start + MAX, text.length);
|
||||||
|
|
||||||
|
// Try to break on a newline first, then on a space
|
||||||
|
if (end < text.length) {
|
||||||
const nl = text.lastIndexOf('\n', end);
|
const nl = text.lastIndexOf('\n', end);
|
||||||
const sp = text.lastIndexOf(' ', end);
|
const sp = text.lastIndexOf(' ', end);
|
||||||
if (nl > start) end = nl + 1;
|
const splitPos = Math.max(nl, sp);
|
||||||
else if (sp > start) end = sp + 1;
|
if (splitPos > start) end = splitPos + 1; // keep the delimiter
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the chunk is too short, pull in the next delimiter
|
||||||
|
if (end - start < MIN && end < text.length) {
|
||||||
|
const nextNL = text.indexOf('\n', end);
|
||||||
|
const nextSP = text.indexOf(' ', end);
|
||||||
|
const nextPos = Math.min(
|
||||||
|
nextNL === -1 ? Infinity : nextNL,
|
||||||
|
nextSP === -1 ? Infinity : nextSP
|
||||||
|
);
|
||||||
|
if (nextPos !== Infinity && nextPos < text.length) {
|
||||||
|
end = nextPos + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
chunks.push(text.slice(start, end));
|
chunks.push(text.slice(start, end));
|
||||||
start = end;
|
start = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
return chunks;
|
return chunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* 6️⃣ Core message handler */
|
/* 6️⃣ Core message handler */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
@@ -121,7 +141,7 @@ async function handleMessage(msg) {
|
|||||||
if (!msg.content.includes(mention)) return; // not a mention
|
if (!msg.content.includes(mention)) return; // not a mention
|
||||||
|
|
||||||
/* 5a Build the system prompt (Silicon Duck persona) */
|
/* 5a Build the system prompt (Silicon Duck persona) */
|
||||||
const systemPrompt = `You are Silicon Duck, a helpful, cheerful, and generally excited creative Discord bot in the server 'Mikael Lövqvist's shenanigans'. You do NOT retain any history across messages. Your tag is <@${client.user.id}>, do not tag yourself in replies. The current channel is '${msg.channel.name}'. The user is ${msg.author.username} with tag <@${msg.author.id}>. You should not produce code examples unless explicitly asked. Do not make markdown tables, discord does not support those. You are running the model ${MODEL} using Ollama and OpenWebUI. Dial back emoji use.`;
|
const systemPrompt = `You are Silicon Duck, a helpful, cheerful, and generally excited creative Discord bot in the server 'Mikael Lövqvist's shenanigans'. You do NOT retain any history across messages. Your tag is <@${client.user.id}>, do not tag yourself in replies. The current channel is '${msg.channel.name}'. The user is ${msg.author.username} with tag <@${msg.author.id}>. You should not produce code examples unless explicitly asked. Do not make markdown tables, discord does not support those. You are running the model ${MODEL} using Ollama and OpenWebUI. Dial back emoji use. <@1108665021048819762> Use <:siduck:1103592588658868314> when you need to express yourself as an emoji. That's your avatar. It is a duck carved out of semiconductor grade silicon.`;
|
||||||
|
|
||||||
/* 5b Check for special commands that use PERMISSIONS */
|
/* 5b Check for special commands that use PERMISSIONS */
|
||||||
if (msg.content.startsWith('!create ')) {
|
if (msg.content.startsWith('!create ')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user