https://www.boundaryml.com logo
make sep a filter
# general
b
Copy code
jinja
template_string Sep(n: int) #"
  {%- set s = n ~ '' -%}
  {%- if s[0] == '-' -%}
    {%- set sign = '-' -%}
    {%- set s = s[1:] -%}
  {%- else -%}
    {%- set sign = '' -%}
  {%- endif -%}
  {%- set l = s|length -%}
  {{- sign -}}
  {%- for ch in s -%}
    {%- if loop.index0 != 0 and ((l - loop.index0) % 3) == 0 -%},{%- endif -%}
    {{- ch -}}
  {%- endfor -%}
"#
Please make
|sep
a filter so I can delete this from my codebase 🙏
b
oh man 😂 i think we might support something like
{{ n|format(“:,”) }}
? am on my phone right now so can’t test on promptfiddle
if not, we may just need to bump or twiddle our jinja implementation to make this work, since a PR for this landed in upstream in nov: https://github.com/mitsuhiko/minijinja/issues/427
you’re welcome to take a stab at it, but otherwise we can take a look at this in the next few weeks!
FYI: when 0.220.0 goes out, you'll be able to do
{{ "{:,}".format(1234) }}
to get
1,234
https://github.com/BoundaryML/baml/pull/3149
b
Yo this is awesome
Copy code
jinja
template_string Sep(n: int) #"
  {{- "{:,}".format(n) -}}
"#
The linter throws warnings: '{:,}' is a literal["{:,}"], expected class '{:,}.format' is undefined, expected function
@baml-sam pls make my baml_src not be yellow anymore 🥹
2 Views