File tree Expand file tree Collapse file tree 2 files changed +37
-5
lines changed
tests/integration_tests/chat_models Expand file tree Collapse file tree 2 files changed +37
-5
lines changed Original file line number Diff line number Diff line change 30
30
SystemMessage ,
31
31
ToolCall ,
32
32
ToolMessage ,
33
+ is_data_content_block ,
33
34
)
34
35
from langchain_core .messages .ai import UsageMetadata
35
36
from langchain_core .messages .tool import tool_call
@@ -173,6 +174,20 @@ def _lc_tool_call_to_openai_tool_call(tool_call: ToolCall) -> dict:
173
174
}
174
175
175
176
177
+ def _get_image_from_data_content_block (block : dict ) -> str :
178
+ """Format standard data content block to format expected by Ollama."""
179
+ if block ["type" ] == "image" :
180
+ if block ["source_type" ] == "base64" :
181
+ return block ["data" ]
182
+ else :
183
+ error_message = "Image data only supported through in-line base64 format."
184
+ raise ValueError (error_message )
185
+
186
+ else :
187
+ error_message = f"Blocks of type { block ['type' ]} not supported."
188
+ raise ValueError (error_message )
189
+
190
+
176
191
def _is_pydantic_class (obj : Any ) -> bool :
177
192
return isinstance (obj , type ) and is_basemodel_subclass (obj )
178
193
@@ -553,7 +568,9 @@ def _convert_messages_to_ollama_messages(
553
568
images .append (image_url_components [1 ])
554
569
else :
555
570
images .append (image_url_components [0 ])
556
-
571
+ elif is_data_content_block (content_part ):
572
+ image = _get_image_from_data_content_block (content_part )
573
+ images .append (image )
557
574
else :
558
575
raise ValueError (
559
576
"Unsupported message content type. "
Original file line number Diff line number Diff line change @@ -14,14 +14,29 @@ def chat_model_class(self) -> type[ChatOllama]:
14
14
def chat_model_params (self ) -> dict :
15
15
return {"model" : "llama3.1" }
16
16
17
- @property
18
- def supports_image_inputs (self ) -> bool :
19
- return True
20
-
21
17
@property
22
18
def supports_json_mode (self ) -> bool :
23
19
return True
24
20
25
21
@property
26
22
def has_tool_choice (self ) -> bool :
27
23
return False
24
+
25
+
26
+ def test_image_model () -> None :
27
+ class ImageModelTests (ChatModelIntegrationTests ):
28
+ @property
29
+ def chat_model_class (self ) -> type [ChatOllama ]:
30
+ return ChatOllama
31
+
32
+ @property
33
+ def chat_model_params (self ) -> dict :
34
+ return {"model" : "gemma3:4b" }
35
+
36
+ @property
37
+ def supports_image_inputs (self ) -> bool :
38
+ return True
39
+
40
+ test_instance = ImageModelTests ()
41
+ model = test_instance .chat_model_class (** test_instance .chat_model_params )
42
+ ImageModelTests ().test_image_inputs (model )
You can’t perform that action at this time.
0 commit comments