国庆节前使用 LiteLLMEmbedding 设置 llama-index Settings.embed_model
还好好的,回来后,就就报错,试着降级 llama-index 也无用;设置 Settings.llm
也是好好地。
解决方法:conda 重新创建环境后,在安装 llama-index 就好了
具体原因还没找到
我的报错信息如下:
1008
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 "" , 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 后,依然报错
/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 "" , 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 "" , 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(二)