Replies: 1 comment
-
Hey! I'm willing to contribute with code for this idea (in particular supporting providing a custom Environment). This will not only allow users to load templates but also use custom filters and other advanced features. I'm looking for a guideline from a langchain maintainer on how to approach the change. A couple of ideas that come to my mind are:
I'm not thrilled about either, hence the advise request. In the meantime a solution is to monkeypatch langchain to inject the correct environment in the "jinja2_formatter" function. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Checked
Feature request
Allow specifying a
loader
when initializing the Jinja2SandboxEnvironment
to permit loading templates. See https://jinja.palletsprojects.com/en/2.10.x/api/#loadersMotivation
If you have different prompts that share common elements, currently it isn't possible to take advantage of jinja2's
include
(https://jinja.palletsprojects.com/en/3.0.x/templates/#include), because there's no way to reference existing templates using thejinja2
formatter for Prompts. This is due to no loader is specified when initializing theSandboxEnvironment
(here https://github.com/langchain-ai/langchain/blob/ff0df5e/libs/core/langchain_core/prompts/string.py#L59).Proposal (If applicable)
Allow specifying a
loader
when initializing the jinja2 environment. Alternatively, it could be more flexible to allow the caller to supply their own jinja2Environment
object, so they can override other initialization parameters (likevariable_start_string
,variable_end_string
, etc).Beta Was this translation helpful? Give feedback.
All reactions