From f8957e52bf008eb38b93ca4bde196657a0d35e2e Mon Sep 17 00:00:00 2001 From: Debanjum Date: Sun, 8 Dec 2024 22:40:32 -0800 Subject: [PATCH] Keep chatml message content simple for wider compat unless attachments This allows for wider compatibility with chat models and openai proxy ai model apis that expect message content to be string format, not objects. --- src/khoj/processor/conversation/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/khoj/processor/conversation/utils.py b/src/khoj/processor/conversation/utils.py index 12fc736f..49c7fb2e 100644 --- a/src/khoj/processor/conversation/utils.py +++ b/src/khoj/processor/conversation/utils.py @@ -333,9 +333,10 @@ def construct_structured_message( ChatModelOptions.ModelType.GOOGLE, ChatModelOptions.ModelType.ANTHROPIC, ]: - constructed_messages: List[Any] = [ - {"type": "text", "text": message}, - ] + if not attached_file_context and not (vision_enabled and images): + return message + + constructed_messages: List[Any] = [{"type": "text", "text": message}] if not is_none_or_empty(attached_file_context): constructed_messages.append({"type": "text", "text": attached_file_context})