Skip to content

Commit

Permalink
fix stopping phrase postprocessing order
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeurerkellner committed Nov 15, 2023
1 parent e94622f commit 139b5e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lmql/ops/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ def postprocess_order(self, other, operands, other_inputs, **kwargs):
return "before" # this operator does not match, so order does not matter
if other_matched_phrase_index == -1:
return "after" # other operator does not match, so order does not matter
if matched_phrase_index < other_matched_phrase_index:
if matched_phrase_index >= other_matched_phrase_index:
return "before"
else:
return "after"
Expand Down
27 changes: 27 additions & 0 deletions src/lmql/tests/test_stopping.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,32 @@ async def test_stop_before_should_not_postprocess_if_sc_not_satisfied():
len(TOKENS(REVIEW)) > 10 and STOPS_BEFORE(REVIEW, "exempted") and STOPS_AT(REVIEW, "vendors")
'''

@lmql.query
async def test_stop_overlapping_before():
'''lmql
argmax
"""{{
"first_name": "Bruno",
"last_name": "Mars",
"birthday": "1985-10-0",
"age": 32,
"hobby": [[
"sing",
"dance"
]],
"address": {{
"street_address": "12345",
"city": "New York",
"state": "NY",
"country":"US"
}},
# the 2 most popular songs
"""
'"songs":[[\n "[GEN_STR]' where STOPS_BEFORE(GEN_STR, ',') and STOPS_BEFORE(GEN_STR, '"') and STOPS_BEFORE(GEN_STR, ']') and len(TOKENS(GEN_STR)) < 10 and GEN_STR == 'abc",'
assert GEN_STR == "abc", "Expected just 'abc', but got {}".format(str([GEN_STR])[1:-1])
from
lmql.model("random", seed=123)
'''

if __name__ == "__main__":
run_all_tests(globals())

0 comments on commit 139b5e6

Please sign in to comment.