llama_index: Not able to use LLama Packs [Bug]:

Bug Description

I always get this error for any pack i download FileNotFoundError: [Errno 2] No such file or directory: ‘/content/chain_of_table_pack/llama_index/packs/tables/base.py’

Version

0.10.5

Steps to Reproduce

download_llama_pack( “ChainOfTablePack”, “./chain_of_table_pack”, )

Relevant Logs/Tracbacks

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-6-da45d7f3ade5> in <cell line: 3>()
      1 from llama_index.core.llama_pack import download_llama_pack
      2 
----> 3 download_llama_pack(
      4     "ChainOfTablePack",
      5     "./chain_of_table_pack",

4 frames
/usr/local/lib/python3.10/dist-packages/llama_index/core/llama_pack/download.py in download_llama_pack(llama_pack_class, download_dir, llama_pack_url, refresh_cache)
     54         )
     55     else:
---> 56         pack_cls = download_llama_pack_template(
     57             new_install_parent=new_install_parent,
     58             llama_pack_class=llama_pack_class,

/usr/local/lib/python3.10/dist-packages/llama_index/core/download/pack.py in download_llama_pack_template(new_install_parent, llama_pack_class, llama_pack_url, llama_pack_source_files_dir_path, refresh_cache, custom_dir, custom_path, base_file_name)
    124 
    125     module = util.module_from_spec(spec)
--> 126     spec.loader.exec_module(module)  # type: ignore
    127 
    128     return getattr(module, llama_pack_class)

/usr/lib/python3.10/importlib/_bootstrap_external.py in exec_module(self, module)

/usr/lib/python3.10/importlib/_bootstrap_external.py in get_code(self, fullname)

/usr/lib/python3.10/importlib/_bootstrap_external.py in get_data(self, path)

FileNotFoundError: [Errno 2] No such file or directory:

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

🤖

Hey @jaideep11061982, back again diving into the deep end with Llama Packs, I see! Let’s tackle this head-on.

Based on the error logs you’ve provided, it seems like the issue is related to the file path of the pack you’re trying to download. The error FileNotFoundError: [Errno 2] No such file or directory: '/content/chain_of_table_pack/llama_index/packs/tables/base.py' indicates that the file or directory you’re trying to access doesn’t exist.

This could be due to a couple of reasons:

  1. The directory you’re trying to download the pack into does not exist. In the handle_download_llama_pack function, the download_dir argument is used as the directory to download the pack into. If this directory does not exist, a FileNotFoundError could be raised.
def handle_download_llama_pack(
    llama_pack_class: Optional[str] = None,
    download_dir: Optional[str] = None,
    llama_pack_url: str = LLAMA_PACKS_CONTENTS_URL,
    **kwargs: Any,
) -> None:
    assert llama_pack_class is not None
    assert download_dir is not None

    download_llama_pack(
        llama_pack_class=llama_pack_class,
        download_dir=download_dir or "./custom_llama_pack",
        llama_pack_url=llama_pack_url,
    )
    print(f"Successfully downloaded {llama_pack_class} to {download_dir}")
  1. The pack you’re trying to download does not exist. In the download_llama_pack function, the llama_pack_class argument is used to specify the pack to download. If this pack does not exist, a FileNotFoundError could be raised.

To resolve this issue, ensure that the directory you’re trying to download the pack into exists and that the pack you’re trying to download also exists. You can refer to the llama-index-cli/llama_index/cli/command_line.py for more details.

Also, there was a similar issue reported in the past, you can refer to this issue for more context.

Regarding the structure of the directory where the Llama Packs are supposed to be downloaded, it is not explicitly mentioned in the provided context. However, the directory can be specified by the user when downloading a Llama Pack. This is done using the --download-dir argument in the CLI command or the second argument in the download_llama_pack function in Python.

CLI command:

llamaindex-cli download-llamapack <pack_name> --download-dir <pack_directory>

Python code:

from llama_index.core.llama_pack import download_llama_pack

# download and install dependencies
pack_cls = download_llama_pack("<pack_name>", "<pack_directory>")

In both cases, <pack_directory> should be replaced with the desired directory path. You can refer to the docs/community/llama_packs/root.md for more details.

I hope this helps! If you have any more questions or need further clarification, feel free to ask.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

Hi @dian-R no worries. Okay, I think I got you. Actually what you have experienced is the expectation in v0.10.x.

In case you missed it, in the latest big release (v0.10.x) we’ve refactored the library by splitting it into “llama-index-core” and many integration packages. The idea being that you install “core” and only the other “integration” packages you need for your application. Now, to make things simpler for our users we’ve actually included llama-index-core plus other popular integration packages (like llama-index-llms-openai) in the main package llama-index.

In terms of ChainOfTableQueryEngine, its package llama-index-packs-tables is not included in llama-index. This means, that in order to be able to import it and use it, you do have to pip install it. So, that’s why after you installed it via poetry (equivalently with pip) you were finally able to import it.

Here’s another example for you to help drive home the changes in v0.10.x. If you want to use HuggingFaceEmbeddings, you would need to install llama-index-embeddings-huggingface package as well as llama-index.

Here’s some more info on the release for you:

Hi @jaideep11061982, I just tried importing both ChainOfTableQueryEngine and serialize_table and it worked for me.

Are you sure that you are using a fresh virtual environment? It looks like you’re using conda, please try this:

# conda
conda create -n venv python=3.11 anaconda # can use any Python 3.9 - 3.12 
conda activate venv
pip install llama-index llama-index-packs-tables

And with venv active:

from llama_index.packs.tables.chain_of_table.base import ChainOfTableQueryEngine, serialize_table

# these should work
# in future we can add seralize_table as top-level import but for now the above should work

Thanks @jaideep11061982 for raising. Can confirm that I am able to reproduce the bug. Looks like this is caused by the logic for downloading packs not taking into account of multi-level code structure. Specifically, its looking for the base.py file, but for this pack, the “base.py” files are found one level deeper in the source code.

Will submit a fix for this shortly.