LLukas22 / llm-rs-python

Unofficial python bindings for the rust llm library. 🐍❤️🦀
MIT License
71 stars 4 forks source link

Deprecated Usage of `@root_validator` Causing Error #29

Closed andri-jpg closed 12 months ago

andri-jpg commented 12 months ago

full trace : Uncaught app exception Traceback (most recent call last): File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script exec(code, module.dict) File "/mount/src/chatkobi.ai/main.py", line 4, in from load_model import Chainer File "/mount/src/chatkobi.ai/load_model.py", line 2, in from llm_rs.langchain import RustformersLLM File "/home/adminuser/venv/lib/python3.9/site-packages/llm_rs/langchain/init.py", line 1, in from .langchain import RustformersLLM File "/home/adminuser/venv/lib/python3.9/site-packages/llm_rs/langchain/langchain.py", line 18, in class RustformersLLM(LLM,Embeddings): File "/home/adminuser/venv/lib/python3.9/site-packages/llm_rs/langchain/langchain.py", line 74, in RustformersLLM @root_validator() File "/home/adminuser/venv/lib/python3.9/site-packages/pydantic/deprecated/class_validators.py", line 228, in root_validator raise PydanticUserError( pydantic.errors.PydanticUserError: If you use @root_validator with pre=False (the default) you MUST specify skip_on_failure=True. Note that @root_validator is deprecated and should be replaced with @model_validator.

Description

When attempting to use the llm-rs[langchain] library with pydantic v2, an uncaught app exception is occurring. This is due to the usage of the deprecated @root_validator method without specifying skip_on_failure=True in the llm_rs/langchain/langchain.py file. As a result, the error is raised as mentioned in the full trace.

Steps to Reproduce:

  1. Install the llm-rs library with the following command: This will automatically install latest version of pydantic.

    pip install llm-rs[langchain]
  2. Attempt to use the library in a script or application.

Expected Behavior:

The library should work without raising any errors related to the deprecated @root_validator usage.

Actual Behavior:

An uncaught app exception occurs due to the deprecated @root_validator usage.

Tested Fix:

Add the following import to line 12 in llm_rs/langchain/langchain.py:

# line 12 on llm_rs/langchain/langchain.py
from pydantic.v1 import root_validator

Summary:

The issue is primarily caused by the deprecated usage of @root_validator without specifying skip_on_failure=True. This error occurs when pydantic v2 is installed automatically as a dependency of the llm-rs[langchain] library.

LLukas22 commented 12 months ago

I guess, langchain updated to pydantic v2 and i didn't pin the version. Can you PR up this fix?

andri-jpg commented 12 months ago

I guess, langchain updated to pydantic v2 and i didn't pin the version. Can you PR up this fix?

Sure.