Prompt Node
概述
Prompt节点用于创建聊天消息,这是一段带有附加"类型"的文本字符串,用于指示消息发送者(用户、助手、系统),并可选择附加"名称"。
Prompt节点也提供了与Text Node相同的插值功能,允许您动态地将值插入到消息中。
该节点还可以计算生成聊天消息的token数量,这对于根据消息大小切换使用的LLM等场景非常有用。
一个有用的模式是使用默认消息 {{input}}
将任何文本转换为提示信息。
- 输入
- 输出
- 编辑器设置
输入项
标题 | 数据类型 | 描述 | 默认值 | 备注 |
---|---|---|---|---|
Function Call | object | An optional input that can be used to attach a function call to the chat message. | (empty) | This input is only available if Enable Function Call is enabled. |
Type | string | The type of the chat message. This input is only available if Use Type Input is enabled. | (empty) | The input will be coerced into a string if it is not a string. |
Name | string | The name to attach to the chat message. This input is only available if Use Name Input is enabled. | (empty) | The input will be coerced into a string if it is not a string. |
(custom names) | string | The values to be interpolated into the prompt text. The names of these inputs are dynamically generated based on the prompt text. | (empty) | The input will be coerced into a string if it is not a string. Each input creates a corresponding input port on the node. |
输出
标题 | 数据类型 | 描述 | 备注 |
---|---|---|---|
Output | chat-message | The generated chat message. | The output will be a chat message containing the interpolated prompt text, the type, and the optional name. |
Token Count | number | The number of tokens in the generated chat message. This output is only available if Compute Token Count is enabled. | The output will be a number representing the number of tokens in the chat message. |
编辑器设置
设置 | 描述 | 默认值 | 使用输入切换 | 输入数据类型 |
---|---|---|---|---|
Type | The type of the chat message. Can be one of the following: system , user , assistant , function . | user | Yes | string |
Name | The name to attach to the chat message. | (empty) | Yes | string |
Enable Function Call | If enabled, a Function Call input port will be added to the node, allowing you to attach a function call to the chat message. | False | No | N/A |
Compute Token Count | If enabled, a Token Count output port will be added to the node, allowing you to compute the number of tokens in the chat message. This can be useful for keeping track of the total number of tokens used in a conversation with an LLM. | False | No | N/A |
Prompt Text | The text of the chat message. You can use {{input}} to dynamically insert values into the message. | {{input}} | No | string |
示例1:使用插值生成聊天消息
- 创建一个提示节点。
- 将
Type
设置为user
。 - 将
Prompt Text
设置为Hello, {{name}}!
。 - 创建一个文本节点并将文本设置为
John Doe
。 - 将文本节点连接到提示节点的
name
输入端口。 - 运行图表。Prompt节点的
Output
应该是一个类型为user
、消息内容为Hello, John Doe!
的聊天消息。
示例2:将LLM响应转换为Assistant消息
- 创建一个Prompt节点。将内容保留为默认的
{{input}}
。将Type
设置为assistant
。 - 创建一个聊天节点并将其
Output
连接到提示节点的input
。 - 给LLM一个提示文本并运行图表。您应该在提示节点中看到LLM的响应作为助手消息。
错误处理
如果未提供Prompt Text
或Type
不是允许的类型之一(system
, user
, assistant
, function
),Prompt Node将会报错。
常见问题
问:我能否使用Prompt节点生成带有函数调用的聊天消息?
A: 是的,你可以使用Function Call
输入来将函数调用附加到聊天消息上。这对于模拟LLM过去执行过的函数调用很有用。更多信息请参阅GPT Function节点。