From 457677c1b73259039fc2514f8be81824282d9fba Mon Sep 17 00:00:00 2001 From: Atul R Date: Thu, 11 Jul 2024 20:31:48 +0200 Subject: [PATCH] community: Fixes use of ImagePromptTemplate with Ollama (#24140) Description: ImagePromptTemplate for Multimodal llms like llava when using Ollama Twitter handle: https://x.com/a7ulr Details: When using llava models / any ollama multimodal llms and passing images in the prompt as urls, langchain breaks with this error. ```python image_url_components = image_url.split(",") ^^^^^^^^^^^^^^^^^^^^ AttributeError: 'dict' object has no attribute 'split' ``` From the looks of it, there was bug where the condition did check for a `url` field in the variable but missed to actually assign it. This PR fixes ImagePromptTemplate for Multimodal llms like llava when using Ollama specifically. @hwchase17 --- libs/community/langchain_community/chat_models/ollama.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/community/langchain_community/chat_models/ollama.py b/libs/community/langchain_community/chat_models/ollama.py index ca936a1c51b..298bfca97f6 100644 --- a/libs/community/langchain_community/chat_models/ollama.py +++ b/libs/community/langchain_community/chat_models/ollama.py @@ -144,7 +144,7 @@ class ChatOllama(BaseChatModel, _OllamaCommon): elif ( isinstance(temp_image_url, dict) and "url" in temp_image_url ): - image_url = temp_image_url + image_url = temp_image_url["url"] else: raise ValueError( "Only string image_url or dict with string 'url' "