From e3ca52b7cb6e46ef8627cc038275e98fbb64b363 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Mon, 4 Nov 2024 16:09:16 -0800 Subject: [PATCH] Use .get() to get text accompanying image url, instead of subindexing --- src/khoj/processor/conversation/google/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/khoj/processor/conversation/google/utils.py b/src/khoj/processor/conversation/google/utils.py index 7b848324..84ad607e 100644 --- a/src/khoj/processor/conversation/google/utils.py +++ b/src/khoj/processor/conversation/google/utils.py @@ -228,7 +228,9 @@ def format_messages_for_gemini(messages: list[ChatMessage], system_prompt: str = if isinstance(message.content, list): # Convert image_urls to PIL.Image and place them at beginning of list (better for Gemini) message.content = [ - get_image_from_url(item["image_url"]["url"]).content if item["type"] == "image_url" else item["text"] + get_image_from_url(item["image_url"]["url"]).content + if item["type"] == "image_url" + else item.get("text", "") for item in sorted(message.content, key=lambda x: 0 if x["type"] == "image_url" else 1) ] elif isinstance(message.content, str):