diff --git a/llama_stack/providers/remote/inference/vllm/vllm.py b/llama_stack/providers/remote/inference/vllm/vllm.py index 317d05207..81c746cce 100644 --- a/llama_stack/providers/remote/inference/vllm/vllm.py +++ b/llama_stack/providers/remote/inference/vllm/vllm.py @@ -176,10 +176,8 @@ class VLLMInferenceAdapter(Inference, ModelsProtocolPrivate): media_present = request_has_media(request) if isinstance(request, ChatCompletionRequest): if media_present: - # vllm does not seem to work well with image urls, so we download the images input_dict["messages"] = [ - await convert_message_to_openai_dict(m, download=True) - for m in request.messages + await convert_message_to_openai_dict(m) for m in request.messages ] else: input_dict["prompt"] = await chat_completion_request_to_prompt( diff --git a/tests/client-sdk/inference/dog.png b/tests/client-sdk/inference/dog.png new file mode 100644 index 000000000..2d502e606 Binary files /dev/null and b/tests/client-sdk/inference/dog.png differ diff --git a/tests/client-sdk/inference/test_inference.py b/tests/client-sdk/inference/test_inference.py index 19314e4ab..ac2c4ce38 100644 --- a/tests/client-sdk/inference/test_inference.py +++ b/tests/client-sdk/inference/test_inference.py @@ -4,6 +4,9 @@ # This source code is licensed under the terms described in the LICENSE file in # the root directory of this source tree. +import base64 +import os + import pytest from pydantic import BaseModel @@ -69,6 +72,16 @@ def get_weather_tool_definition(): } +@pytest.fixture +def base64_image_url(): + image_path = os.path.join(os.path.dirname(__file__), "dog.png") + with open(image_path, "rb") as image_file: + # Convert the image to base64 + base64_string = base64.b64encode(image_file.read()).decode("utf-8") + base64_url = f"data:image;base64,{base64_string}" + return base64_url + + def test_completion_non_streaming(llama_stack_client, text_model_id): response = llama_stack_client.inference.completion( content="Complete the sentence using one word: Roses are red, violets are ", @@ -356,3 +369,31 @@ def test_image_chat_completion_streaming(llama_stack_client, vision_model_id): streamed_content += chunk.event.delta.text.lower() assert len(streamed_content) > 0 assert any(expected in streamed_content for expected in {"dog", "puppy", "pup"}) + + +def test_image_chat_completion_base64_url( + llama_stack_client, vision_model_id, base64_image_url +): + + message = { + "role": "user", + "content": [ + { + "type": "image", + "url": { + "uri": base64_image_url, + }, + }, + { + "type": "text", + "text": "Describe what is in this image.", + }, + ], + } + response = llama_stack_client.inference.chat_completion( + model_id=vision_model_id, + messages=[message], + stream=False, + ) + message_content = response.completion_message.content.lower().strip() + assert len(message_content) > 0