Repository navigation
fix(client): preserve empty message content when copying messages - #791
Open
davrens101 wants to merge 2 commits into
Open
davrens101 wants to merge 2 commits into
davrens101 wants to merge 2 commits into
Conversation
_copy_messages dropped every falsy field (if v), so a message with
empty content was sent with content unset. Only unset None values
should be omitted; serialization already drops None via exclude_none.
Reproduced: chat messages built from [{'role': 'user', 'content': ''}]
previously lost the content field; it is now preserved.
Adds a regression test in tests/test_utils.py.
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.
Bug
_copy_messages()dropped every falsy field (if v), so a chat messagebuilt with empty
content(e.g.[{'role': 'user', 'content': ''}]) wassent with
contentunset (None). Only unsetNonevalues should beomitted — downstream serialization already drops
Noneviamodel_dump(exclude_none=True).Reproduction (CPU, no server)
Before:
content=None,fields_set={'role'}(empty content lost)After:
content='',fields_set={'content', 'role'}Fix
ollama/_client.py: changeif vtoif v is not Nonein_copy_messagesso falsy-but-set values (empty
content, etc.) are preserved while unsetNonevalues are still dropped.Validation
tests/test_utils.py::test_copy_messages_preserves_empty_contentpytest tests/test_utils.py-> 11 passedtests/test_type_serialization.pyare pre-existing andunrelated (Windows tempfile locking / image path handling,
Tests fail on Windows due to NamedTemporaryFile locking behavior #676)
Before / After
content=''messagecontent=None(lost)content=''(preserved)AI-assisted contribution. Reproduced on unmodified code, then fixed.