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

Function chunkString

lib/utils.ts:143–166  ·  view source on GitHub ↗
(
  text: string,
  chunkSize: number,
  overlap: number,
)

Source from the content-addressed store, hash-verified

141}
142
143export function chunkString(
144 text: string,
145 chunkSize: number,
146 overlap: number,
147): string[] {
148 /** Splits a long string into chunks of length `chunkSize`, with overlap `overlap`
149 * Useful for splitting up long strings for GPT. **/
150 const encoding = tokenizer.encode(text);
151 console.log("Chunking string. Number of tokens = " + encoding.length);
152
153 const chunks = [];
154 let i = 0;
155 let start,
156 end = 0;
157 while (end < encoding.length) {
158 start = i * (chunkSize - overlap);
159 end = start + chunkSize;
160
161 chunks.push(tokenizer.decode(encoding.slice(start, end)));
162 i++;
163 }
164 console.log("Outputting " + chunks.length + " chunks of length " + chunkSize);
165 return chunks;
166}
167
168export function objectNotEmpty(obj: Object): boolean {
169 return Object.keys(obj).length > 0;

Callers 2

summarizeTextFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected