一、python环境
python 11
二、运行如下代码报错
from langchain_openai import ChatOpenAI
import os
# 加载 .env 到环境变量
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
llm = ChatOpenAI(model="gpt-3.5-turbo") # 默认是gpt-3.5-turbo
response = llm.invoke("你是谁")
print(response.content)
第一次报错信息:
pydantic.errors.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.6/u/root-validator-pre-skip
第一次修改:
pip3 install pydantic==1.10.13
第二次报错:
File "D:\Python311\Lib\site-packages\langchain_core\globals.py", line 72, in get_verbose
old_verbose = langchain.verbose
^^^^^^^^^^^^^^^^^
AttributeError: module 'langchain' has no attribute 'verbose'
第二次修改解决:
pip3 install --upgrade --force-reinstall --no-deps --no-cache-dir langchain