-
Notifications
You must be signed in to change notification settings - Fork 23
Support call/endcall blocks
#81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b4e794
Add call/endcall support
yatarkan e00e7b2
Add syntax tests for call blocks
yatarkan b3a2d00
Add call blocks to supported features in readme
yatarkan ecc5770
Add openbmb/MiniCPM3-4B to test models
yatarkan 92238a5
Remove non-existent model
yatarkan 2fe1ab8
Add tests for unterminated call and macro
yatarkan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -429,6 +429,54 @@ TEST(SyntaxTest, SimpleCases) { | |
| {%- endmacro -%} | ||
| {{- foo() }} {{ foo() -}})", {}, {})); | ||
|
|
||
| EXPECT_EQ( | ||
| "x,x", | ||
| render(R"( | ||
| {%- macro test() -%}{{ caller() }},{{ caller() }}{%- endmacro -%} | ||
| {%- call test() -%}x{%- endcall -%} | ||
| )", {}, {})); | ||
|
|
||
| EXPECT_EQ( | ||
| "Outer[Inner(X)]", | ||
| render(R"( | ||
| {%- macro outer() -%}Outer[{{ caller() }}]{%- endmacro -%} | ||
| {%- macro inner() -%}Inner({{ caller() }}){%- endmacro -%} | ||
| {%- call outer() -%}{%- call inner() -%}X{%- endcall -%}{%- endcall -%} | ||
| )", {}, {})); | ||
|
|
||
| EXPECT_EQ( | ||
| "<ul><li>A</li><li>B</li></ul>", | ||
| render(R"( | ||
| {%- macro test(prefix, suffix) -%}{{ prefix }}{{ caller() }}{{ suffix }}{%- endmacro -%} | ||
| {%- set items = ["a", "b"] -%} | ||
| {%- call test("<ul>", "</ul>") -%} | ||
| {%- for item in items -%} | ||
| <li>{{ item | upper }}</li> | ||
| {%- endfor -%} | ||
| {%- endcall -%} | ||
| )", {}, {})); | ||
|
|
||
| EXPECT_EQ( | ||
| "\\n\\nclass A:\\n b: 1\\n c: 2\\n", | ||
| render(R"( | ||
| {%- macro recursive(obj) -%} | ||
| {%- set ns = namespace(content = caller()) -%} | ||
| {%- for key, value in obj.items() %} | ||
| {%- if value is mapping %} | ||
| {%- call recursive(value) -%} | ||
| {{ '\\n\\nclass ' + key.title() + ':\\n' }} | ||
| {%- endcall -%} | ||
| {%- else -%} | ||
| {%- set ns.content = ns.content + ' ' + key + ': ' + value + '\\n' -%} | ||
| {%- endif -%} | ||
| {%- endfor -%} | ||
| {{ ns.content }} | ||
| {%- endmacro -%} | ||
|
|
||
| {%- call recursive({"a": {"b": "1", "c": "2"}}) -%} | ||
| {%- endcall -%} | ||
| )", {}, {})); | ||
|
|
||
| if (!getenv("USE_JINJA2")) { | ||
| EXPECT_EQ( | ||
| "Foo", | ||
|
|
@@ -576,6 +624,8 @@ TEST(SyntaxTest, SimpleCases) { | |
| EXPECT_THAT([]() { render("{% elif 1 %}", {}, {}); }, ThrowsWithSubstr("Unexpected elif")); | ||
| EXPECT_THAT([]() { render("{% endfor %}", {}, {}); }, ThrowsWithSubstr("Unexpected endfor")); | ||
| EXPECT_THAT([]() { render("{% endfilter %}", {}, {}); }, ThrowsWithSubstr("Unexpected endfilter")); | ||
| EXPECT_THAT([]() { render("{% endmacro %}", {}, {}); }, ThrowsWithSubstr("Unexpected endmacro")); | ||
| EXPECT_THAT([]() { render("{% endcall %}", {}, {}); }, ThrowsWithSubstr("Unexpected endcall")); | ||
|
|
||
| EXPECT_THAT([]() { render("{% if 1 %}", {}, {}); }, ThrowsWithSubstr("Unterminated if")); | ||
| EXPECT_THAT([]() { render("{% for x in 1 %}", {}, {}); }, ThrowsWithSubstr("Unterminated for")); | ||
|
|
@@ -584,6 +634,12 @@ TEST(SyntaxTest, SimpleCases) { | |
| EXPECT_THAT([]() { render("{% if 1 %}{% else %}{% elif 1 %}{% endif %}", {}, {}); }, ThrowsWithSubstr("Unterminated if")); | ||
| EXPECT_THAT([]() { render("{% filter trim %}", {}, {}); }, ThrowsWithSubstr("Unterminated filter")); | ||
| EXPECT_THAT([]() { render("{# ", {}, {}); }, ThrowsWithSubstr("Missing end of comment tag")); | ||
| EXPECT_THAT([]() { render("{% macro test() %}", {}, {}); }, ThrowsWithSubstr("Unterminated macro")); | ||
| EXPECT_THAT([]() { render("{% call test %}", {}, {}); }, ThrowsWithSubstr("Unterminated call")); | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please also add an unterminated call test: EXPECT_THAT([]() { render("{%- call test -%}", {}, {}); }, ThrowsWithSubstr("Missing end of call tag"));There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests for call and macro added |
||
| EXPECT_THAT([]() { | ||
| render("{%- macro test() -%}content{%- endmacro -%}{%- call test -%}caller_content{%- endcall -%}", {}, {}); | ||
| }, ThrowsWithSubstr("Invalid call block syntax - expected function call")); | ||
| } | ||
|
|
||
| EXPECT_EQ( | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this removal accidental?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This model is removed from HF
https://huggingface.co/qingy2024/Falcon3-2x10B-MoE-Instruct