New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
convert_to_openai_function not generating properly with nested BaseModels #21270
Comments
Hi @eyurtsev, @mimichelow! Upon investigating the error, it appears that the issue lies with the import of pydantic. The nested function seems to only work correctly when imported as from langchain_core.pydantic_v1 import BaseModel, Field instead of from pydantic import Field, BaseModel. Within the convert_to_openai_function, when dealing with a standard Pydantic BaseModel, it's reaching the elif callable(function) and it calls the convert_python_function_to_openai_function(function) method part instead of the section where convert_pydantic_to_openai_function (which handles nested versions) is called. The chunk in the code: (from line 281 langchain_core/utils/function_calling.py)
Modified script:
Output:
|
Ya it also silently will drop some special keys - looking forward to upgrading to pydantic v2 in the future |
Updating the notebooks from the course on "Functions, Tools and Agents with LangChain" at DeepLearning.ai by Harrison Chase has similar issue. convert_to_openai_function(Information) {'name': 'Information', from langchain.utils.openai_functions import convert_pydantic_to_openai_function Using: solves the problem. |
Discussed in #17481
Originally posted by mimichelow February 13, 2024
Checked other resources
Commit to Help
Example Code
Description
I'm trying to migrate from the deprecated convert_pydantic_to_openai_function with the previous Pydantic class, but the new function is not going beyond the first level. The produced output is
Is this a known bug, do i have to manually produce the full schema to pass as a dictionary now? I can't find anything in how to generate the full openai function using the new function.
Thanks
System Info
System Information
The following packages were not found:
The text was updated successfully, but these errors were encountered: