def llama_index_to_mistralrs_messages(
    messages: Sequence[ChatMessage],
) -> List[Dict[str, str]]:
    """
    Convert llamaindex to mistralrs messages. Raises an exception if the role is not user or assistant.
    """
    messages_new = []
    for message in messages:
        if message.role == "user":
            messages_new.append({"role": "user", "content": message.content})
        elif message.role == "assistant":
            messages_new.append({"role": "assistant", "content": message.content})
        elif message.role == "system":
            messages_new.append({"role": "system", "content": message.content})
        else:
            raise ValueError(
                f"Unsupported chat role `{message.role}` for `mistralrs` automatic chat templating: supported are `user`, `assistant`, `system`. Please specify `messages_to_prompt`."
            )
    return messages_new

    Convert llamaindex to mistralrs messages. Raises an exception if the role is not user or assistant.
    
llama-index-integrations/llms/llama-index-llms-mistral-rs/llama_index/llms/mistral_rs/base.py