from datasets import Dataset
import os


def conversation_array_to_string(
    dataset: Dataset, conversation_column: str, flat_column_name: str
) -> Dataset:
    """
    Will turn the datasets conversation array [{'from': 'user', 'value': '...'}, {'from': 'assistant', 'value': '...'}, ...] into a flat string
    """
    dataset = dataset.map(
        lambda x: {
            flat_column_name: " ".join(
                [f"{item['from']}: {item['value']}" for item in x[conversation_column]]
            ),
        },
        num_proc=os.cpu_count(),
    )
    return dataset
