Documentation
Classes
Msg

Class: Msg

Utility class for creating and checking message types.

Constructors

new Msg()

new Msg(): Msg

Returns

Msg

Methods

assistant()

static assistant(content, opts?): Assistant

Create an assistant message. Cleans indentation and newlines by default.

Parameters

ParameterTypeDescription
contentstring-
opts?object-
opts.cleanContent?booleanWhether to clean extra newlines and indentation. Defaults to true.
opts.name?stringCustom name for the message.

Returns

Assistant

Source

src/prompt/utils/message.ts:52 (opens in a new tab)


funcCall()

static funcCall(function_call, opts?): FuncCall

Create a function call message with argumets.

Parameters

ParameterTypeDescription
function_callobject-
function_call.argumentsstringArguments to pass to the function.
function_call.name?stringName of the function to call.
opts?object-
opts.name?stringThe name descriptor for the message.(message.name)

Returns

FuncCall

Source

src/prompt/utils/message.ts:70 (opens in a new tab)


funcResult()

static funcResult(content, name): FuncResult

Create a function result message.

Parameters

ParameterType
contentstring | object | unknown[]
namestring

Returns

FuncResult

Source

src/prompt/utils/message.ts:92 (opens in a new tab)


getMessage()

static getMessage(response): Assistant | FuncCall

Get the narrowed message from an EnrichedResponse.

Parameters

ParameterType
responseany

Returns

Assistant | FuncCall

Source

src/prompt/utils/message.ts:102 (opens in a new tab)


isAssistant()

static isAssistant(message): message is Assistant

Check if a message is an assistant message.

Parameters

ParameterType
messageMsg

Returns

message is Assistant

Source

src/prompt/utils/message.ts:135 (opens in a new tab)


isFuncCall()

static isFuncCall(message): message is FuncCall

Check if a message is a function call message with arguments.

Parameters

ParameterType
messageMsg

Returns

message is FuncCall

Source

src/prompt/utils/message.ts:139 (opens in a new tab)


isFuncResult()

static isFuncResult(message): message is FuncResult

Check if a message is a function result message.

Parameters

ParameterType
messageMsg

Returns

message is FuncResult

Source

src/prompt/utils/message.ts:143 (opens in a new tab)


isSystem()

static isSystem(message): message is System

Check if a message is a system message.

Parameters

ParameterType
messageMsg

Returns

message is System

Source

src/prompt/utils/message.ts:127 (opens in a new tab)


isUser()

static isUser(message): message is User

Check if a message is a user message.

Parameters

ParameterType
messageMsg

Returns

message is User

Source

src/prompt/utils/message.ts:131 (opens in a new tab)


narrow()

narrow(message)

static narrow(message): System

Narrow a ChatModel.Message to a specific type.

Parameters
ParameterType
messageSystem
Returns

System

Source

src/prompt/utils/message.ts:148 (opens in a new tab)

narrow(message)

static narrow(message): User

Parameters
ParameterType
messageUser
Returns

User

Source

src/prompt/utils/message.ts:149 (opens in a new tab)

narrow(message)

static narrow(message): Assistant

Parameters
ParameterType
messageAssistant
Returns

Assistant

Source

src/prompt/utils/message.ts:150 (opens in a new tab)

narrow(message)

static narrow(message): FuncCall

Parameters
ParameterType
messageFuncCall
Returns

FuncCall

Source

src/prompt/utils/message.ts:151 (opens in a new tab)

narrow(message)

static narrow(message): FuncResult

Parameters
ParameterType
messageFuncResult
Returns

FuncResult

Source

src/prompt/utils/message.ts:152 (opens in a new tab)


narrowResponseMessage()

static narrowResponseMessage(msg): Assistant | FuncCall

Narrow a message received from the API. It only responds with role=assistant

Parameters

ParameterType
msgMsg

Returns

Assistant | FuncCall

Source

src/prompt/utils/message.ts:112 (opens in a new tab)


system()

static system(content, opts?): System

Create a system message. Cleans indentation and newlines by default.

Parameters

ParameterTypeDescription
contentstring-
opts?object-
opts.cleanContent?booleanWhether to clean extra newlines and indentation. Defaults to true.
opts.name?stringCustom name for the message.

Returns

System

Source

src/prompt/utils/message.ts:16 (opens in a new tab)


user()

static user(content, opts?): User

Create a user message. Cleans indentation and newlines by default.

Parameters

ParameterTypeDescription
contentstring-
opts?object-
opts.cleanContent?booleanWhether to clean extra newlines and indentation. Defaults to true.
opts.name?stringCustom name for the message.

Returns

User

Source

src/prompt/utils/message.ts:34 (opens in a new tab)