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
This commit is contained in:
Debanjum Singh Solanky 2023-03-08 18:45:13 -06:00
parent 87d1e1341d
commit 2739a492b4
2 changed files with 6 additions and 8 deletions

View file

@ -186,22 +186,20 @@ def message_to_prompt(
return f"{conversation_history}{restart_sequence} {user_message}{start_sequence}{gpt_message}" 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""" """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}, "intent": {"type": "remember", "memory-type": "notes", "query": user_message},
"trigger-emotion": "calm", "trigger-emotion": "calm",
} }
current_dt = datetime.now().strftime("%Y-%m-%d %H:%M:%S") current_dt = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Create json log from Human's message # Create json log from Human's message
human_log = merge_dicts(user_message_metadata, default_user_message_metadata) human_log = {"message": user_message, "by": "you", "created": current_dt}
human_log["message"] = user_message
human_log["by"] = "you"
human_log["created"] = current_dt
# Create json log from GPT's response # 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]) conversation_log.extend([human_log, khoj_log])
return conversation_log return conversation_log

View file

@ -101,7 +101,7 @@ def chat(q: Optional[str] = None):
# Update Conversation History # Update Conversation History
state.processor_config.conversation.chat_session = message_to_prompt(q, chat_session, gpt_message=gpt_response) 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( 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} return {"status": status, "response": gpt_response, "context": collated_result}