* 👷 basic skeleton for building with pkg * ⚡️ first attempt at syncing in .ts * 🎨 change lancedb storage format * 🚧 add chunking to LanceDbIndex * 🔥 move transformers.js from gui to core * 🐛 fix tsc build * 🐛 fix bugs loading native modules in vscode extension * 👷 copy wasms and fix other syncing bugs * 👷 esbuild modification to allow importMetaUrl for transformers.js * 👷 add sharp as external module so transformers.js can be loade * 🐛 more indexing fixes * ✨ retrieve from lancedb * 🎨 respect .gitignore when traversing file tree * 🐛 fix logic bugs in indexing * 🐛 fix prompt construction bug causing doubling of context items * 🔥 remove legacy files * 📌 vendor transformers.js to avoid dependency on sharp * 👷 package necessary native modules * 🎨 respect multi-root workspaces when indexing/retrieving * 🔥 only ship onnxruntime-node binaries for current platform * 🎨 trigger re-indexing on git branch change * 🎨 make indexing resumable * ✨ add folder context provider * ✨ folders context provider in dropdown * 🐛 polishing folders context provider
32 lines
763 B
TypeScript
32 lines
763 B
TypeScript
import { ChunkWithoutID } from "../..";
|
|
import { countTokens } from "../../llm/countTokens";
|
|
|
|
export function* basicChunker(
|
|
contents: string,
|
|
maxChunkSize: number
|
|
): Generator<ChunkWithoutID> {
|
|
let chunkContent = "";
|
|
let chunkTokens = 0;
|
|
let startLine = 0;
|
|
let currLine = 0;
|
|
|
|
for (const line of contents.split("\n")) {
|
|
const lineTokens = countTokens(line, "gpt-4");
|
|
if (chunkTokens + lineTokens > maxChunkSize) {
|
|
yield { content: chunkContent, startLine, endLine: currLine - 1 };
|
|
chunkContent = "";
|
|
chunkTokens = 0;
|
|
startLine = currLine;
|
|
}
|
|
|
|
chunkContent += line + "\n";
|
|
chunkTokens += lineTokens;
|
|
currLine++;
|
|
}
|
|
|
|
yield {
|
|
content: chunkContent,
|
|
startLine,
|
|
endLine: currLine - 1,
|
|
};
|
|
}
|