llama-index

Форк
0
62 строки · 1.9 Кб
1
"""Download loader from Llama Hub.
2

3
NOTE: using `download_loader` is now deprecated.
4
Please do `pip install llama-hub` instead.
5

6
"""
7

8
from typing import Optional, Type
9

10
from llama_index.legacy.download.module import (
11
    LLAMA_HUB_URL,
12
    MODULE_TYPE,
13
    download_llama_module,
14
    track_download,
15
)
16
from llama_index.legacy.readers.base import BaseReader
17

18

19
def download_loader(
20
    loader_class: str,
21
    loader_hub_url: str = LLAMA_HUB_URL,
22
    refresh_cache: bool = False,
23
    use_gpt_index_import: bool = False,
24
    custom_path: Optional[str] = None,
25
) -> Type[BaseReader]:
26
    """Download a single loader from the Loader Hub.
27

28
    Args:
29
        loader_class: The name of the loader class you want to download,
30
            such as `SimpleWebPageReader`.
31
        refresh_cache: If true, the local cache will be skipped and the
32
            loader will be fetched directly from the remote repo.
33
        use_gpt_index_import: If true, the loader files will use
34
            llama_index as the base dependency. By default (False),
35
            the loader files use llama_index as the base dependency.
36
            NOTE: this is a temporary workaround while we fully migrate all usages
37
            to llama_index.
38
        custom_path: Custom dirpath to download loader into.
39

40
    Returns:
41
        A Loader.
42
    """
43
    # Only one of the `custom_dir` or `custom_path` is supported.
44
    if custom_path is not None:
45
        custom_dir = None
46
    else:
47
        custom_dir = "llamahub_modules"
48

49
    reader_cls = download_llama_module(
50
        loader_class,
51
        llama_hub_url=loader_hub_url,
52
        refresh_cache=refresh_cache,
53
        custom_dir=custom_dir,
54
        custom_path=custom_path,
55
        use_gpt_index_import=use_gpt_index_import,
56
    )
57
    if not issubclass(reader_cls, BaseReader):
58
        raise ValueError(
59
            f"Loader class {loader_class} must be a subclass of BaseReader."
60
        )
61
    track_download(loader_class, MODULE_TYPE.LOADER)
62
    return reader_cls
63

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.