From adb2e8cc5f61b4750be527abe3f5a6ac69c8b977 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Tue, 16 Apr 2024 02:05:58 +0530 Subject: [PATCH] Check if n is populated before making a comparison --- src/khoj/routers/api_chat.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/khoj/routers/api_chat.py b/src/khoj/routers/api_chat.py index 867319ed..b4ec2454 100644 --- a/src/khoj/routers/api_chat.py +++ b/src/khoj/routers/api_chat.py @@ -110,12 +110,13 @@ def chat_history( } ) - # Get latest N messages if N > 0 - if n > 0 and meta_log.get("chat"): - meta_log["chat"] = meta_log["chat"][-n:] - # Else return all messages except latest N - elif n < 0 and meta_log.get("chat"): - meta_log["chat"] = meta_log["chat"][:n] + if n: + # Get latest N messages if N > 0 + if n > 0 and meta_log.get("chat"): + meta_log["chat"] = meta_log["chat"][-n:] + # Else return all messages except latest N + elif n < 0 and meta_log.get("chat"): + meta_log["chat"] = meta_log["chat"][:n] update_telemetry_state( request=request,