-
Notifications
You must be signed in to change notification settings - Fork 50
Support jinja templates #1156
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
base: main
Are you sure you want to change the base?
Support jinja templates #1156
Conversation
Run prompts in the sandbox environment, depabtable but seems recommended for untrusted templates
| "GitPython", | ||
| "requests", | ||
| "chevron", | ||
| "jinja2>=3.1.6", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jinja appeared to have some bad vulnerabilities prior to 3.1.5 so I chose 3.1.6 as min version.
|
|
||
| def render_templated_object(obj: Any, args: Any) -> Any: | ||
|
|
||
| class _JinjaSafeDict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran into jinja accessing . as function methods during evaluation (ie. TypeError: 'builtin_function_or_method' object is not iterable). This would prevent that by wrapping the dictionary values. Some users may find this and the sandbox environment to be restrictive but start with safety.
|
@cpinn is this one still needed? |
|
| template_format: TemplateFormat | None = None | ||
|
|
||
| @classmethod | ||
| def from_dict_deep(cls, d: dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome input here.
I want the api to accept nunjucks but I want users of the sdk to interact with jinja.
Run prompts in the sandbox environment, depabtable but seems recommended for untrusted templates