def chat_messages_to_list(messages: Sequence[ChatMessage]) -> Sequence[Dict[str, Any]]:
    """
    Convert a sequence of chat messages to a list of dictionaries.

    Args:
        messages (Sequence[ChatMessage]): A sequence of chat messages.

    Returns:
        Sequence[Dict[str, Any]]: A list of dictionaries.

    """
    chat_messages = []
    for message in messages:
        if message.role in [
            MessageRole.USER,
            MessageRole.ASSISTANT,
            MessageRole.SYSTEM,
            MessageRole.TOOL,
        ]:
            chat_messages.append(
                {
                    "role": message.role,
                    "content": message.content,
                    **message.additional_kwargs,
                }
            )

    return chat_messages

    Convert a sequence of chat messages to a list of dictionaries.

    Args:
        messages (Sequence[ChatMessage]): A sequence of chat messages.

    Returns:
        Sequence[Dict[str, Any]]: A list of dictionaries.

    
llama-index-integrations/llms/llama-index-llms-deepinfra/llama_index/llms/deepinfra/utils.py