Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ollama/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def serialize_model(self):
pass

# String might be a file path, but might not exist
if self.value.split('.')[-1] in ('png', 'jpg', 'jpeg', 'webp'):
if self.value.split('.')[-1].lower() in ('png', 'jpg', 'jpeg', 'webp'):
raise ValueError(f'File {self.value} does not exist')

try:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_type_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ def test_image_serialization_string_path():
img.model_dump()


@pytest.mark.parametrize('extension', ['PNG', 'JPG', 'JPEG', 'WEBP'])
def test_image_serialization_string_path_uppercase_extension(extension):
# A non-existent path with an uppercase image extension must be rejected the
# same way its lowercase counterpart is, rather than being treated as base64.
with pytest.raises(ValueError, match='does not exist'):
Image(value=f'some_path/that/does/not/exist.{extension}').model_dump()

# A bare filename with an uppercase extension can be valid base64, so without a
# case-insensitive check it is silently accepted instead of raising.
with pytest.raises(ValueError, match='does not exist'):
Image(value=f'PHOTO.{extension}').model_dump()


def test_create_request_serialization():
request = CreateRequest(model='test-model', from_='base-model', quantize='q4_0', files={'file1': 'content1'}, adapters={'adapter1': 'content1'}, template='test template', license='MIT', system='test system', parameters={'param1': 'value1'})

Expand Down