adieyal / dynamicprompts

Templating language for generating prompts for text to image generators such as Stable Diffusion
MIT License
124 stars 20 forks source link

Added new Jinja helper functions `flip_coin` and `pick_multiple` #134

Open Jaid opened 3 months ago

Jaid commented 3 months ago

I added two new helper functions for Jinja2 templates.

pick_multiple

Returns multiple values from an input list (a resolved wildcard for example). The number of items can be specified, otherwise it’s rolled between 1 and the maximum. If the specified amount is too high, it’s autocorrected instead of throwing an error.

Example

Between 1 and maximum

{% set separator = ' and ' %}
{% set characters = ['ash', 'misty', 'brock', 'professor_oak', 'gary'] %}
a hike with {{ pick_multiple(characters)|join(separator) }} in the mountains

Between 0 and maximum

{% set separator = ' and ' %}
a hike
{% set characters = ['ash', 'misty', 'brock', 'professor_oak', 'gary'] %}
{% set charactersAmount = randint(0, characters|length) %}
{% if charactersAmount > 0 %}
  with {{ pick_multiple(characters, charactersAmount)|join(separator) }}
{% endif %}
in the mountains

flip_coin

If no arguments are given, returns a random boolean. Otherwise randomly picks an argument.

Example

For branches

{% if flip_coin() %}
  1girl,
{% endif %}
laying on grass

For quick inline decisions

a {{ flip_coin('caught', 'fleeing') }} Pikachu