Skip to content
Discussion options

You must be logged in to vote

That's a nice idea - unfortunately the standard syntax doesn't support it because the string is only parsed once. The${car} token becomes a literal and the prompt generator sees __cars/${car}/types__ without the variable being resolved. You can use jinja2 templates to make it work. It's a little clunky but gets the job done:


# first choose the car
{% set car = choice("ford", "porsche", "john_deere" ) %}

# now create strings for the wildcards, e.g. __cards/ford/__types__
{% set car_types = '__cars/' ~ car ~ '/types__' %}
{% set car_names = '__cars/' ~ car ~ '/name__' %}
{% set car_colors = '__cars/' ~ car ~ '/colors__' %}

# finally, create the final prompt
a {{ random_sample(car_types) …

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@adieyal
Comment options

@anothertal3
Comment options

@anothertal3
Comment options

Answer selected by anothertal3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants