From 2739a492b41105d84bff454b6a2b38ec00e6106e Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 8 Mar 2023 18:45:13 -0600 Subject: [PATCH] Log message metadata along with Khoj message instead of user message References should be attached to khoj chat messsage rather than the users message in the chat interface --- src/khoj/processor/conversation/gpt.py | 12 +++++------- src/khoj/routers/api_beta.py | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/khoj/processor/conversation/gpt.py b/src/khoj/processor/conversation/gpt.py index 22f229aa..8874c805 100644 --- a/src/khoj/processor/conversation/gpt.py +++ b/src/khoj/processor/conversation/gpt.py @@ -186,22 +186,20 @@ def message_to_prompt( return f"{conversation_history}{restart_sequence} {user_message}{start_sequence}{gpt_message}" -def message_to_log(user_message, gpt_message, user_message_metadata={}, conversation_log=[]): +def message_to_log(user_message, gpt_message, khoj_message_metadata={}, conversation_log=[]): """Create json logs from messages, metadata for conversation log""" - default_user_message_metadata = { + default_khoj_message_metadata = { "intent": {"type": "remember", "memory-type": "notes", "query": user_message}, "trigger-emotion": "calm", } current_dt = datetime.now().strftime("%Y-%m-%d %H:%M:%S") # Create json log from Human's message - human_log = merge_dicts(user_message_metadata, default_user_message_metadata) - human_log["message"] = user_message - human_log["by"] = "you" - human_log["created"] = current_dt + human_log = {"message": user_message, "by": "you", "created": current_dt} # Create json log from GPT's response - khoj_log = {"message": gpt_message, "by": "khoj", "created": current_dt} + khoj_log = merge_dicts(khoj_message_metadata, default_khoj_message_metadata) + khoj_log = merge_dicts({"message": gpt_message, "by": "khoj", "created": current_dt}, khoj_log) conversation_log.extend([human_log, khoj_log]) return conversation_log diff --git a/src/khoj/routers/api_beta.py b/src/khoj/routers/api_beta.py index 1ee6e552..1baf0142 100644 --- a/src/khoj/routers/api_beta.py +++ b/src/khoj/routers/api_beta.py @@ -101,7 +101,7 @@ def chat(q: Optional[str] = None): # Update Conversation History state.processor_config.conversation.chat_session = message_to_prompt(q, chat_session, gpt_message=gpt_response) state.processor_config.conversation.meta_log["chat"] = message_to_log( - q, gpt_response, user_message_metadata={"context": collated_result}, conversation_log=meta_log.get("chat", []) + q, gpt_response, khoj_message_metadata={"context": collated_result}, conversation_log=meta_log.get("chat", []) ) return {"status": status, "response": gpt_response, "context": collated_result}