def _to_message_dicts(
    messages: Sequence[ChatMessage], drop_none: bool = False
) -> List[Dict[str, Any]]:
    """
    Convert a sequence of ChatMessage objects to a list of dictionaries.

    Args:
        messages: The messages to convert.
        drop_none: Whether to drop keys with `None` values. Defaults to False.

    Returns:
        A list of message dictionaries.

    """
    message_dicts = []
    for message in messages:
        message_dict = {
            "role": message.role.value,
            "content": message.content,
            **message.additional_kwargs,
        }
        if drop_none:
            message_dict = {k: v for k, v in message_dict.items() if v is not None}
        message_dicts.append(message_dict)
    return message_dicts

    Convert a sequence of ChatMessage objects to a list of dictionaries.

    Args:
        messages: The messages to convert.
        drop_none: Whether to drop keys with `None` values. Defaults to False.

    Returns:
        A list of message dictionaries.

    
llama-index-integrations/llms/llama-index-llms-oci-data-science/llama_index/llms/oci_data_science/utils.py