Skip to content
This repository was archived by the owner on Sep 8, 2023. It is now read-only.
This repository was archived by the owner on Sep 8, 2023. It is now read-only.

reimplementAuthorsNote.js truncation at the end is nonsensical/bugged. #18

@Slight0

Description

@Slight0

Towards the end of the context modifier example reimplementAuthorsNote.js some code tries to truncate the output so as to not exceed info.memoryLength or info.maxChars, but ends up needlessly truncating the most recent actions instead.

Edit Note: (Fixed an issue with my reasoning. The bug is there, but for a different set of reasons)

// 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 }

So at this point the function has split the incoming text into contextMemory and context where context is the length of memoryLength representing the AI's memory window. lines.join("\n") is context with the author's notes injected (3 lines back from front). It's assumed that the input text was an arbitrary length that could have exceeded maxChars. I believe the above code is trying to truncate the modified output text so that finalText is truncated from the front (ie oldest player actions) to maxChars. (otherwise the server would truncate the back losing the newest actions).

So the mistakes it makes are that it assumes lines.join("\n") is already info.memoryLength, which is false because it is context (which is length memoryLength) with the author's notes injected, pushing it over. Further, truncation is only happening on the context portion of the text when the intent here is to truncate all of text; context portion should be untouched. Last, truncation is weird when maxChars is greater than memoryLength. Like, if memoryLength is 20 and maxChars is 21, that's slice(-1) which results in the very last char of the most recent player actions making it through. Why would we throw away the most recent actions right? We want to truncate the oldest actions.

Below is the fixed code that should replace the above.

// Make sure the final context isn't too long, or it will get truncated by the server.
const finalText = (contextMemory + lines.join("\n")).slice(-info.maxChars);
return { text: finalText }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions