helper functions:
def get_model_role(created_by):
if created_by == "Ray":
return MessageRole.ASSISTANT
else:
return MessageRole.USER
def convert_chat_to_chat_message(index, message):
print(index, message)
return ChatMessage(
id=message["id"],
index=index,
content=message["message"],
role=get_model_role(message["created_by"])
)
Creating the chat_history object:
# Convert all but the last message to a List[ChatMessage]
chat_history = [convert_chat_to_chat_message(index, message) for index, message in enumerate(chat.messages[:-1])]
# Send message plus history to chat engine
result = chat_engine.chat(
message = chat.messages[-1]["message"],
chat_history = chat_history
)