o1-mini and o1 is not supported yet?
Checked other resources
- [X] I added a very descriptive title to this issue.
- [X] I searched the LangChain documentation with the integrated search.
- [X] I used the GitHub search to find a similar question and didn't find it.
- [X] I am sure that this is a bug in LangChain rather than my code.
- [X] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
api-1 | Error during streaming: BadRequestError: 400 Unsupported value: 'messages[0].role' does not support 'developer' with this model.
Error Message and Stack Trace (if applicable)
No response
Description
api-1 | Error during streaming: BadRequestError: 400 Unsupported value: 'messages[0].role' does not support 'developer' with this model.
System Info
nodejs
Same issue here. The developer role does not work. Seams a bug on the OpenAI side.
https://platform.openai.com/docs/guides/reasoning#advice-on-prompting
Starting with o1-2024-12-17, o1 models support developer messages rather than system messages, to align with the chain of command behavior described in the model spec.
OpenAI changed the message type "system" to "developer" for the o1 models. Seems like this should be handled/abstracted by LangChain right? Being able to swap out models without worry about these types of implementation details is a core reason we use a tool like LangChain isn't it?
You can use the developer role like this:
SystemMessage(
content=developer_prompt, additional_kwargs={"__openai_role__": "developer"}
)
@dalmia Thanks! this is just what i need to!
You can use the developer role like this:
SystemMessage( content=developer_prompt, additional_kwargs={"openai_role": "developer"} )
This didn't appear to help, as the prompt was ignored in AzureChatOpenAI causing the result to not have any context to my inquiry. So, I've been using human and assistant, which appears to work.
Anyone on the langchainjs team looking into this? Would appreciate this to be fixed asap since o-series models support "developer" role now, but we are still getting this error:
400 Unsupported value: 'messages[0].role' does not support 'developer' with this model.
Unsupported value: 'messages[3].role' does not support 'function' with this model.
Looking at langchainjs code, it seems like system is automatically replaced with developer on "reasoning models" (o1-*, o3-*) which looks unsupported in case of o1
When I manually edited node_modules/@langchain/openai/dist/chat_models.js using patch-package :
diff --git a/node_modules/@langchain/openai/dist/chat_models.js b/node_modules/@langchain/openai/dist/chat_models.js
index 0a974ac..b42b475 100644
--- a/node_modules/@langchain/openai/dist/chat_models.js
+++ b/node_modules/@langchain/openai/dist/chat_models.js
@@ -52,7 +52,7 @@ export function _convertMessagesToOpenAIParams(messages, model) {
return messages.flatMap((message) => {
let role = messageToOpenAIRole(message);
if (role === "system" && isReasoningModel(model)) {
- role = "developer";
+ role = "assistant";
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const completionParam = {
By replacing "developer" with "assistant" I made it to work (that's obviously only a temporary workaround)
This is fixed on our end - o1 supports developer messages, as do all of the more recent oX models. Unfortunately, o1-mini doesn't support system (or developer, equivalently) messages. You can block said information in with a HumanMessage, if desired.
Closing as resolved, happy to answer any follow up questions!