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