From df0e2e73ee0dc639193a8916df9a19075c70a40e Mon Sep 17 00:00:00 2001 From: JiangNan <1394485448@qq.com> Date: Sun, 8 Mar 2026 22:09:49 +0800 Subject: [PATCH] fix: preserve falsy values like empty strings in _copy_messages The _copy_messages helper uses `if v` to filter out dictionary entries, but this incorrectly drops legitimate falsy values such as empty strings (`content: ""`), zero (`0`), and `False`. For example, a message with `content: ""` would silently lose the content field entirely, which can cause unexpected behavior downstream when the message structure no longer matches what was originally provided. Change the filter condition from `if v` to `if v is not None` so that only actual None values are excluded, preserving all other falsy values. Signed-off-by: JiangNan <1394485448@qq.com> --- ollama/_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ollama/_client.py b/ollama/_client.py index 18cb0fb4..b499d1cf 100644 --- a/ollama/_client.py +++ b/ollama/_client.py @@ -1321,7 +1321,7 @@ def _copy_images(images: Optional[Sequence[Union[Image, Any]]]) -> Iterator[Imag def _copy_messages(messages: Optional[Sequence[Union[Mapping[str, Any], Message]]]) -> Iterator[Message]: for message in messages or []: yield Message.model_validate( - {k: list(_copy_images(v)) if k == 'images' else v for k, v in dict(message).items() if v}, + {k: list(_copy_images(v)) if k == 'images' else v for k, v in dict(message).items() if v is not None}, )