报错 - llama-index pydantic error | arbitrary_types_allowed | PydanticUserError

国庆节前使用 LiteLLMEmbedding 设置 llama-index Settings.embed_model 还好好的,回来后,就就报错,试着降级 llama-index 也无用;设置 Settings.llm 也是好好地。

解决方法:conda 重新创建环境后,在安装 llama-index 就好了

具体原因还没找到


我的报错信息如下:

1008

shell 复制代码
 As of langchain-core 0.3.0, LangChain uses pydantic v2 internally. The langchain_core.pydantic_v1 module was a compatibility shim for pydantic v1, and should no longer be used. Please update the code to import from Pydantic directly.

For example, replace imports like: `from langchain_core.pydantic_v1 import BaseModel`
with: `from pydantic import BaseModel`
or the v1 compatibility namespace if you are working in a code base that has not been fully upgraded to pydantic 2 yet. 	from pydantic.v1 import BaseModel

  from langchain.agents.agent import (
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/llama_index/core/settings.py", line 74, in embed_model
    self._embed_model = resolve_embed_model(embed_model)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/llama_index/core/embeddings/utils.py", line 39, in resolve_embed_model
    from llama_index.core.bridge.langchain import Embeddings as LCEmbeddings
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/llama_index/core/bridge/langchain.py", line 2, in <module>
    from langchain.agents import (
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/langchain/agents/__init__.py", line 40, in <module>
    from langchain.agents.agent import (
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/langchain/agents/agent.py", line 639, in <module>
    class LLMSingleActionAgent(BaseSingleActionAgent):
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/v1/main.py", line 197, in __new__
    fields[ann_name] = ModelField.infer(
                       ^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/v1/fields.py", line 504, in infer
    return cls(
           ^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/v1/fields.py", line 434, in __init__
    self.prepare()
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/v1/fields.py", line 555, in prepare
    self.populate_validators()
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/v1/fields.py", line 829, in populate_validators
    *(get_validators() if get_validators else list(find_validators(self.type_, self.model_config))),
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/v1/validators.py", line 765, in find_validators
    raise RuntimeError(f'no validator found for {type_}, see `arbitrary_types_allowed` in Config')
RuntimeError: no validator found for <class 'langchain.chains.llm.LLMChain'>, see `arbitrary_types_allowed` in Config

升级 langchain 从 0.2 到 0.3 后,依然报错

shell 复制代码
/Users/xx/miniconda3/lib/python3.11/site-packages/langchain/chains/api/base.py:56: LangChainDeprecationWarning: As of langchain-core 0.3.0, LangChain uses pydantic v2 internally. The langchain_core.pydantic_v1 module was a compatibility shim for pydantic v1, and should no longer be used. Please update the code to import from Pydantic directly.

For example, replace imports like: `from langchain_core.pydantic_v1 import BaseModel`
with: `from pydantic import BaseModel`
or the v1 compatibility namespace if you are working in a code base that has not been fully upgraded to pydantic 2 yet. 	from pydantic.v1 import BaseModel

  from langchain_community.utilities.requests import TextRequestsWrapper
/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/_internal/_config.py:341: UserWarning: Valid config keys have changed in V2:
* 'allow_population_by_field_name' has been renamed to 'populate_by_name'
  warnings.warn(message, UserWarning)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/llama_index/core/settings.py", line 74, in embed_model
    self._embed_model = resolve_embed_model(embed_model)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/llama_index/core/embeddings/utils.py", line 39, in resolve_embed_model
    from llama_index.core.bridge.langchain import Embeddings as LCEmbeddings
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/llama_index/core/bridge/langchain.py", line 66, in <module>
    from langchain_community.chat_models import (
  File "<frozen importlib._bootstrap>", line 1229, in _handle_fromlist
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/langchain_community/chat_models/__init__.py", line 301, in __getattr__
    module = importlib.import_module(_module_lookup[name])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/langchain_community/chat_models/anyscale.py", line 31, in <module>
    class ChatAnyscale(ChatOpenAI):
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 224, in __new__
    complete_model_class(
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 577, in complete_model_class
    schema = cls.__get_pydantic_core_schema__(cls, handler)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/main.py", line 671, in __get_pydantic_core_schema__
    return handler(source)
           ^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/_internal/_schema_generation_shared.py", line 83, in __call__
    schema = self._handler(source_type)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 655, in generate_schema
    schema = self._generate_schema_inner(obj)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 924, in _generate_schema_inner
    return self._model_schema(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 739, in _model_schema
    {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()},
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 739, in <dictcomp>
    {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()},
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 1115, in _generate_md_field_schema
    common_field = self._common_field_schema(name, field_info, decorators)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 1308, in _common_field_schema
    schema = self._apply_annotations(
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 2107, in _apply_annotations
    schema = get_inner_schema(source_type)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/_internal/_schema_generation_shared.py", line 83, in __call__
    schema = self._handler(source_type)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 2091, in inner_handler
    metadata_js_function = _extract_get_pydantic_json_schema(obj, schema)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xx/miniconda3/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 2447, in _extract_get_pydantic_json_schema
    raise PydanticUserError(
pydantic.errors.PydanticUserError: The `__modify_schema__` method is not supported in Pydantic v2. Use `__get_pydantic_json_schema__` instead in class `SecretStr`.

For further information visit https://errors.pydantic.dev/2.9/u/custom-json-schema

2024-10-08(二)

相关推荐
AI小白龙*5 小时前
AI工业大模型报告:体系架构、关键技术与典型应用
人工智能·语言模型·程序员·架构·llm·大语言模型·ai大模型
知来者逆10 小时前
探索大规模语言模型(LLM)在心理健康护理领域中的应用与潜力
人工智能·gpt·深度学习·神经网络·自然语言处理·chatgpt·llm
冻感糕人~1 天前
大模型研究报告 | 2024年中国金融大模型产业发展洞察报告|附34页PDF文件下载
人工智能·程序人生·金融·llm·大语言模型·ai大模型·大模型研究报告
python_知世1 天前
2024年中国金融大模型产业发展洞察报告(附完整PDF下载)
人工智能·自然语言处理·金融·llm·计算机技术·大模型微调·大模型研究报告
致Great2 天前
Invar-RAG:基于不变性对齐的LLM检索方法提升生成质量
人工智能·大模型·rag
火山引擎边缘云2 天前
创新实践:基于边缘智能+扣子的智能轮椅 AIoT 解决方案
人工智能·llm·边缘计算
Baihai_IDP2 天前
「混合专家模型」可视化指南:A Visual Guide to MoE
人工智能·llm·aigc
Just Jump2 天前
大语言模型LLM综述
llm·大语言模型
水中加点糖3 天前
使用Spring AI中的RAG技术,实现私有业务领域的大模型系统
人工智能·function call·向量数据库·rag·springai·私有大模型·embedding模型
数据智能老司机3 天前
LLM工程师手册——RAG 推理管道
人工智能·llm·aiops