@@ -24,6 +24,7 @@ class DefaultFileReader(FileLoaderSkill):
2424 - .doc, .docx: Word documents using UnstructuredWordDocumentLoader
2525 - .ppt, .pptx: PowerPoint files using UnstructuredPowerPointLoader
2626 - .xls, .xlsx: Excel files using UnstructuredExcelLoader
27+ - .yml, .yaml: YAML files using PyYAML (multiple documents supported)
2728 """
2829
2930 def __init__ (self , skill_config : dict , global_config : Config ) -> None :
@@ -38,7 +39,32 @@ def __init__(self, skill_config: dict, global_config: Config) -> None:
3839 ".pptx" : self ._load_powerpoint ,
3940 ".xls" : self ._load_excel ,
4041 ".xlsx" : self ._load_excel ,
42+ ".yml" : self ._load_yaml ,
43+ ".yaml" : self ._load_yaml ,
4144 }
45+
46+ def _load_yaml (self , file_path : Path ) -> List [Document ]:
47+ """Load YAML files that may contain multiple documents separated by ---."""
48+ try :
49+ import yaml
50+ except ImportError as err :
51+ raise ImportError ("yaml module is required to read YAML files." ) from err
52+
53+ documents = []
54+ with file_path .open () as fp :
55+ for i , content in enumerate (yaml .safe_load_all (fp )):
56+ if content is not None :
57+ yaml_text = yaml .safe_dump (content )
58+ doc_name = f"{ file_path .stem } _doc_{ i } { file_path .suffix } "
59+ documents .append (
60+ Document (
61+ filename = str (file_path ),
62+ source_url = str (file_path ),
63+ text = yaml_text
64+ )
65+ )
66+
67+ return documents
4268
4369 def run (self , documents : Optional [List [Document ]]) -> List [Document ]:
4470 """Process input documents by reading their content based on file extension.
@@ -118,4 +144,4 @@ def _load_excel(self, file_path: Path) -> List[Document]:
118144 """Load Excel files using UnstructuredExcelLoader."""
119145 loader = UnstructuredExcelLoader (str (file_path ))
120146 docs = loader .load ()
121- return [Document (filename = str (file_path ), source_url = str (file_path ), text = doc .page_content ) for doc in docs ]
147+ return [Document (filename = str (file_path ), source_url = str (file_path ), text = doc .page_content ) for doc in docs ]
0 commit comments