Improved system prompt

This commit is contained in:
2026-01-13 22:20:45 +01:00
parent 62d8ae1034
commit 02d32352d6

View File

@@ -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 chunks = []; const MIN = 100; // avoid tiny chunks
let start = 0; const chunks = [];
while (start < text.length) { let start = 0;
let end = Math.min(start + MAX, text.length);
const nl = text.lastIndexOf('\n', end);
const sp = text.lastIndexOf(' ', end);
if (nl > start) end = nl + 1;
else if (sp > start) end = sp + 1;
chunks.push(text.slice(start, end));
start = end;
}
return chunks;
}
while (start < 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 sp = text.lastIndexOf(' ', end);
const splitPos = Math.max(nl, sp);
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));
start = end;
}
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 ')) {