langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
93.57k stars 15.08k forks source link

It Seems There's a Compatibility Issue with Pydantic v2.0: FieldInfo object has no attribute 'required' #24427

Closed sharrajesh closed 2 months ago

sharrajesh commented 2 months ago

Checked other resources

Example Code

my code is proprietary

Error Message and Stack Trace (if applicable)

Traceback (most recent call last): File "/home/username/.pycharm_helpers/pydev/pydevd.py", line 1551, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "/home/username/.pycharm_helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/home/username/code/ai/myproject/examples/llm_rule_translation_and_creation.py", line 20, in sigma_agent_executor = create_sigma_agent(sigma_vectorstore=sigma_llm.sigmadb) File "/home/username/code/ai/myproject/myproject/llm/toolkits/base.py", line 63, in create_sigma_agent llm_with_tools = agent_llm.bind(functions=[convert_to_openai_function(t) for t in tools]) File "/home/username/code/ai/myproject/myproject/llm/toolkits/base.py", line 63, in llm_with_tools = agent_llm.bind(functions=[convert_to_openai_function(t) for t in tools]) File "/home/username/.cache/pypoetry/virtualenvs/myproject-ItWCGl7B-py3.10/lib/python3.10/site-packages/langchain_core/utils/function_calling.py", line 278, in convert_to_openai_function return cast(Dict, format_tool_to_openai_function(function)) File "/home/username/.cache/pypoetry/virtualenvs/myproject-ItWCGl7B-py3.10/lib/python3.10/site-packages/langchain_core/_api/deprecation.py", line 168, in warning_emitting_wrapper return wrapped(*args, **kwargs) File "/home/username/.cache/pypoetry/virtualenvs/myproject-ItWCGl7B-py3.10/lib/python3.10/site-packages/langchain_core/utils/function_calling.py", line 199, in format_tool_to_openai_function if tool.tool_call_schema: File "/home/username/.cache/pypoetry/virtualenvs/myproject-ItWCGl7B-py3.10/lib/python3.10/site-packages/langchain_core/tools.py", line 428, in tool_call_schema return _create_subset_model( File "/home/username/.cache/pypoetry/virtualenvs/myproject-ItWCGl7B-py3.10/lib/python3.10/site-packages/langchain_core/tools.py", line 129, in _create_subset_model if field.required and not field.allow_none AttributeError: 'FieldInfo' object has no attribute 'required'. Did you mean: 'is_required'?

Description

I started seeing an AttributeError after upgrading to Pydantic v2.0 while using the latest version of LangChain. The error message is:

csharp Copy code AttributeError: 'FieldInfo' object has no attribute 'required'. Did you mean: 'is_required'? This issue seems related to the recent Pydantic upgrade. See the trace for more information. Downgrading Pydantic resolves the issue.

System Info

LangChain Version: Latest Pydantic Version: 2.20.1 Python Version: 3.10.12 Operating System: Windows with WSL Ubuntu poetry

yeaung276 commented 2 months ago

I got it working by using "langchain-core==0.2.20"

sharrajesh commented 2 months ago

thank you; your suggestion works; it seems something broke in langchain-core 0.2.21

eyurtsev commented 2 months ago

@sharrajesh could you include a minimal reproducible example. We won't be able to help otherwise. You don't need to include any proprietary code.

eyurtsev commented 2 months ago

Also please include the output of: python -m langchain_core.sys_info

eyurtsev commented 2 months ago

This issue will likely have been fixed in the next release of langchain-core (can't tell for sure since there's no reproduction code)

sharrajesh commented 2 months ago

I will give a try and update here.

sharrajesh commented 2 months ago

Confirmed problem has been fixed by latest langchain-core. Thank you langchain team!