Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
lm-evaluation-harness
Commits
8c653b93
Commit
8c653b93
authored
Jun 21, 2023
by
nikuya3
Browse files
Add regex_replace filter for Jinja templates
parent
193b0a47
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
0 deletions
+4
-0
lm_eval/utils.py
lm_eval/utils.py
+4
-0
No files found.
lm_eval/utils.py
View file @
8c653b93
...
...
@@ -398,8 +398,12 @@ def load_yaml_config(yaml_path):
return
final_yaml_config
return
yaml_config
def
regex_replace
(
string
,
pattern
,
repl
,
count
=
0
):
"""Implements the `re.sub` function as a custom Jinja filter."""
return
re
.
sub
(
pattern
,
repl
,
string
,
count
=
count
)
env
=
Environment
(
loader
=
BaseLoader
,
undefined
=
StrictUndefined
)
env
.
filters
[
"regex_replace"
]
=
regex_replace
def
apply_template
(
template
,
doc
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment