Repository navigation
Conversation
Follow up on huggingface#51069 by teaching `_schema_types` to resolve local JSON Pointer `$ref` targets (`#/$defs/...`, `#/definitions/...`), traverse `allOf` branches, and infer literal types from `const` and `enum`, passing each tool's root `parameters` schema from `ResponseParser` for `$ref` lookup.
Member
|
Hmm, not sure about this one; I'm not sure we actually want to support the whole range of JSON schema, considering that I'm unaware of any chat templates that can parse them. So this seems like a lot of code complexity with no clear purpose |
Contributor
Author
|
Fair point — |
Member
|
Yes, I think we can close this for now! |
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.
What does this PR do?
Follow-up to #51069:
_schema_typesinsrc/transformers/utils/chat_parsing/response_parser.pypreviously only checkedtype,anyOf,oneOf, andnullable, returning()for properties defined via local$ref(#/$defs/...,#/definitions/...),allOf,const, orenum.As a result:
xml-inline,kv-lines) skipped coercion for parameters declared with$ref,allOf,const, orenumwhentools=was passed.json,python-call-list) could not see"string"inside string-valued$ref/allOf/const/enumschemas.Changes
_resolve_local_ref(ref, root)with RFC 6901 pointer unescaping (~1->/,~0->~) and cycle protection via_seen._json_value_type(value)(checkingboolbeforeint) forconstandenumschemas._schema_types(schema, root=...)to traverse$ref,allOf(narrowing compatible branches such as["number"]+["integer"]->("integer",)and falling back cleanly when branches are disjoint),const, andenum, preserving insertion order without duplicates.self._tool_roots[name] = parametersinResponseParser.__init__and passrootfrom_coerce_tool_calls.ToolArgCoercionTest.test_schema_types_and_coerce_handle_ref_allof_const_enumcovering nested/escaped/cyclic$ref,allOf,const(bool/int/str),enum, untyped coercion, and typed-parser string preservation.Verification
tests/utils/test_chat_parsing.py(ToolArgCoercionTest: 25 non-AutoTokenizertests passing;test_chat_parsing.py: 83 passed, 12 skipped, only pre-existing missingfixtures/chat_parsing/python_call_list.jsonin sparse checkout) andtests/utils/test_chat_template_utils.py(46 passed, 11 subtests passed).ruff checkandruff format --checkclean on both modified files.Disclosure: Assisted by AI tooling during root-cause analysis and test/patch drafting; all code and tests were verified locally.