Update handling of images when included in the chat history with assistant message
Some checks failed
dockerize / Publish Khoj Docker Images (push) Waiting to run
build and deploy github pages for documentation / deploy (push) Waiting to run
pypi / Publish Python Package to PyPI (push) Waiting to run
desktop / 🖥️ Build, Release Desktop App (push) Has been cancelled
pre-commit / Setup Application and Lint (push) Has been cancelled
test / Run Tests (push) Has been cancelled

This commit is contained in:
sabaimran 2024-12-08 21:46:04 -08:00
parent b660c494bc
commit eb36492ba5

View file

@ -433,8 +433,7 @@ def generate_chatml_messages_with_context(
reconstructed_context_message = ChatMessage(content=message_context, role="user")
chatml_messages.insert(0, reconstructed_context_message)
if chat.get("images"):
if role == "assistant":
if chat.get("images") and role == "assistant":
# Issue: the assistant role cannot accept an image as a message content, so send it in a separate user message.
file_attachment_message = construct_structured_message(
message=prompts.generated_image_attachment.format(),
@ -443,9 +442,9 @@ def generate_chatml_messages_with_context(
vision_enabled=vision_enabled,
)
chatml_messages.append(ChatMessage(content=file_attachment_message, role="user"))
else:
message_content = construct_structured_message(
chat_message, chat.get("images"), model_type, vision_enabled
chat_message, chat.get("images") if role == "user" else [], model_type, vision_enabled
)
reconstructed_message = ChatMessage(content=message_content, role=role)