You can use the nodes in the
Flow
default library to parametrically enable or disable parts of your Runchat and prevent them from updating. This is useful if you want your runchat to perform different actions under different conditions.
The Switch
node enables or disables outputs based on the switchVal
. When the switch is On
, then the trueVal
output is enabled and all connected downstream nodes will update. When the switch is Off
, then the falseVal
output is enabled and all connected downstream nodes will update. Nodes downstream from the disabled output will not update.
Generally speaking, some other node in your runchat will control whether the switch
should be on or off. There are several common approaches to this. One flexible approach is to use a Prompt
. The advantage of using prompts to control the switch is you can reason about subjective circumstances and still control your application flow. In your Prompt
node, set the Output Format
to boolean
to ensure that the model only outputs True
or False
. Then frame your prompt as a question: “is this x?”.
As an amusing example, you could create an app or game where players need to try to create images of cute things by combining only negative words. You could then use a Prompt
node to look at the image and judge if it is “cute”’. Based on this, you could add to the players score or end the game.
If the switch condition can be measured empirically then you can also use a Code
node to write a script to output a boolean value. This is typically the case for checking things like:
Here is an example of using a switch to control how our Runchat updates if a key is no found in an object. The Get Key
node returns “Key not found” of the given key doesn’t exist, and we can then use the Equals
node to return True if the input is “Key not found” and false otherwise. This then becomes our switch value.
This allows us to gracefully handle when things go off the rails in our Runchat. We could for instance display an error message, or send an email, or create the key etc.