From 8ef7892c5e1c896774a27bcd9a3aab1ec1a3e0eb Mon Sep 17 00:00:00 2001 From: Debanjum Date: Sun, 10 Nov 2024 13:42:55 -0800 Subject: [PATCH] Exclude non-dictionary doc context from chat history sent to chat models This fixes chat with old chat sessions. Fixes issue with old Whatsapp users can't chat with Khoj because chat history doc context was stored as a list earlier --- src/khoj/processor/conversation/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/khoj/processor/conversation/utils.py b/src/khoj/processor/conversation/utils.py index 74c464d9..c6b3bc2f 100644 --- a/src/khoj/processor/conversation/utils.py +++ b/src/khoj/processor/conversation/utils.py @@ -338,7 +338,11 @@ def generate_chatml_messages_with_context( message_context += chat.get("intent").get("inferred-queries")[0] if not is_none_or_empty(chat.get("context")): references = "\n\n".join( - {f"# File: {item['file']}\n## {item['compiled']}\n" for item in chat.get("context") or []} + { + f"# File: {item['file']}\n## {item['compiled']}\n" + for item in chat.get("context") or [] + if isinstance(item, dict) + } ) message_context += f"{prompts.notes_conversation.format(references=references)}\n\n" if not is_none_or_empty(chat.get("onlineContext")):