Skip to content

Commit d4cb624

Browse files
lesebkaushik-himself
authored andcommitted
test: encode image data as base64 (llamastack#1003)
# What does this PR do? Previously, the test was failing due to a pydantic validation error caused by passing raw binary image data instead of a valid Unicode string. This fix encodes the image data as base64, ensuring it is a valid string format compatible with `ImageContentItem`. Error: ``` ______________ ERROR collecting llama_stack/providers/tests/inference/test_vision_inference.py _______________ llama_stack/providers/tests/inference/test_vision_inference.py:31: in <module> class TestVisionModelInference: llama_stack/providers/tests/inference/test_vision_inference.py:37: in TestVisionModelInference ImageContentItem(image=dict(data=PASTA_IMAGE)), E pydantic_core._pydantic_core.ValidationError: 1 validation error for ImageContentItem E image.data E Input should be a valid string, unable to parse raw data as a unicode string [type=string_unicode, input_value=b'\xff\xd8\xff\xe0\x00\x1...0\xe6\x9f5\xb5?\xff\xd9', input_type=bytes] E For further information visit https://errors.pydantic.dev/2.10/v/string_unicode ``` Signed-off-by: Sébastien Han <[email protected]> [//]: # (If resolving an issue, uncomment and update the line below) [//]: # (Closes #[issue-number]) ## Test Plan Execute the following: ``` ollama run llama3.2-vision --keepalive 2m & uv run pytest -v -s -k "ollama" --inference-model=llama3.2-vision:latest llama_stack/providers/tests/inference/test_vision_inference.py llama_stack/providers/tests/inference/test_vision_inference.py::TestVisionModelInference::test_vision_chat_completion_non_streaming[-ollama-image0-expected_strings0] PASSED llama_stack/providers/tests/inference/test_vision_inference.py::TestVisionModelInference::test_vision_chat_completion_non_streaming[-ollama-image1-expected_strings1] FAILED llama_stack/providers/tests/inference/test_vision_inference.py::TestVisionModelInference::test_vision_chat_completion_streaming[-ollama] FAILED ``` The last two tests are failing because Cloudflare blocked me from accessing https://www.healthypawspetinsurance.com/Images/V3/DogAndPuppyInsurance/Dog_CTA_Desktop_HeroImage.jpg but this has no impact on the current fix. [//]: # (## Documentation) [//]: # (- [ ] Added a Changelog entry if the change is significant) Signed-off-by: Sébastien Han <[email protected]>
1 parent ca80e7a commit d4cb624

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

llama_stack/providers/tests/inference/test_vision_inference.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
# This source code is licensed under the terms described in the LICENSE file in
55
# the root directory of this source tree.
66

7+
import base64
78
from pathlib import Path
89

910
import pytest
1011

11-
from llama_stack.apis.common.content_types import ImageContentItem, TextContentItem, URL
12-
12+
from llama_stack.apis.common.content_types import URL, ImageContentItem, TextContentItem
1313
from llama_stack.apis.inference import (
1414
ChatCompletionResponse,
1515
ChatCompletionResponseEventType,
@@ -23,7 +23,7 @@
2323
THIS_DIR = Path(__file__).parent
2424

2525
with open(THIS_DIR / "pasta.jpeg", "rb") as f:
26-
PASTA_IMAGE = f.read()
26+
PASTA_IMAGE = base64.b64encode(f.read()).decode("utf-8")
2727

2828

2929
class TestVisionModelInference:

0 commit comments

Comments
 (0)