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:56 (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:74 (opens in a new tab)
funcResult()
static
funcResult(content
,name
):FuncResult
Create a function result message.
Parameters
Parameter | Type |
---|---|
content | Jsonifiable |
name | string |
Returns
Source
src/prompt/utils/message.ts:95 (opens in a new tab)
getMessage()
static
getMessage(response
):Assistant
|FuncCall
|ToolCall
Get the narrowed message from an EnrichedResponse.
Parameters
Parameter | Type |
---|---|
response | any |
Returns
Assistant
| FuncCall
| ToolCall
Source
src/prompt/utils/message.ts:130 (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:165 (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:169 (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:173 (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:157 (opens in a new tab)
isToolCall()
static
isToolCall(message
):message is ToolCall
Check if a message is a tool calls message.
Parameters
Parameter | Type |
---|---|
message | Msg |
Returns
message is ToolCall
Source
src/prompt/utils/message.ts:177 (opens in a new tab)
isToolResult()
static
isToolResult(message
):message is ToolResult
Check if a message is a tool call result message.
Parameters
Parameter | Type |
---|---|
message | Msg |
Returns
message is ToolResult
Source
src/prompt/utils/message.ts:181 (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:161 (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:186 (opens in a new tab)
narrow(message)
static
narrow(message
):User
Parameters
Parameter | Type |
---|---|
message | User |
Returns
Source
src/prompt/utils/message.ts:187 (opens in a new tab)
narrow(message)
static
narrow(message
):Assistant
Parameters
Parameter | Type |
---|---|
message | Assistant |
Returns
Source
src/prompt/utils/message.ts:188 (opens in a new tab)
narrow(message)
static
narrow(message
):FuncCall
Parameters
Parameter | Type |
---|---|
message | FuncCall |
Returns
Source
src/prompt/utils/message.ts:189 (opens in a new tab)
narrow(message)
static
narrow(message
):FuncResult
Parameters
Parameter | Type |
---|---|
message | FuncResult |
Returns
Source
src/prompt/utils/message.ts:190 (opens in a new tab)
narrow(message)
static
narrow(message
):ToolCall
Parameters
Parameter | Type |
---|---|
message | ToolCall |
Returns
Source
src/prompt/utils/message.ts:191 (opens in a new tab)
narrow(message)
static
narrow(message
):ToolResult
Parameters
Parameter | Type |
---|---|
message | ToolResult |
Returns
Source
src/prompt/utils/message.ts:192 (opens in a new tab)
narrowResponseMessage()
static
narrowResponseMessage(msg
):Assistant
|FuncCall
|ToolCall
Narrow a message received from the API. It only responds with role=assistant
Parameters
Parameter | Type |
---|---|
msg | Msg |
Returns
Assistant
| FuncCall
| ToolCall
Source
src/prompt/utils/message.ts:140 (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:20 (opens in a new tab)
toolCall()
static
toolCall(tool_calls
,opts
?):ToolCall
Create a function call message with argumets.
Parameters
Parameter | Type | Description |
---|---|---|
tool_calls | Tool [] | - |
opts ? | object | - |
opts.name ? | string | The name descriptor for the message.(message.name) |
Returns
Source
src/prompt/utils/message.ts:101 (opens in a new tab)
toolResult()
static
toolResult(content
,tool_call_id
,opts
?):ToolResult
Create a tool call result message.
Parameters
Parameter | Type | Description |
---|---|---|
content | Jsonifiable | - |
tool_call_id | string | - |
opts ? | object | - |
opts.name ? | string | The name of the tool which was called |
Returns
Source
src/prompt/utils/message.ts:117 (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. |