mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Make user_message_metadata arg to message_to_log in gpt.py optional
- Use a default user_message_metadata if arg not set - Update conversation to use `by' as `you' and `khoj'
This commit is contained in:
parent
cc2456e411
commit
cb6f0b53c9
2 changed files with 18 additions and 7 deletions
|
@ -210,20 +210,31 @@ def message_to_prompt(user_message, conversation_history="", gpt_message=None, s
|
|||
return f"{conversation_history}{restart_sequence} {user_message}{start_sequence}{gpt_message}"
|
||||
|
||||
|
||||
def message_to_log(user_message, user_message_metadata, gpt_message, conversation_log=[]):
|
||||
def message_to_log(user_message, gpt_message, user_message_metadata={}, conversation_log=[]):
|
||||
"""Create json logs from messages, metadata for conversation log"""
|
||||
default_user_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 = user_message_metadata
|
||||
human_log = user_message_metadata or default_user_message_metadata
|
||||
human_log["message"] = user_message
|
||||
human_log["by"] = "Human"
|
||||
human_log["created"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
human_log["by"] = "you"
|
||||
human_log["created"] = current_dt
|
||||
|
||||
# Create json log from GPT's response
|
||||
ai_log = {"message": gpt_message, "by": "AI", "created": datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
|
||||
khoj_log = {"message": gpt_message, "by": "khoj", "created": current_dt}
|
||||
|
||||
conversation_log.extend([human_log, ai_log])
|
||||
conversation_log.extend([human_log, khoj_log])
|
||||
return conversation_log
|
||||
|
||||
|
||||
def extract_summaries(metadata):
|
||||
"""Extract summaries from metadata"""
|
||||
return ''.join(
|
||||
|
|
|
@ -100,7 +100,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, metadata, gpt_response, meta_log.get('chat', []))
|
||||
state.processor_config.conversation.meta_log['chat'] = message_to_log(q, gpt_response, metadata, meta_log.get('chat', []))
|
||||
|
||||
return {'status': status, 'response': gpt_response}
|
||||
|
||||
|
|
Loading…
Reference in a new issue