Add anything and until DSL terms for reasoning models - #1978
Open
rs-03 wants to merge 1 commit into
Open
Conversation
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.
Summary
Adds the
anythinganduntilDSL constructs requested in #1480, so structured generation can let a model produce free-form text up to a delimiter before switching to a structured schema. This is the common reasoning-model pattern:anythingcorresponds to.*.anything.until(delimiter)matches any text up to, but not including, a literaldelimiter. Sinceoutlines-coredoes not support lookaheads, the negative-lookahead form((?!</think>).)*is expanded into the equivalent alternation, as suggested in the issue:Closes #1480
Design choices worth your input
untilexcludes the delimiter (it stops just before it), matching the expansion above. The issue notes "we could also decide that until keeps the</think>token"; I went with the excluding version, and I am happy to change it if you prefer keeping the token.until_regexis deferred as suggested in the issue.re.escape, so a delimiter containing regex metacharacters is matched literally. As a side effect the generated pattern uses, for example,[^/]where the issue illustration wrote[^\/]; the two are equivalent in Python regex, and usingre.escapekeeps it robust for arbitrary delimiters.Changes
Anythingterm (with anuntilmethod) and theanythingsingleton inoutlines/types/dsl.py, plus ato_regexbranch mappinganythingto.*anythingfromoutlines.typestests/types/test_dsl.pycovering the expanded pattern, matching behaviour (including newlines and delimiter rejection), special-character escaping, the empty-delimiter guard, and the end-to-end reasoning outlineRan locally:
pytest tests/types/test_dsl.py -k anything(5 passed).