Skip to content

Commit

Permalink
Use .get() to get text accompanying image url, instead of subindexing
Browse files Browse the repository at this point in the history
  • Loading branch information
sabaimran committed Nov 5, 2024
1 parent 1e89bac commit e3ca52b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/khoj/processor/conversation/google/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit e3ca52b

Please sign in to comment.