llama_index: [Bug]: AssertionError 2024-12-01 12:51:18.470 Examining the path of torch.classes raised: Tried to instantiate class '__path__._path', but it does not exist! Ensure that it is registered via torch::class_

Bug Description

AssertionError 2024-12-01 12:51:18.470 Examining the path of torch.classes raised: Tried to instantiate class 'path.path’, but it does not exist! Ensure that it is registered via torch::class

Version

python = “3.11” llama-index = “0.11.23”

Steps to Reproduce

python = “^3.11” llama-index = “0.11.23” llama-index-vector-stores-chroma = “0.3.0” llama-index-llms-ollama = “0.3.6”

Relevant Logs/Tracbacks

2024-12-01 12:51:17.157 Uncaught app exception
Traceback (most recent call last):
  File "C:\Users\VilvanSS\AppData\Local\pypoetry\Cache\virtualenvs\golden_build-6-JWb2q3-py3.11\Lib\site-packages\streamlit\runtime\scriptrunner\exec_code.py", line 88, in exec_func_with_error_handling
    result = func()
             ^^^^^^
  File "C:\Users\VilvanSS\AppData\Local\pypoetry\Cache\virtualenvs\golden_build-6-JWb2q3-py3.11\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 579, in code_to_exec
    exec(code, module.__dict__)
  File "C:\TestingBot\GB\Hybrid_11_23\chat.py", line 751, in <module>
    main()
  File "C:\TestingBot\GB\Hybrid_11_23\chat.py", line 386, in main
    init_llm_ollama(temperature=temperature)
  File "C:\Users\VilvanSS\AppData\Local\pypoetry\Cache\virtualenvs\golden_build-6-JWb2q3-py3.11\Lib\site-packages\streamlit\runtime\caching\cache_utils.py", line 219, in __call__
    return self._get_or_create_cached_value(args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\VilvanSS\AppData\Local\pypoetry\Cache\virtualenvs\golden_build-6-JWb2q3-py3.11\Lib\site-packages\streamlit\runtime\caching\cache_utils.py", line 242, in _get_or_create_cached_value
    return self._handle_cache_miss(cache, value_key, func_args, func_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\VilvanSS\AppData\Local\pypoetry\Cache\virtualenvs\golden_build-6-JWb2q3-py3.11\Lib\site-packages\streamlit\runtime\caching\cache_utils.py", line 299, in _handle_cache_miss
    computed_value = self._info.func(*func_args, **func_kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\TestingBot\GB\Hybrid_11_23\rag_functions.py", line 300, in init_llm_ollama
    Settings.llm = llm
    ^^^^^^^^^^^^
  File "C:\Users\VilvanSS\AppData\Local\pypoetry\Cache\virtualenvs\golden_build-6-JWb2q3-py3.11\Lib\site-packages\llama_index\core\settings.py", line 46, in llm      
    self._llm = resolve_llm(llm)
                ^^^^^^^^^^^^^^^^
  File "C:\Users\VilvanSS\AppData\Local\pypoetry\Cache\virtualenvs\golden_build-6-JWb2q3-py3.11\Lib\site-packages\llama_index\core\llms\utils.py", line 102, in resolve_llm
    assert isinstance(llm, LLM)
           ^^^^^^^^^^^^^^^^^^^^
AssertionError
2024-12-01 12:51:18.470 Examining the path of torch.classes raised: Tried to instantiate class '__path__._path', but it does not exist! Ensure that it is registered via torch::class_
  Stopping...

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20

Most upvoted comments

The error you’re encountering, ValueError: "CustomOllama" object has no field "headers", suggests that the CustomOllama class is likely using a library like Pydantic, which enforces strict attribute definitions. This means that attributes must be explicitly defined in the class, typically using Pydantic’s BaseModel or similar.

To resolve this issue, you should explicitly define the headers attribute in your CustomOllama class. Here’s how you can modify your class to include the headers attribute:

from pydantic import BaseModel
from typing import Dict, Any, Sequence

class CustomOllama(BaseModel):
    """Wrapper around Ollama to handle custom headers."""

    model: str
    request_timeout: float
    base_url: str
    headers: Dict[str, str] = {}

    def __init__(self, **data: Any):
        super().__init__(**data)
        self.ollama = Ollama(
            model=self.model, request_timeout=self.request_timeout, base_url=self.base_url, **data
        )

    # Rest of your methods...

In this modification:

  • The CustomOllama class inherits from BaseModel, which is a common pattern when using Pydantic.
  • The headers attribute is defined as a field with a default value of an empty dictionary.
  • The __init__ method is adjusted to use super().__init__(**data) to initialize the Pydantic model with the provided data.

This should resolve the ValueError by ensuring that headers is a recognized attribute of the CustomOllama class.

To continue talking to Dosu, mention @dosu.