* Makes a copy of an interaction that can be mutated without changing * any objects/arrays that are part of the old state. We always make * a copy of the last (open) result group, so that we can simply append * to it; this is very slightly inefficient for the case where we're * handling a single
(oldInteraction: LLMInteraction)
| 101 | * handling a single end item with no results, but makes things simpler. |
| 102 | */ |
| 103 | function copyInteractionForMutation(oldInteraction: LLMInteraction) { |
| 104 | const oldResults = oldInteraction.results; |
| 105 | let oldLastGroup = oldInteraction.results[oldInteraction.results.length - 1]; |
| 106 | let newResults; |
| 107 | |
| 108 | if (oldLastGroup == undefined || oldLastGroup.length == MAX_GROUP_LENGTH) { |
| 109 | newResults = [...oldInteraction.results]; |
| 110 | } else { |
| 111 | newResults = oldInteraction.results.slice(0, -1); |
| 112 | newResults.push([...oldLastGroup]); |
| 113 | } |
| 114 | |
| 115 | return { ...oldInteraction, results: newResults }; |
| 116 | } |
| 117 | |
| 118 | function appendItemsToLLMLog( |
| 119 | oldLog: LLMLog, |
no test coverage detected