Passa al contenuto principale

Class: PromptHelper

A collection of helper functions for working with prompts.

Constructors

constructor

new PromptHelper(contextWindow?, numOutput?, chunkOverlapRatio?, chunkSizeLimit?, tokenizer?, separator?)

Parameters

NameTypeDefault value
contextWindownumberDEFAULT_CONTEXT_WINDOW
numOutputnumberDEFAULT_NUM_OUTPUTS
chunkOverlapRationumberDEFAULT_CHUNK_OVERLAP_RATIO
chunkSizeLimit?numberundefined
tokenizer?(text: string) => Uint32Arrayundefined
separatorstring" "

Defined in

packages/core/src/PromptHelper.ts:40

Properties

chunkOverlapRatio

chunkOverlapRatio: number = DEFAULT_CHUNK_OVERLAP_RATIO

Defined in

packages/core/src/PromptHelper.ts:35


chunkSizeLimit

Optional chunkSizeLimit: number

Defined in

packages/core/src/PromptHelper.ts:36


contextWindow

contextWindow: number = DEFAULT_CONTEXT_WINDOW

Defined in

packages/core/src/PromptHelper.ts:33


numOutput

numOutput: number = DEFAULT_NUM_OUTPUTS

Defined in

packages/core/src/PromptHelper.ts:34


separator

separator: string = " "

Defined in

packages/core/src/PromptHelper.ts:38


tokenizer

tokenizer: (text: string) => Uint32Array

Type declaration

▸ (text): Uint32Array

Parameters
NameType
textstring
Returns

Uint32Array

Defined in

packages/core/src/PromptHelper.ts:37

Methods

getAvailableChunkSize

Private getAvailableChunkSize(prompt, numChunks?, padding?): number

Find the maximum size of each chunk given a prompt.

Parameters

NameTypeDefault value
promptSimplePromptundefined
numChunksnumber1
paddingnumber5

Returns

number

Defined in

packages/core/src/PromptHelper.ts:76


getAvailableContextSize

Private getAvailableContextSize(prompt): number

Given a prompt, return the maximum size of the inputs to the prompt.

Parameters

NameType
promptSimplePrompt

Returns

number

Defined in

packages/core/src/PromptHelper.ts:61


getTextSplitterGivenPrompt

getTextSplitterGivenPrompt(prompt, numChunks?, padding?): SentenceSplitter

Creates a text splitter with the correct chunk sizes and overlaps given a prompt.

Parameters

NameTypeDefault value
promptSimplePromptundefined
numChunksnumber1
paddingnumberDEFAULT_PADDING

Returns

SentenceSplitter

Defined in

packages/core/src/PromptHelper.ts:99


repack

repack(prompt, textChunks, padding?): string[]

Repack resplits the strings based on the optimal text splitter.

Parameters

NameTypeDefault value
promptSimplePromptundefined
textChunksstring[]undefined
paddingnumberDEFAULT_PADDING

Returns

string[]

Defined in

packages/core/src/PromptHelper.ts:120