我安装了以下软件包
langchain_core==0.2.39
langchain==0.2.16
langchain-community==0.2.16
langchain_groq==0.1.10
langchain_openai==0.1.24
fastapi==0.114.2
redis
pyyaml
但是,当我尝试
from langchain_groq import ChatGroq
我有错误
PydanticUserError Traceback (most recent call last)
Cell In[20], line 70
64 #print(pm)
65
66
68 import os
---> 70 from langchain_groq import ChatGroq
File /opt/anaconda3/envs/my_env/lib/python3.12/site-packages/langchain_groq/__init__.py:1
----> 1 from langchain_groq.chat_models import ChatGroq
3 __all__ = ["ChatGroq"]
File /opt/anaconda3/envs/my_env/lib/python3.12/site-packages/langchain_groq/chat_models.py:87
80 from langchain_core.utils.function_calling import (
81 convert_to_openai_function,
82 convert_to_openai_tool,
83 )
84 from langchain_core.utils.pydantic import is_basemodel_subclass
---> 87 class ChatGroq(BaseChatModel):
88 """`Groq` Chat large language models API.
89
90 To use, you should have the
(...)
296 'logprobs': None}
...
2454 if hasattr(tp, '__origin__') and not is_annotated(tp):
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
请指教。
该问题是由fastapi版本引起的。抱歉,我还没有把完整的代码放出来。但显然 fastapi 版本不支持 Pydantic v2,这会导致尝试导入 Groq 时出现问题。所以升级到fastapi 0.115.0后,一切正常。