Do not add "Notes:" suffix to chat messages when no notes retrieved

This was causing spurious "Notes:" suffix being added to Khoj Chat in
response
This commit is contained in:
Debanjum Singh Solanky 2023-05-28 19:28:57 +05:30
parent 334be4e600
commit 277d2f5c96

View file

@ -72,7 +72,11 @@ def generate_chatml_messages_with_context(
):
"""Generate messages for ChatGPT with context from previous conversation"""
# Extract Chat History for Context
chat_logs = [f'{chat["message"]}\n\nNotes:\n{chat.get("context","")}' for chat in conversation_log.get("chat", [])]
chat_logs = []
for chat in conversation_log.get("chat", []):
chat_notes = f'\n\n Notes:\n{chat.get("context")}' if chat.get("context") else "\n"
chat_logs += [chat["message"] + chat_notes]
rest_backnforths = []
# Extract in reverse chronological order
for user_msg, assistant_msg in zip(chat_logs[-2::-2], chat_logs[::-2]):