From a343614ff2c1d021745b52ae990fc7ab8894c5d6 Mon Sep 17 00:00:00 2001 From: yurekami Date: Mon, 29 Dec 2025 05:29:10 +0900 Subject: [PATCH] fix: make model_info field optional in ShowResponse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `model_info` field in ShowResponse was defined with `Field(alias='model_info')` without a default value, making it required even though the type is `Optional`. This caused a ValidationError when the `/api/show` endpoint omits the `model_info` field, which happens with certain cloud models like: - glm-4.7:cloud - qwen3-next:80b-cloud - deepseek-v3.2:cloud The fix adds `default=None` to the Field definition, making the field truly optional (can be absent from input data) and defaulting to `None`. Fixes #607 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- ollama/_types.py | 2 +- tests/test_type_serialization.py | 58 +++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/ollama/_types.py b/ollama/_types.py index 8931ceac..709a40e4 100644 --- a/ollama/_types.py +++ b/ollama/_types.py @@ -551,7 +551,7 @@ class ShowResponse(SubscriptableBaseModel): details: Optional[ModelDetails] = None - modelinfo: Optional[Mapping[str, Any]] = Field(alias='model_info') + modelinfo: Optional[Mapping[str, Any]] = Field(default=None, alias='model_info') parameters: Optional[str] = None diff --git a/tests/test_type_serialization.py b/tests/test_type_serialization.py index f458cd23..3d9747c0 100644 --- a/tests/test_type_serialization.py +++ b/tests/test_type_serialization.py @@ -4,7 +4,7 @@ import pytest -from ollama._types import CreateRequest, Image +from ollama._types import CreateRequest, Image, ShowResponse def test_image_serialization_bytes(): @@ -92,3 +92,59 @@ def test_create_request_serialization_license_list(): request = CreateRequest(model='test-model', license=['MIT', 'Apache-2.0']) serialized = request.model_dump() assert serialized['license'] == ['MIT', 'Apache-2.0'] + + +def test_show_response_without_model_info(): + """ + Test that ShowResponse can be created without model_info field. + + This is a regression test for issue #607 where certain cloud models + (e.g., glm-4.7:cloud, qwen3-next:80b-cloud, deepseek-v3.2:cloud) return + responses without the model_info field, causing a ValidationError. + """ + # Response data without model_info field (as returned by some cloud models) + response_data = { + 'modelfile': '# Modelfile generated by "ollama show"', + 'template': '{{ .Prompt }}', + 'details': { + 'parent_model': '', + 'format': 'gguf', + 'family': 'glm', + 'families': ['glm'], + 'parameter_size': '9.4B', + 'quantization_level': 'Q4_K_M', + }, + 'capabilities': ['completion'], + 'modified_at': '2025-01-01T00:00:00Z', + } + + # This should not raise a ValidationError + response = ShowResponse.model_validate(response_data) + + assert response.modelfile == '# Modelfile generated by "ollama show"' + assert response.template == '{{ .Prompt }}' + assert response.modelinfo is None # model_info was not provided + assert response.capabilities == ['completion'] + + +def test_show_response_with_model_info(): + """ + Test that ShowResponse still works correctly when model_info is provided. + """ + response_data = { + 'modelfile': '# Modelfile', + 'template': '{{ .Prompt }}', + 'model_info': { + 'general.architecture': 'llama', + 'general.parameter_count': 7000000000, + }, + 'capabilities': ['completion'], + 'modified_at': '2025-01-01T00:00:00Z', + } + + response = ShowResponse.model_validate(response_data) + + assert response.modelfile == '# Modelfile' + assert response.modelinfo is not None + assert response.modelinfo['general.architecture'] == 'llama' + assert response.modelinfo['general.parameter_count'] == 7000000000