@@ -63,13 +63,14 @@ def initialize(
6363
6464 # Add a user message to the messages array
6565 #
66- # @param content [String] The content of the message
6766 # @param role [String] The role attribute of the message. Default: "user"
67+ # @param content [String] The content of the message
68+ # @param image_url [String] The URL of the image to include in the message
6869 # @param tool_calls [Array<Hash>] The tool calls to include in the message
6970 # @param tool_call_id [String] The ID of the tool call to include in the message
7071 # @return [Array<Langchain::Message>] The messages
71- def add_message ( content : nil , role : "user" , tool_calls : [ ] , tool_call_id : nil )
72- message = build_message ( role : role , content : content , tool_calls : tool_calls , tool_call_id : tool_call_id )
72+ def add_message ( role : "user" , content : nil , image_url : nil , tool_calls : [ ] , tool_call_id : nil )
73+ message = build_message ( role : role , content : content , image_url : image_url , tool_calls : tool_calls , tool_call_id : tool_call_id )
7374
7475 # Call the callback with the message
7576 add_message_callback . call ( message ) if add_message_callback # rubocop:disable Style/SafeNavigation
@@ -145,17 +146,17 @@ def run!
145146 # @param content [String] The content of the message
146147 # @param auto_tool_execution [Boolean] Whether or not to automatically run tools
147148 # @return [Array<Langchain::Message>] The messages
148- def add_message_and_run ( content :, auto_tool_execution : false )
149- add_message ( content : content , role : "user" )
149+ def add_message_and_run ( content : nil , image_url : nil , auto_tool_execution : false )
150+ add_message ( content : content , image_url : image_url , role : "user" )
150151 run ( auto_tool_execution : auto_tool_execution )
151152 end
152153
153154 # Add a user message and run the assistant with automatic tool execution
154155 #
155156 # @param content [String] The content of the message
156157 # @return [Array<Langchain::Message>] The messages
157- def add_message_and_run! ( content :)
158- add_message_and_run ( content : content , auto_tool_execution : true )
158+ def add_message_and_run! ( content : nil , image_url : nil )
159+ add_message_and_run ( content : content , image_url : image_url , auto_tool_execution : true )
159160 end
160161
161162 # Submit tool output
@@ -388,11 +389,12 @@ def run_tools(tool_calls)
388389 #
389390 # @param role [String] The role of the message
390391 # @param content [String] The content of the message
392+ # @param image_url [String] The URL of the image to include in the message
391393 # @param tool_calls [Array<Hash>] The tool calls to include in the message
392394 # @param tool_call_id [String] The ID of the tool call to include in the message
393395 # @return [Langchain::Message] The Message object
394- def build_message ( role :, content : nil , tool_calls : [ ] , tool_call_id : nil )
395- @llm_adapter . build_message ( role : role , content : content , tool_calls : tool_calls , tool_call_id : tool_call_id )
396+ def build_message ( role :, content : nil , image_url : nil , tool_calls : [ ] , tool_call_id : nil )
397+ @llm_adapter . build_message ( role : role , content : content , image_url : image_url , tool_calls : tool_calls , tool_call_id : tool_call_id )
396398 end
397399
398400 # Increment the tokens count based on the last interaction with the LLM
@@ -443,7 +445,7 @@ def extract_tool_call_args(tool_call:)
443445 raise NotImplementedError , "Subclasses must implement extract_tool_call_args"
444446 end
445447
446- def build_message ( role :, content : nil , tool_calls : [ ] , tool_call_id : nil )
448+ def build_message ( role :, content : nil , image_url : nil , tool_calls : [ ] , tool_call_id : nil )
447449 raise NotImplementedError , "Subclasses must implement build_message"
448450 end
449451 end
@@ -457,7 +459,9 @@ def build_chat_params(tools:, instructions:, messages:, tool_choice:)
457459 params
458460 end
459461
460- def build_message ( role :, content : nil , tool_calls : [ ] , tool_call_id : nil )
462+ def build_message ( role :, content : nil , image_url : nil , tool_calls : [ ] , tool_call_id : nil )
463+ warn "Image URL is not supported by Ollama currently" if image_url
464+
461465 Langchain ::Messages ::OllamaMessage . new ( role : role , content : content , tool_calls : tool_calls , tool_call_id : tool_call_id )
462466 end
463467
@@ -506,8 +510,8 @@ def build_chat_params(tools:, instructions:, messages:, tool_choice:)
506510 params
507511 end
508512
509- def build_message ( role :, content : nil , tool_calls : [ ] , tool_call_id : nil )
510- Langchain ::Messages ::OpenAIMessage . new ( role : role , content : content , tool_calls : tool_calls , tool_call_id : tool_call_id )
513+ def build_message ( role :, content : nil , image_url : nil , tool_calls : [ ] , tool_call_id : nil )
514+ Langchain ::Messages ::OpenAIMessage . new ( role : role , content : content , image_url : image_url , tool_calls : tool_calls , tool_call_id : tool_call_id )
511515 end
512516
513517 # Extract the tool call information from the OpenAI tool call hash
@@ -564,7 +568,9 @@ def build_chat_params(tools:, instructions:, messages:, tool_choice:)
564568 params
565569 end
566570
567- def build_message ( role :, content : nil , tool_calls : [ ] , tool_call_id : nil )
571+ def build_message ( role :, content : nil , image_url : nil , tool_calls : [ ] , tool_call_id : nil )
572+ warn "Image URL is not supported by MistralAI currently" if image_url
573+
568574 Langchain ::Messages ::MistralAIMessage . new ( role : role , content : content , tool_calls : tool_calls , tool_call_id : tool_call_id )
569575 end
570576
@@ -623,7 +629,9 @@ def build_chat_params(tools:, instructions:, messages:, tool_choice:)
623629 params
624630 end
625631
626- def build_message ( role :, content : nil , tool_calls : [ ] , tool_call_id : nil )
632+ def build_message ( role :, content : nil , image_url : nil , tool_calls : [ ] , tool_call_id : nil )
633+ warn "Image URL is not supported by Google Gemini" if image_url
634+
627635 Langchain ::Messages ::GoogleGeminiMessage . new ( role : role , content : content , tool_calls : tool_calls , tool_call_id : tool_call_id )
628636 end
629637
@@ -676,7 +684,9 @@ def build_chat_params(tools:, instructions:, messages:, tool_choice:)
676684 params
677685 end
678686
679- def build_message ( role :, content : nil , tool_calls : [ ] , tool_call_id : nil )
687+ def build_message ( role :, content : nil , image_url : nil , tool_calls : [ ] , tool_call_id : nil )
688+ warn "Image URL is not supported by Anthropic currently" if image_url
689+
680690 Langchain ::Messages ::AnthropicMessage . new ( role : role , content : content , tool_calls : tool_calls , tool_call_id : tool_call_id )
681691 end
682692
0 commit comments