在StreamLit上部署(和托管)LangChain代码会引发PydanticUserError。

huangapple go评论126阅读模式
英文:

Deploying (and hosting) a LangChain code on StreamLit throws PydanticUserError

问题

我使用LangChain、OpenAI(嵌入和LLM)以及Chroma(用于存储向量嵌入)构建了一个PDF文档问答系统,并使用StreamLit创建了用户界面(UI)。我尝试使用StreamLit云服务部署和托管Web应用程序。在安装所有必需的库和软件包后,Web应用程序抛出了以下错误:

PydanticUserError: 如果您使用`@root_validator`并且pre=False(默认设置),则必须指定`skip_on_failure=True`。请注意,`@root_validator`已弃用,应替换为`@model_validator`。有关更多信息,请访问https://errors.pydantic.dev/2.0.2/u/root-validator-pre-skip

随后是一个Traceback(回溯):

Traceback:
    File "/opt/render/project/src/.venv/lib/python3.7/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
    exec(code, module.__dict__)
File "/opt/render/project/src/app.py", line 3, in <module>
    from langchain.document_loaders import PyMuPDFLoader, PyPDFLoader
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/__init__.py", line 8, in <module>
    from langchain.agents import MRKLChain, ReActChain, SelfAskWithSearchChain
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/agents/__init__.py", line 2, in <module>
    from langchain.agents.agent import Agent
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/agents/agent.py", line 10, in <module>
    from langchain.chains.base import Chain
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/chains/__init__.py", line 2, in <module>
    from langchain.chains.conversation.base import ConversationChain
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/chains/conversation/base.py", line 7, in <module>
    from langchain.chains.conversation.memory import ConversationBufferMemory
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/chains/conversation/memory.py", line 7, in <module>
    from langchain.chains.conversation.prompt import SUMMARY_PROMPT
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/chains/conversation/prompt.py", line 2, in <module>
    from langchain.prompts.prompt import PromptTemplate
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/prompts/__init__.py", line 2, in <module>
    from langchain.prompts.base import BasePromptTemplate
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/prompts/base.py", line 35, in <module>
    class BasePromptTemplate(BaseModel, ABC):
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/prompts/base.py", line 41, in BasePromptTemplate
    @root_validator()
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/pydantic/deprecated/class_validators.py", line 231, in root_validator
    code='root-validator-pre-skip',

如何处理这个错误,尽管我相信我已安装了所有必要的库和兼容版本?

我尝试查看错误显示的URL,但找不到足够好的内容来调试错误。

英文:

I built a pdf document question-answering using LangChain, OpenAI (embeddings and LLM) and Chroma (for storing the vector embeddings) and UI with StreamLit. I am trying to deploy and host the webapp using StreamLit cloud services. And on installing all the required libraries and packages, the webapp throws an error:

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`. For further information visit https://errors.pydantic.dev/2.0.2/u/root-validator-pre-skip

followed by a Traceback:

Traceback:
    File &quot;/opt/render/project/src/.venv/lib/python3.7/site-packages/streamlit/runtime/scriptrunner/script_runner.py&quot;, line 552, in _run_script
    exec(code, module.__dict__)
File &quot;/opt/render/project/src/app.py&quot;, line 3, in &lt;module&gt;
    from langchain.document_loaders import PyMuPDFLoader, PyPDFLoader
File &quot;/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/__init__.py&quot;, line 8, in &lt;module&gt;
    from langchain.agents import MRKLChain, ReActChain, SelfAskWithSearchChain
File &quot;/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/agents/__init__.py&quot;, line 2, in &lt;module&gt;
    from langchain.agents.agent import Agent
File &quot;/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/agents/agent.py&quot;, line 10, in &lt;module&gt;
    from langchain.chains.base import Chain
File &quot;/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/chains/__init__.py&quot;, line 2, in &lt;module&gt;
    from langchain.chains.conversation.base import ConversationChain
File &quot;/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/chains/conversation/base.py&quot;, line 7, in &lt;module&gt;
    from langchain.chains.conversation.memory import ConversationBufferMemory
File &quot;/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/chains/conversation/memory.py&quot;, line 7, in &lt;module&gt;
    from langchain.chains.conversation.prompt import SUMMARY_PROMPT
File &quot;/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/chains/conversation/prompt.py&quot;, line 2, in &lt;module&gt;
    from langchain.prompts.prompt import PromptTemplate
File &quot;/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/prompts/__init__.py&quot;, line 2, in &lt;module&gt;
    from langchain.prompts.base import BasePromptTemplate
File &quot;/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/prompts/base.py&quot;, line 35, in &lt;module&gt;
    class BasePromptTemplate(BaseModel, ABC):
File &quot;/opt/render/project/src/.venv/lib/python3.7/site-packages/langchain/prompts/base.py&quot;, line 41, in BasePromptTemplate
    @root_validator()
File &quot;/opt/render/project/src/.venv/lib/python3.7/site-packages/pydantic/deprecated/class_validators.py&quot;, line 231, in root_validator
    code=&#39;root-validator-pre-skip&#39;,

How to deal with this error, although I believe I have installed all the necessary packages with compatible versions?

I am trying to see the url that the error shows but could not find anything good enough to debug the error.

答案1

得分: 1

尝试这个:

pip install ydata-profiling
英文:

Try this:

pip install ydata-profiling

答案2

得分: 0

我一直在阅读这个帖子并尝试不同版本的langchain和pydantic。在Pydantic 1.10.9和Langchain 0.0.231上仍然失败。

链接:https://stackoverflow.com/questions/76614379/roo-validator-error-when-importing-langchain-text-splitter-python

英文:

I have been reading this thread and trying different versions of langchain an pydantic. Still failing with Pydantic 1.10.9 and Langchain 0.0.231.

https://stackoverflow.com/questions/76614379/roo-validator-error-when-importing-langchain-text-splitter-python

huangapple
  • 本文由 发表于 2023年7月10日 14:54:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76651314.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定