Document Context Modifiers
This commit is contained in:
parent
4a4ccdb603
commit
1c60ccf14a
4 changed files with 111 additions and 0 deletions
23
examples/contextModifiers/reimplementAuthorsNote.js
Normal file
23
examples/contextModifiers/reimplementAuthorsNote.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Checkout the repo examples to get an idea of other ways you can use scripting
|
||||
// https://github.com/AIDungeon/Scripting/blob/master/examples
|
||||
|
||||
// info.memoryLength is the length of the memory section of text.
|
||||
// info.maxChars is the maximum length that text can be. The server will truncate the text you return to this length.
|
||||
|
||||
// This modifier re-implements Author's Note as an example.
|
||||
const modifier = (text) => {
|
||||
const memory = info.memoryLength ? text.slice(0, info.memoryLength) : ''
|
||||
const context = info.memoryLength ? text.slice(info.memoryLength + 1) : text
|
||||
const lines = context.split("\n")
|
||||
if (lines.length > 2) {
|
||||
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 = [memory, combinedLines].join("")
|
||||
return { text: finalText }
|
||||
}
|
||||
|
||||
// Don't modify this part
|
||||
modifier(text)
|
Reference in a new issue