(arr: string[], tokenLimit: number)
| 234 | } |
| 235 | |
| 236 | export function joinShortChunks(arr: string[], tokenLimit: number): string[] { |
| 237 | const result = []; |
| 238 | let tempStr = ""; |
| 239 | for (let i = 0; i < arr.length; i++) { |
| 240 | if ( |
| 241 | getTokenCount(RemoveMarkdown(tempStr + arr[i]).trim()) <= |
| 242 | tokenLimit + 7 // +7 corrects for chat formatting |
| 243 | ) { |
| 244 | tempStr += arr[i]; |
| 245 | } else { |
| 246 | // Do this in case the final string is too short |
| 247 | if (tempStr) result.push(tempStr); |
| 248 | tempStr = arr[i]; |
| 249 | } |
| 250 | //add the last short string sequence if it exists |
| 251 | if (i === arr.length - 1 && tempStr) result.push(tempStr); |
| 252 | } |
| 253 | |
| 254 | return result; |
| 255 | } |
| 256 | |
| 257 | export function removeRepetition(str: string): string { |
| 258 | const regex = /^(.*?)(?:\s)?\1$/; |
no test coverage detected