-
-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prompt self-templating #90
Comments
Makes total sense to have it. This feature would make a nice addtion to |
With: smtp_user: "[[smtp_user]]@example.com" I get the following prompt: smtp_user? Format: yaml
🎤 [[[smtp_user]]@example.com]: @yajo So, this is already implemented and we can close this issue now? |
No, this is missing still. I noticed the description was misleading so I updated the example. It makes sense now 🤣 |
I moved this to next milestone, v3 seems ready to go for me. |
I'd like to work on this, could you give me hints? I guess the default = answers_data.get(question, details.get("default"))
tmpl = env.from_string(default) # how do I get 'env'?
default = tmpl.render(**results)
answer = default Question is: how do I get access to the Jinja env from within this function? |
I bet you'd have to create a new env for each loop, because the values would differ as the user keeps answering. In any case, you have to at least create a new temporary env, because the normal env is not created until we have all answers in place, and at this point we still don't have them. Also you shouldn't just render One thing you have to think is that there could be templating errors if one answer is not yet given while asking the previous one. You can take a look at #161 also, which depends on this one and shouldn't be very hard to implement once this is fixed. 🤔 This is trickier than it seems, but your help will be very appreciated! 😊 🙌 |
I don't think so. You don't need a new env when the context changes. The env just contains the filters, some configuration, and templates loader (and in this case templates are strings). At each iteration, new values are added to
OK!
Makes sense, I will try 🙂
I guess it's the user responsibility to write their |
I agree.
That'd be nice. Gotta see if Jinja allows that. Otherwise, an exception would be acceptable for what you said before. |
Oh silly me. In strict mode, if the string cannot be rendered (due to variables not being defined or else), it will trigger an exception. That's how we'll know. For some reason when writing this I was thinking that, if the string couldn't be rendered, it would be returned as-is, but it's not true. Instead it would be returned empty (or partially empty), and that would be hard to detect. Strict mode it is! And catch the exception to abort and print a readable warning? |
Just reraise it as |
We need to go from:
To:
The text was updated successfully, but these errors were encountered: