Class: Msg
Utility class for creating and checking message types.
Constructors
new Msg()
new Msg():
Msg
Returns
Methods
assistant()
static
assistant(content
,opts
?):Assistant
Create an assistant message. Cleans indentation and newlines by default.
Parameters
Parameter | Type | Description |
---|---|---|
content | string | - |
opts ? | object | - |
opts.cleanContent ? | boolean | Whether to clean extra newlines and indentation. Defaults to true. |
opts.name ? | string | Custom name for the message. |
Returns
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
Parameter | Type | Description |
---|---|---|
function_call | object | - |
function_call.arguments | string | Arguments to pass to the function. |
function_call.name ? | string | Name of the function to call. |
opts ? | object | - |
opts.name ? | string | The name descriptor for the message.(message.name) |
Returns
Source
src/prompt/utils/message.ts:70 (opens in a new tab)
funcResult()
static
funcResult(content
,name
):FuncResult
Create a function result message.
Parameters
Parameter | Type |
---|---|
content | string | object | unknown [] |
name | string |
Returns
Source
src/prompt/utils/message.ts:92 (opens in a new tab)
getMessage()
Get the narrowed message from an EnrichedResponse.
Parameters
Parameter | Type |
---|---|
response | any |
Returns
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
Parameter | Type |
---|---|
message | Msg |
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
Parameter | Type |
---|---|
message | Msg |
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
Parameter | Type |
---|---|
message | Msg |
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
Parameter | Type |
---|---|
message | Msg |
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
Parameter | Type |
---|---|
message | Msg |
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
Parameter | Type |
---|---|
message | System |
Returns
Source
src/prompt/utils/message.ts:148 (opens in a new tab)
narrow(message)
static
narrow(message
):User
Parameters
Parameter | Type |
---|---|
message | User |
Returns
Source
src/prompt/utils/message.ts:149 (opens in a new tab)
narrow(message)
static
narrow(message
):Assistant
Parameters
Parameter | Type |
---|---|
message | Assistant |
Returns
Source
src/prompt/utils/message.ts:150 (opens in a new tab)
narrow(message)
static
narrow(message
):FuncCall
Parameters
Parameter | Type |
---|---|
message | FuncCall |
Returns
Source
src/prompt/utils/message.ts:151 (opens in a new tab)
narrow(message)
static
narrow(message
):FuncResult
Parameters
Parameter | Type |
---|---|
message | FuncResult |
Returns
Source
src/prompt/utils/message.ts:152 (opens in a new tab)
narrowResponseMessage()
Narrow a message received from the API. It only responds with role=assistant
Parameters
Parameter | Type |
---|---|
msg | Msg |
Returns
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
Parameter | Type | Description |
---|---|---|
content | string | - |
opts ? | object | - |
opts.cleanContent ? | boolean | Whether to clean extra newlines and indentation. Defaults to true. |
opts.name ? | string | Custom name for the message. |
Returns
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
Parameter | Type | Description |
---|---|---|
content | string | - |
opts ? | object | - |
opts.cleanContent ? | boolean | Whether to clean extra newlines and indentation. Defaults to true. |
opts.name ? | string | Custom name for the message. |