Open adubovik opened 1 month ago
Hello, I've tested your code and confirmed that certain fields are being ignored when converting between a dictionary and a message. I agree with you that this undermines forwards compatibility with future versions of OpenAI's API.
I'm a member of a group at University of Toronto and we're going to take a look at this issue and hopefully have a working pull request soon.
I've created a pull request with a fix for this issue.
While working on this issue, our group was wondering whether the new feature could accidentally break backwards compatibility in certain use cases (e.g. converting a dict where they want the extra fields to be ignored).
If anyone thinks this pull request might break their older code, our group would like to discuss this and see if there's another solution.
A group member also mentioned the possibility that allowing users to include extra fields may be against LangChain's goal, since it allows users to invoke messages that always result in errors. I haven't been using LangChain for long, so I'm not sure if that might be a consideration.
Checked other resources
Example Code
requirements.txt:
test.py:
Error Message and Stack Trace (if applicable)
No response
Description
The core of the problem is that OpenAI adapter ignores additional fields in request messages and response messages. It happens in convert* family of methods where only a certain subset of fields from the input type is being converted.
There are two implications of this:
langchain_openai
library with future versions of OpenAI API is undermined. Let's suppose OpenAI introduces a new field to the responseassistant
message, e.g. one which reflects thought process in the latest GPT-4 o1. Thelangchain_openai
users will have to wait for the library to pick up with the changed in the API and then migrate their apps to the new version of the library. Same goes about the request messages. Curiously, the forward compatibility is supported for the top-level request parameters, which could be provided viaextra_body
parameter inChatOpenAI
.Note that the
openai
library itself is designed to be forward compatible. The additional fields undeclared in the request and response schemas are passed through unperturbed. The request types are defined viaTypedDict
and the response one as pydanticBaseModel
with extra fields allowed.It would be great to achieve the same in
langchain_openai
as well.System Info