Skip to content

Commit

Permalink
s/from_str/from_string
Browse files Browse the repository at this point in the history
  • Loading branch information
rlouf committed Feb 26, 2025
1 parent eced2ce commit 5c8ff7e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions outlines/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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] = {}):
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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!"

Expand All @@ -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"

0 comments on commit 5c8ff7e

Please sign in to comment.