跳至主要内容

Prompt Node

Prompt Node Screenshot

概述

Prompt节点用于创建聊天消息,这是一段带有附加"类型"的文本字符串,用于指示消息发送者(用户、助手、系统),并可选择附加"名称"。

Prompt节点也提供了与Text Node相同的插值功能,允许您动态地将值插入到消息中。

该节点还可以计算生成聊天消息的token数量,这对于根据消息大小切换使用的LLM等场景非常有用。

一个有用的模式是使用默认消息 {{input}} 将任何文本转换为提示信息。

输入项

标题数据类型描述默认值备注
Function CallobjectAn 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.
TypestringThe 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.
NamestringThe 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)stringThe 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.

示例1:使用插值生成聊天消息

  1. 创建一个提示节点。
  2. Type设置为user
  3. Prompt Text设置为Hello, {{name}}!
  4. 创建一个文本节点并将文本设置为John Doe
  5. 将文本节点连接到提示节点的name输入端口。
  6. 运行图表。Prompt节点的Output应该是一个类型为user、消息内容为Hello, John Doe!的聊天消息。

Prompt Node Example 1

示例2:将LLM响应转换为Assistant消息

  1. 创建一个Prompt节点。将内容保留为默认的{{input}}。将Type设置为assistant
  2. 创建一个聊天节点并将其Output连接到提示节点的input
  3. 给LLM一个提示文本并运行图表。您应该在提示节点中看到LLM的响应作为助手消息。

Prompt Node Example 2

错误处理

如果未提供Prompt TextType不是允许的类型之一(system, user, assistant, function),Prompt Node将会报错。

常见问题

问:我能否使用Prompt节点生成带有函数调用的聊天消息?

A: 是的,你可以使用Function Call输入来将函数调用附加到聊天消息上。这对于模拟LLM过去执行过的函数调用很有用。更多信息请参阅GPT Function节点。

另请参阅