Class: Msg
Utility class for creating and checking message types.
Constructors
new Msg()
new Msg():
Msg
Returns
Methods
assistant()
staticassistant(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()
staticfuncCall(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()
staticfuncResult(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()
staticgetMessage(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()
staticisAssistant(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()
staticisFuncCall(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()
staticisFuncResult(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()
staticisSystem(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()
staticisToolCall(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()
staticisToolResult(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()
staticisUser(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)
staticnarrow(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)
staticnarrow(message):User
Parameters
| Parameter | Type |
|---|---|
message | User |
Returns
Source
src/prompt/utils/message.ts:187 (opens in a new tab)
narrow(message)
staticnarrow(message):Assistant
Parameters
| Parameter | Type |
|---|---|
message | Assistant |
Returns
Source
src/prompt/utils/message.ts:188 (opens in a new tab)
narrow(message)
staticnarrow(message):FuncCall
Parameters
| Parameter | Type |
|---|---|
message | FuncCall |
Returns
Source
src/prompt/utils/message.ts:189 (opens in a new tab)
narrow(message)
staticnarrow(message):FuncResult
Parameters
| Parameter | Type |
|---|---|
message | FuncResult |
Returns
Source
src/prompt/utils/message.ts:190 (opens in a new tab)
narrow(message)
staticnarrow(message):ToolCall
Parameters
| Parameter | Type |
|---|---|
message | ToolCall |
Returns
Source
src/prompt/utils/message.ts:191 (opens in a new tab)
narrow(message)
staticnarrow(message):ToolResult
Parameters
| Parameter | Type |
|---|---|
message | ToolResult |
Returns
Source
src/prompt/utils/message.ts:192 (opens in a new tab)
narrowResponseMessage()
staticnarrowResponseMessage(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()
staticsystem(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()
statictoolCall(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()
statictoolResult(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()
staticuser(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. |