|  | 
| 83 | 83 | from .anki import load_anki | 
| 84 | 84 | 
 | 
| 85 | 85 | # Mapping of filetypes to their corresponding loader function names | 
| 86 |  | -FILETYPE_TO_LOADER = { | 
|  | 86 | +LOADABLE_FILETYPE = { | 
| 87 | 87 |     "url": "load_url", | 
| 88 | 88 |     "youtube": "load_youtube_video", | 
| 89 | 89 |     "pdf": "load_pdf", | 
| @@ -220,13 +220,13 @@ def load_one_doc( | 
| 220 | 220 |     assert temp_dir.exists(), temp_dir | 
| 221 | 221 | 
 | 
| 222 | 222 |     # Check if filetype is supported | 
| 223 |  | -    if filetype not in FILETYPE_TO_LOADER: | 
|  | 223 | +    if filetype not in LOADABLE_FILETYPE: | 
| 224 | 224 |         logger.warning(f"Unsupported filetype: '{filetype}'") | 
| 225 | 225 |         raise Exception(f"Unsupported filetype: '{filetype}'") | 
| 226 | 226 | 
 | 
| 227 |  | -    # Get the loader function name and retrieve the actual function | 
| 228 |  | -    loader_func_name = FILETYPE_TO_LOADER[filetype] | 
| 229 |  | -    loader_func = locals().get(loader_func_name) or globals().get(loader_func_name) | 
|  | 227 | +    # Lazy loading the document loader function | 
|  | 228 | +    exec(f"from .{filetype} import load_{filetype}") | 
|  | 229 | +    loader_func = locals()[f"load_{filetype}"] or globals()[f"load_{filetype}"] or None | 
| 230 | 230 | 
 | 
| 231 | 231 |     if loader_func is None: | 
| 232 | 232 |         raise Exception( | 
| @@ -2205,9 +2205,9 @@ def dl_audio_from_url(trial: int, url: str) -> Path: | 
| 2205 | 2205 | 
 | 
| 2206 | 2206 | # Validation: Check that all loader functions exist | 
| 2207 | 2207 | def _validate_loader_functions(): | 
| 2208 |  | -    """Validate that all loader functions referenced in FILETYPE_TO_LOADER exist.""" | 
|  | 2208 | +    """Validate that all loader functions referenced in LOADABLE_FILETYPE exist.""" | 
| 2209 | 2209 |     current_module = sys.modules[__name__] | 
| 2210 |  | -    for filetype, func_name in FILETYPE_TO_LOADER.items(): | 
|  | 2210 | +    for filetype, func_name in LOADABLE_FILETYPE.items(): | 
| 2211 | 2211 |         if not hasattr(current_module, func_name): | 
| 2212 | 2212 |             raise Exception( | 
| 2213 | 2213 |                 f"Loader function '{func_name}' for filetype '{filetype}' not found in module" | 
|  | 
0 commit comments