Repository navigation
types: serialize Tool parameters $defs by alias when dumped directly - #789
Open
suhailult777 wants to merge 1 commit into
Open
suhailult777 wants to merge 1 commit into
suhailult777 wants to merge 1 commit into
Conversation
Tool.Function.Parameters stored the JSON Schema `$defs` key under the field name `defs`. Only ChatRequest's serializer renamed it back, so Tool.model_dump() / model_dump_json() emitted `defs` and broke `$ref: '#/$defs/...'` targets. Rename it in a wrap serializer on Parameters itself so every dump path produces `$defs`. Fixes ollama#787
This branch has not been deployed
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.
Fixes #787
Tool.Function.Parametersstores the JSON Schema$defskey in the fielddefs. OnlyChatRequest's serializer renamed it back, so dumping aToolon its own (Tool.model_dump()/model_dump_json()) emitteddefs, and$ref: '#/$defs/...'targets pointed at a missing key.This adds a wrap
model_serializeronParametersthat renamesdefsto$defs, so every dump path emits$defs. It keeps thepydantic>=2.9floor (noserialize_by_alias).tests/test_utils.pypinned the old'defs': Nonekey; they now expect'$defs': None.tests/test_type_serialization.py: direct dump, JSON dump, same output as theChatRequestpath, round trip back intoTool.ChatRequest's rename is now a no-op but is left as-is, to keep this PR focused (ChatRequest.model_dump() crashes when a tool has no parameters or no function #733 touches that code).Tests:
pytest tests118 passed;ruff check/ruff format --checkclean.I used AI assistance and reviewed and tested every line.