Viewing File: /home/ubuntu/codegamaai-test/efisupport_bot/src/chats.py

from llama_index.llms import ChatMessage, MessageRole

def convert_chat_message(chat_history):
    """
    Convert chat history from MongoDB to the format required by the chat engine
    """

    chat = []

    for message in chat_history:
        chat.append(ChatMessage(
        role=get_history_role(message), 
        content=message['message'],
    ))

    return chat

def get_history_role(message):
    """
    Get the role of the message in the chat history
    """

    if message['role'] == 'user':
        return MessageRole.USER
    else:
        return MessageRole.ASSISTANT
Back to Directory File Manager