def METHOD_NAME(passages, keep_only_relevant_passages):
    contexts = []
    if keep_only_relevant_passages:
        for passage in passages:
            if passage["is_selected"] == 1:
                contexts.append(passage["passage_text"])
    else:
        contexts = [passage["passage_text"] for passage in passages]
    return " ".join(contexts)