fix(custom): escape pipes in r1_searcher_query_extract tag regex#439
Open
Chen17-sq wants to merge 1 commit into
Open
fix(custom): escape pipes in r1_searcher_query_extract tag regex#439Chen17-sq wants to merge 1 commit into
Chen17-sq wants to merge 1 commit into
Conversation
The tag regex used unescaped pipes: re.compile(r"<|begin_of_query|>([^<]*)"). In a regex `|` is alternation, so the pattern matched `<` OR `begin_of_query` OR `>([^<]*)` instead of the literal tag `<|begin_of_query|>`. The extractor therefore returned trailing text after the query rather than the query itself. For "... <|begin_of_query|>capital of France<|end_of_query|> done" get_query() returned "done?" instead of "capital of France?". Escape the pipes so the literal tag is matched, and add the first test suite for the custom server covering this extractor.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bug
r1_searcher_query_extractextracts the wrong text because its tag regex has unescaped pipes:In a regex
|is alternation, so this matches<orbegin_of_queryor>([^<]*)— not the literal<|begin_of_query|>tag the function intends (and that its docstring documents).Reproduction
findallon the buggy pattern returns['', '', 'capital of France', '', ' done'], andget_querytakesmatches[-1]→' done', so the extracted "query" is whatever trails the tag.Fix
Escape the pipes so the literal tag is matched:
The sibling
<search>extractor is unaffected (no pipes).Tests
Adds
tests/servers/custom/test_query_extract.pycovering correct extraction, last-query selection, the?suffix, and the no-tag fallback.pytestis already declared as a dev dependency; these are the first tests in the repo. All 4 pass locally.