langchain/chains/loading.py/_load_map_reduce_documents_chain
def _load_map_reduce_documents_chain(
    config: dict, **kwargs: Any
) -> MapReduceDocumentsChain:
    if "llm_chain" in config:
        llm_chain_config = config.pop("llm_chain")
        llm_chain = load_chain_from_config(llm_chain_config)
    elif "llm_chain_path" in config:
        llm_chain = load_chain(config.pop("llm_chain_path"))
    else:
        raise ValueError("One of `llm_chain` or `llm_chain_config` must be present.")

    if not isinstance(llm_chain, LLMChain):
        raise ValueError(f"Expected LLMChain, got {llm_chain}")

    if "combine_document_chain" in config:
        combine_document_chain_config = config.pop("combine_document_chain")
        combine_document_chain = load_chain_from_config(combine_document_chain_config)
    elif "combine_document_chain_path" in config:
        combine_document_chain = load_chain(config.pop("combine_document_chain_path"))
    else:
        raise ValueError(
            "One of `combine_document_chain` or "
            "`combine_document_chain_path` must be present."
        )
    if "collapse_document_chain" in config:
        collapse_document_chain_config = config.pop("collapse_document_chain")
        if collapse_document_chain_config is None:
            collapse_document_chain = None
        else:
            collapse_document_chain = load_chain_from_config(
                collapse_document_chain_config
            )
    elif "collapse_document_chain_path" in config:
        collapse_document_chain = load_chain(config.pop("collapse_document_chain_path"))
    return MapReduceDocumentsChain(
        llm_chain=llm_chain,
        combine_document_chain=combine_document_chain,
        collapse_document_chain=collapse_document_chain,
        **config,
    )