Passa al contenuto principale

Class: PromptHelper

A collection of helper functions for working with prompts.

Constructors

new PromptHelper()

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

Parameters

contextWindow: number= DEFAULT_CONTEXT_WINDOW

numOutput: number= DEFAULT_NUM_OUTPUTS

chunkOverlapRatio: number= DEFAULT_CHUNK_OVERLAP_RATIO

chunkSizeLimit?: number

tokenizer?

separator?: string= " "

Returns

PromptHelper

Source

packages/core/src/PromptHelper.ts:41

Properties

chunkOverlapRatio

chunkOverlapRatio: number = DEFAULT_CHUNK_OVERLAP_RATIO

Source

packages/core/src/PromptHelper.ts:35


chunkSizeLimit?

optional chunkSizeLimit: number

Source

packages/core/src/PromptHelper.ts:36


contextWindow

contextWindow: number = DEFAULT_CONTEXT_WINDOW

Source

packages/core/src/PromptHelper.ts:33


numOutput

numOutput: number = DEFAULT_NUM_OUTPUTS

Source

packages/core/src/PromptHelper.ts:34


separator

separator: string = " "

Source

packages/core/src/PromptHelper.ts:38


tokenizer()

tokenizer: (text) => Uint32Array

Parameters

text: string

Returns

Uint32Array

Source

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

prompt: SimplePrompt

numChunks: number= 1

padding: number= 5

Returns

number

Source

packages/core/src/PromptHelper.ts:77


getAvailableContextSize()

private getAvailableContextSize(prompt): number

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

Parameters

prompt: SimplePrompt

Returns

number

Source

packages/core/src/PromptHelper.ts:62


getTextSplitterGivenPrompt()

getTextSplitterGivenPrompt(prompt, numChunks, padding): SentenceSplitter

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

Parameters

prompt: SimplePrompt

numChunks: number= 1

padding: number= DEFAULT_PADDING

Returns

SentenceSplitter

Source

packages/core/src/PromptHelper.ts:100


repack()

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

Repack resplits the strings based on the optimal text splitter.

Parameters

prompt: SimplePrompt

textChunks: string[]

padding: number= DEFAULT_PADDING

Returns

string[]

Source

packages/core/src/PromptHelper.ts:121