
    Ng                     :    d dl mZ d dlmZ  G d de          ZdS )    )List)UnstructuredFileLoaderc                       e Zd ZdZdefdZdS )UnstructuredMarkdownLoadera  Load `Markdown` files using `Unstructured`.

    You can run the loader in one of two modes: "single" and "elements".
    If you use "single" mode, the document will be returned as a single
    langchain Document object. If you use "elements" mode, the unstructured
    library will split the document into elements such as Title and NarrativeText.
    You can pass in additional unstructured kwargs after mode to apply
    different unstructured settings.

    Setup:
        Install ``langchain-community``.

        .. code-block:: bash

            pip install -U langchain-community

    Instantiate:
        .. code-block:: python

            from langchain_community.document_loaders import UnstructuredMarkdownLoader

            loader = UnstructuredMarkdownLoader(
                "./example_data/example.md",
                mode="elements",
                strategy="fast",
            )

    Lazy load:
        .. code-block:: python

            docs = []
            docs_lazy = loader.lazy_load()

            # async variant:
            # docs_lazy = await loader.alazy_load()

            for doc in docs_lazy:
                docs.append(doc)
            print(docs[0].page_content[:100])
            print(docs[0].metadata)

        .. code-block:: python

            Sample Markdown Document
            {'source': './example_data/example.md', 'category_depth': 0, 'last_modified': '2024-08-14T15:04:18', 'languages': ['eng'], 'filetype': 'text/markdown', 'file_directory': './example_data', 'filename': 'example.md', 'category': 'Title', 'element_id': '3d0b313864598e704aa26c728ecb61e5'}


    Async load:
        .. code-block:: python

            docs = await loader.aload()
            print(docs[0].page_content[:100])
            print(docs[0].metadata)

        .. code-block:: python

            Sample Markdown Document
            {'source': './example_data/example.md', 'category_depth': 0, 'last_modified': '2024-08-14T15:04:18', 'languages': ['eng'], 'filetype': 'text/markdown', 'file_directory': './example_data', 'filename': 'example.md', 'category': 'Title', 'element_id': '3d0b313864598e704aa26c728ecb61e5'}

    References
    ----------
    https://unstructured-io.github.io/unstructured/core/partition.html#partition-md
    returnc                    ddl m} ddlm} |                    d          d         }t          d |                    d          D                       }|dk     rt          d| d	           |dd
| j        i| j        S )Nr   )__version__)partition_md-c                 ,    g | ]}t          |          S  )int).0xs     i/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/document_loaders/markdown.py
<listcomp>z<UnstructuredMarkdownLoader._get_elements.<locals>.<listcomp>N   s    %W%W%Wc!ff%W%W%W    .)r         z You are on unstructured version zH. Partitioning markdown files is only supported in unstructured>=0.4.16.filenamer   )	unstructured.__version__r	   unstructured.partition.mdr
   splittuple
ValueError	file_pathunstructured_kwargs)self__unstructured_version__r
   _unstructured_versionunstructured_versions        r   _get_elementsz(UnstructuredMarkdownLoader._get_elementsG   s    TTTTTT:::::: !9 > >s C CA F$%W%W6K6Q6QRU6V6V%W%W%WXX*,,Y3K Y Y Y  
 |PPT^Pt7OPPPr   N)__name__
__module____qualname____doc__r   r#   r   r   r   r   r      sA        > >@Qt Q Q Q Q Q Qr   r   N)typingr   1langchain_community.document_loaders.unstructuredr   r   r   r   r   <module>r*      sr          T T T T T TPQ PQ PQ PQ PQ!7 PQ PQ PQ PQ PQr   