在一开始运行代码后报错显示
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases 根据报错内容找到/home/cloudide/.local/lib/python3.12/site-packages/langchain_community/tools/file_management/copy.py 如图所示,
from langchain_core.pydantic_v1 import BaseModel, Field
引起错误: 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 pydantic import BaseModel, Field
使得pydantic的兼容性得到提升,再次运行代码得到输出如下
完成代理,得到搜索结果并与llm结合生成最终结果。