Assemble Prompt Node
Overview
A Chat Node takes in a single Prompt input which can be a single message, or an array of messages that forms the message chain. The Assemble Prompt Node is used to assemble multiple chat messages into a single prompt. It takes multiple chat messages or strings as inputs and outputs a single prompt containing all the messages.
If a string is connected to any of the inputs, it will be converted to a User type chat message with the string as the message.
- Inputs
- Outputs
- Editor Settings
Inputs
Title | Data Type | Description | Default Value | Notes |
---|---|---|---|---|
Message [i] | chat-message, chat-message[] | The ith chat message input to be assembled | N/A | Dynamic number of inputs based on how many connections there are |
Outputs
Title | Data Type | Description | Notes |
---|---|---|---|
Prompt | chat-message[] | The assembled chat messages | The output will be a single prompt resulting from assembling all valid chat messages |
Editor Settings
This node does not have any specific settings.
Example: Assembling Multiple Chat Messages
Let's say you have two Prompt nodes: one with the the AI's text "How can I assist you today?" and the user's response "Hello". If you want to assemble these two messages into a single prompt to feed into a Chat Node, you can do the following:
- Add an Assemble Prompt Node to your graph.
- Connect the output of the first Prompt node (AI's message) to
Message 1
of the Assemble Prompt Node. - Connect the output of the second Prompt node (user's response) to
Message 2
of the Assemble Prompt Node. - Connect the output of the Assemble Prompt Node to the
Prompt
input of a Chat Node.
Example: Appending Chat Messages in a Loop
A common use case for the Assemble Prompt Node is to append chat messages in a loop. This can be achieved by using a Loop Controller Node in conjunction with the Assemble Prompt Node.
Here's how you can set this up:
- Add a Loop Controller Node to your graph.
- Add an Assemble Prompt Node to your graph.
- Connect the
Output 1
of the Loop Controller Node toInput 1
of the Assemble Prompt Node. This will feed the output of the loop back into the Assemble Prompt Node. - Connect the
Output 1
of the Assemble Prompt Node toInput 1
of the Loop Controller Node. This will effectively create a feedback loop where the Assemble Prompt Node feeds back into itself. - Connect your first message to
Input 1 Default
of the Loop Controller Node. This will be the initial message that starts the loop. - Any additional messages that you want to append during each loop iteration can be connected to
Input 2
,Input 3
, etc of the Assemble Prompt Node.
The Assemble Prompt Node will flatten the output, resulting in a list of the current messages. During each loop iteration, the Assemble Prompt Node will append any additional messages connected to its inputs.
This setup allows you to dynamically append chat messages in a loop, which can be useful in various scenarios such as creating a chatbot that can carry on a conversation with a user.
Note: If you want to control the number of loop iterations, you can do so by setting the Max Iterations
property of the Loop Controller Node.
Here's a diagram to help visualize the setup:
This example demonstrates the power and flexibility of Rivet's node-based system, allowing you to create complex behaviors with just a few nodes.
Handling Missing Inputs
If an input is missing or not a chat message, the Assemble Prompt Node will simply ignore it during the assembling process. This can be useful when dealing with optional inputs that may not always be present.
Error Handling
If no valid chat message inputs are provided, the output will be an empty array.
Q: What happens if I connect a non-chat message to the Assemble Prompt Node?
A: The Assemble Prompt Node is designed to work with chat message inputs. If a non-chat message input is connected, the node will attempt to convert it to a chat message. In most cases, this will be a User type message with message being the data converted to a string. If this conversion isn't possible, the input will be ignored during the assembling process.
Q: Can I connect an Array Node to the Assemble Prompt Node?
A: Yes, you can connect an Array Node to the Assemble Prompt Node. Each element of the array will be treated as a separate chat message to be assembled (flattens the array).
Q: How does the Assemble Prompt Node handle empty strings or null values?
A: The Assemble Prompt Node will ignore any inputs that are null or not a chat message. Empty chat messages, however, will be included in the assembling operation.