Skip to content

Prompt Variables

ljleb edited this page Apr 10, 2023 · 17 revisions

Variables are a convenience feature that allows you to reuse part of a prompt without having to repeat yourself. It is a prompt element that allows part of a prompt to be stored under a label.

Here is how you define a variable:

$label_name = here is my prompt! 

The following section will cover how to use them.

Examples of usage

To use it in your prompt, just write a dollar sign $ followed by the variable name. (Note that you HAVE to define the variable before using it in your prompt!) For instance:

$cat = cat, fluffy, striped fur

very cute $cat

This will be translated into:

very cute cat, fluffy, striped fur

Here is another example:

$subject = a man
$color = blue

superb picture of $subject wearing a $color jacket and $color jeans

This will be translated into:

superb picture of a man wearing a blue jacket and blue jeans

Scopes

You can nest prompt variable definitions into one another, like so:

$head_description = black hair, sunglasses, 
$outfit_description = green coat, white fancy necklace, 

$subject = $head_description $outfit_description

$subject

This translates to:

black hair, sunglasses, green coat, white fancy necklace, 

If you want to define a prompt variable as a prompt that has more than one line, you can add a weight of 1 around it, like so:

$cool_prompt_on_multiple_lines = (
chimpanzee,
wearing a necktie,
dancing,
:1)

Functions

You can also define functions. For example:

$f($a, $b) = Hello M. $a, I am $b.

$f(Frank, Dan)
$f(Dan, Frank)

The above example is equivalent to:

Hello M. Frank, I am Dan.
Hello M. Dan, I am Frank.

Weight variables

Weight variables are just normal variables but you can also put them in places where weights are expected. For example:

$tree_weight = 1.3

a gigantic sparkling (christmas tree:$tree_weight),
in the middle of times squares,
golden hour, busy hour,
(christmas tree balls:$tree_weight),
massive crowd of pedestrians

Step index variables

Step index variables are just normal variables but you can also put them in places where step indices are expected. For example:

$begin = 7
$end = 13

a supersonic [rocket:starship: $begin, $end] flying in the night sky,
leaving behind [:a: $begin, $end] supersonic [boost fire:gas trail: $begin, $end]
Clone this wiki locally