From 5c8ff7e1b3f501364ce4cb5b262efdf4f0c64433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Louf?= Date: Tue, 25 Feb 2025 12:28:13 +0100 Subject: [PATCH] s/from_str/from_string --- outlines/templates.py | 8 ++++---- tests/test_templates.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/outlines/templates.py b/outlines/templates.py index a1fbc1932..16588e813 100644 --- a/outlines/templates.py +++ b/outlines/templates.py @@ -41,7 +41,7 @@ def __call__(self, *args, **kwargs) -> str: return self.template.render(**kwargs) @classmethod - def from_str(cls, content: str, filters: Dict[str, Callable] = {}): + def from_string(cls, content: str, filters: Dict[str, Callable] = {}): """Create a `Template` instance from a string containing a Jinja template. Parameters @@ -53,7 +53,7 @@ def from_str(cls, content: str, filters: Dict[str, Callable] = {}): ------- An instance of the class with the provided content as a template. """ - return cls(build_template_from_str(content, filters), None) + return cls(build_template_from_string(content, filters), None) @classmethod def from_file(cls, path: Path, filters: Dict[str, Callable] = {}): @@ -77,7 +77,7 @@ def from_file(cls, path: Path, filters: Dict[str, Callable] = {}): return cls(build_template_from_file(path, filters), None) -def build_template_from_str( +def build_template_from_string( content: str, filters: Dict[str, Callable] = {} ) -> jinja2.Template: # Dedent, and remove extra linebreak @@ -187,7 +187,7 @@ def prompt( if docstring is None: raise TypeError("Could not find a template in the function's docstring.") - template = build_template_from_str(cast(str, docstring), filters) + template = build_template_from_string(cast(str, docstring), filters) return Template(template, signature) diff --git a/tests/test_templates.py b/tests/test_templates.py index 06727eab1..aa9939278 100644 --- a/tests/test_templates.py +++ b/tests/test_templates.py @@ -6,11 +6,11 @@ from pydantic import BaseModel, Field import outlines -from outlines.templates import Template, build_template_from_str +from outlines.templates import Template, build_template_from_string def render(content: str, **kwargs): - template = build_template_from_str(content) + template = build_template_from_string(content) return template.render(kwargs) @@ -417,7 +417,7 @@ def test_prompt_from_str(): content = """ Hello, {{ name }}! """ - prompt = Template.from_str(content) + prompt = Template.from_string(content) assert prompt.signature is None assert prompt(name="World") == "Hello, World!" @@ -428,5 +428,5 @@ def test_template_from_str_with_extra_linebreaks(): """ - template = build_template_from_str(content) + template = build_template_from_string(content) assert template.render(name="World") == "Hello, World!\n"