mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-09 04:50:37 +00:00
parent
90ef705ced
commit
8e386613ac
@ -18,7 +18,7 @@ def jinja2_formatter(template: str, **kwargs: Any) -> str:
|
|||||||
try:
|
try:
|
||||||
from jinja2 import Template
|
from jinja2 import Template
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ValueError(
|
raise ImportError(
|
||||||
"jinja2 not installed, which is needed to use the jinja2_formatter. "
|
"jinja2 not installed, which is needed to use the jinja2_formatter. "
|
||||||
"Please install it with `pip install jinja2`."
|
"Please install it with `pip install jinja2`."
|
||||||
)
|
)
|
||||||
|
@ -5,7 +5,6 @@ from pathlib import Path
|
|||||||
from string import Formatter
|
from string import Formatter
|
||||||
from typing import Any, Dict, List, Set, Union
|
from typing import Any, Dict, List, Set, Union
|
||||||
|
|
||||||
from jinja2 import Environment, meta
|
|
||||||
from pydantic import Extra, root_validator
|
from pydantic import Extra, root_validator
|
||||||
|
|
||||||
from langchain.prompts.base import (
|
from langchain.prompts.base import (
|
||||||
@ -16,6 +15,13 @@ from langchain.prompts.base import (
|
|||||||
|
|
||||||
|
|
||||||
def _get_jinja2_variables_from_template(template: str) -> Set[str]:
|
def _get_jinja2_variables_from_template(template: str) -> Set[str]:
|
||||||
|
try:
|
||||||
|
from jinja2 import Environment, meta
|
||||||
|
except ImportError:
|
||||||
|
raise ImportError(
|
||||||
|
"jinja2 not installed, which is needed to use the jinja2_formatter. "
|
||||||
|
"Please install it with `pip install jinja2`."
|
||||||
|
)
|
||||||
env = Environment()
|
env = Environment()
|
||||||
ast = env.parse(template)
|
ast = env.parse(template)
|
||||||
variables = meta.find_undeclared_variables(ast)
|
variables = meta.find_undeclared_variables(ast)
|
||||||
|
Loading…
Reference in New Issue
Block a user