报错 - 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(二)

相关推荐
zaim115 小时前
计算机的错误计算(一百八十七)
人工智能·ai·大模型·llm·错误·正弦/sin·误差/error
张拭心17 小时前
Google 提供的 Android 端上大模型组件:MediaPipe LLM 介绍
android·人工智能·llm
带电的小王17 小时前
whisper.cpp: Android端测试 -- Android端手机部署音频大模型
android·智能手机·llm·whisper·音频大模型·whisper.cpp
带电的小王21 小时前
whisper.cpp: PC端测试 -- 电脑端部署音频大模型
llm·whisper·音视频·音频大模型
Ambition_LAO1 天前
LLaMA-Factory QuickStart 流程详解
llm·llama
宇梵文书C2 天前
在CFFF云平台使用llama-factory部署及微调Qwen2.5-7B-Instruct
llm·llama·cfff
zaim12 天前
计算机的错误计算(一百八十六)
人工智能·python·ai·大模型·llm·误差·decimal
带电的小王2 天前
llama.cpp:PC端测试 MobileVLM -- 电脑端部署图生文大模型
llm·llama.cpp·vlm·mobilevlm·图生文
火山引擎边缘云3 天前
2024冬季FORCE大会,火山引擎边缘云全面展示边缘云 + AI 产品技术方案
llm·aigc·边缘计算