MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / joinShortChunks

Function joinShortChunks

lib/embed-docs/utils.ts:236–255  ·  view source on GitHub ↗
(arr: string[], tokenLimit: number)

Source from the content-addressed store, hash-verified

234}
235
236export 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
257export function removeRepetition(str: string): string {
258 const regex = /^(.*?)(?:\s)?\1$/;

Callers 2

splitIntoTextChunksFunction · 0.85

Calls 1

getTokenCountFunction · 0.90

Tested by

no test coverage detected