From f85a96c4bb8096ad3f3273cb754e9f0ea7d22b78 Mon Sep 17 00:00:00 2001 From: JaonHax Date: Mon, 1 Feb 2021 16:39:18 -0600 Subject: [PATCH] Create context-modifier.js --- contributed/AIDECLib/context-modifier.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 contributed/AIDECLib/context-modifier.js diff --git a/contributed/AIDECLib/context-modifier.js b/contributed/AIDECLib/context-modifier.js new file mode 100644 index 0000000..46f3f19 --- /dev/null +++ b/contributed/AIDECLib/context-modifier.js @@ -0,0 +1,22 @@ + +const modifier = (text) => { + let stop = state.stop || state.stopped + + const contextMemory = info.memoryLength ? text.slice(0, info.memoryLength) : '' + const context = info.memoryLength ? text.slice(info.memoryLength) : text + const lines = context.split("\n") + + if (lines.length > 2) { + // Uncomment to use this! + // const authorsNote = "Everyone in this story is an AI programmer." + // lines.splice(-3, 0, `[Author's note: ${authorsNote}]`) + } + + // Make sure the new context isn't too long, or it will get truncated by the server. + const combinedLines = lines.join("\n").slice(-(info.maxChars - info.memoryLength)) + const finalText = [contextMemory, combinedLines].join("") + return { text: finalText, stop } +} + +// Don't modify this part +modifier(text)