Skip to content
Snippets Groups Projects
Unverified Commit 468bda59 authored by Alex Yang's avatar Alex Yang Committed by GitHub
Browse files

fix: correct warning when chunk size smaller than 0 (#1297)

parent 6f3a31ca
No related branches found
No related tags found
No related merge requests found
---
"@llamaindex/core": patch
---
fix: correct warning when chunk size smaller than 0
......@@ -76,7 +76,7 @@ export class PromptHelper {
* @param prompt
* @returns
*/
private getAvailableContextSize(prompt: PromptTemplate) {
#getAvailableContextSize(prompt: PromptTemplate) {
const emptyPromptText = getEmptyPromptTxt(prompt);
const promptTokens = this.tokenizer.encode(emptyPromptText);
const numPromptTokens = promptTokens.length;
......@@ -87,12 +87,12 @@ export class PromptHelper {
/**
* Find the maximum size of each chunk given a prompt.
*/
private getAvailableChunkSize(
#getAvailableChunkSize(
prompt: PromptTemplate,
numChunks = 1,
padding = 5,
): number {
const availableContextSize = this.getAvailableContextSize(prompt);
const availableContextSize = this.#getAvailableContextSize(prompt);
const result = Math.floor(availableContextSize / numChunks) - padding;
......@@ -111,9 +111,12 @@ export class PromptHelper {
numChunks = 1,
padding = DEFAULT_PADDING,
) {
const chunkSize = this.getAvailableChunkSize(prompt, numChunks, padding);
if (chunkSize === 0) {
throw new Error("Got 0 as available chunk size");
const chunkSize = this.#getAvailableChunkSize(prompt, numChunks, padding);
if (chunkSize <= 0) {
/**
* If you see this error, it means that the input is larger than LLM context window.
*/
throw new TypeError(`Chunk size ${chunkSize} is not positive.`);
}
const chunkOverlap = this.chunkOverlapRatio * chunkSize;
return new SentenceSplitter({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment