Skip to content

Commit

Permalink
Inline mustache dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
nfcampos committed Apr 5, 2024
1 parent 7a3a1c3 commit 916dd61
Show file tree
Hide file tree
Showing 8 changed files with 635 additions and 88 deletions.
17 changes: 3 additions & 14 deletions libs/community/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions libs/core/langchain_core/prompts/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from string import Formatter
from typing import Any, Callable, Dict, List, Set, Tuple, Type

import chevron

import langchain_core.utils.mustache as mustache
from langchain_core.prompt_values import PromptValue, StringPromptValue
from langchain_core.prompts.base import BasePromptTemplate
from langchain_core.pydantic_v1 import BaseModel, create_model
Expand Down Expand Up @@ -90,7 +89,7 @@ def _get_jinja2_variables_from_template(template: str) -> Set[str]:

def mustache_formatter(template: str, **kwargs: Any) -> str:
"""Format a template using mustache."""
return chevron.render(template, kwargs, partials_path=None)
return mustache.render(template, kwargs)


def mustache_template_vars(
Expand All @@ -99,7 +98,7 @@ def mustache_template_vars(
"""Get the variables from a mustache template."""
vars: Set[str] = set()
in_section = False
for type, key in chevron.tokenizer.tokenize(template):
for type, key in mustache.tokenize(template):
if type == "end":
in_section = False
elif in_section:
Expand All @@ -120,7 +119,7 @@ def mustache_schema(
"""Get the variables from a mustache template."""
fields = set()
prefix: Tuple[str, ...] = ()
for type, key in chevron.tokenizer.tokenize(template):
for type, key in mustache.tokenize(template):
if key == ".":
continue
if type == "end":
Expand Down

0 comments on commit 916dd61

Please sign in to comment.