PromptSectionBase class

Abstract Base class for most prompt sections.

Remarks

This class provides a default implementation of renderAsText() so that derived classes only need to implement renderAsMessages().

Constructors

PromptSectionBase(number, boolean, string, string)

Creates a new 'PromptSectionBase' instance.

Properties

required

If true the section is mandatory otherwise it can be safely dropped.

separator
textPrefix
tokens

The requested token budget for this section.

  • Values between 0.0 and 1.0 represent a percentage of the total budget and the section will be layed out proportionally to all other sections.
  • Values greater than 1.0 represent the max number of tokens the section should be allowed to consume.

Methods

getMessageText(Message<string>)

Returns the content of a message as a string.

renderAsMessages(TurnContext, Memory, PromptFunctions, Tokenizer, number)

Renders the prompt section as a list of Message objects.

renderAsText(TurnContext, Memory, PromptFunctions, Tokenizer, number)

Renders the prompt section as a string of text.

Constructor Details

PromptSectionBase(number, boolean, string, string)

Creates a new 'PromptSectionBase' instance.

new PromptSectionBase(tokens?: number, required?: boolean, separator?: string, textPrefix?: string)

Parameters

tokens

number

Optional. Sizing strategy for this section. Defaults to -1, 'auto'.

required

boolean

Optional. Indicates if this section is required. Defaults to true.

separator

string

Optional. Separator to use between sections when rendering as text. Defaults to \n.

textPrefix

string

Optional. Prefix to use for text output. Defaults to an empty string.

Property Details

required

If true the section is mandatory otherwise it can be safely dropped.

required: boolean

Property Value

boolean

separator

separator: string

Property Value

string

textPrefix

textPrefix: string

Property Value

string

tokens

The requested token budget for this section.

  • Values between 0.0 and 1.0 represent a percentage of the total budget and the section will be layed out proportionally to all other sections.
  • Values greater than 1.0 represent the max number of tokens the section should be allowed to consume.
tokens: number

Property Value

number

Method Details

getMessageText(Message<string>)

Returns the content of a message as a string.

static function getMessageText(message: Message<string>): string

Parameters

message

Message<string>

Message to get the text of.

Returns

string

The message content as a string.

renderAsMessages(TurnContext, Memory, PromptFunctions, Tokenizer, number)

Renders the prompt section as a list of Message objects.

function renderAsMessages(context: TurnContext, memory: Memory, functions: PromptFunctions, tokenizer: Tokenizer, maxTokens: number): Promise<RenderedPromptSection<Message<any>[]>>

Parameters

context

TurnContext

Context for the current turn of conversation.

memory
Memory

Interface for accessing state variables.

functions
PromptFunctions

Functions for rendering prompts.

tokenizer
Tokenizer

Tokenizer to use for encoding/decoding text.

maxTokens

number

Maximum number of tokens allowed for the rendered prompt.

Returns

Promise<RenderedPromptSection<Message<any>[]>>

The rendered prompt section.

Remarks

MUST be implemented by derived classes.

renderAsText(TurnContext, Memory, PromptFunctions, Tokenizer, number)

Renders the prompt section as a string of text.

function renderAsText(context: TurnContext, memory: Memory, functions: PromptFunctions, tokenizer: Tokenizer, maxTokens: number): Promise<RenderedPromptSection<string>>

Parameters

context

TurnContext

Context for the current turn of conversation.

memory
Memory

Interface for accessing state variables.

functions
PromptFunctions

Functions for rendering prompts.

tokenizer
Tokenizer

Tokenizer to use for encoding/decoding text.

maxTokens

number

Maximum number of tokens allowed for the rendered prompt.

Returns

Promise<RenderedPromptSection<string>>

The rendered prompt section.