fix: ShowResponse raises ValidationError when model_info is omitted#644
Closed
CyberRaccoonTeam wants to merge 1 commit intoollama:mainfrom
Closed
fix: ShowResponse raises ValidationError when model_info is omitted#644CyberRaccoonTeam wants to merge 1 commit intoollama:mainfrom
CyberRaccoonTeam wants to merge 1 commit intoollama:mainfrom
Conversation
…bility Pydantic requires explicit default=None for Optional fields with aliases. Without it, ShowResponse raises ValidationError when /api/show omits model_info, which happens with some cloud models. Fixes #607
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
Fixes #607
ShowResponseraises aPydantic ValidationErrorwhen the/api/showendpoint omitsmodel_infofrom its response. This happens with some cloud models and breaks downstream tools likellm-ollama.Root Cause
modelinfousesField(alias='model_info')withOptional[Mapping]type, but Pydantic requires an explicitdefault=Nonefor aliased Optional fields. Without it, the field is treated as required even though the type hint suggests otherwise.Changes
ollama/_types.py: Addedmodel_config = ConfigDict(populate_by_name=True)anddefault=Noneto themodelinfofield onShowResponsetests/test_type_serialization.py: Added 3 tests covering the fix:test_show_response_without_model_info— verifies no error when model_info is absenttest_show_response_with_model_info_alias— verifies the alias still workstest_show_response_with_modelinfo_field_name— verifies the Python field name worksTesting
All existing tests continue to pass.