langchain icon indicating copy to clipboard operation
langchain copied to clipboard

o1-mini and o1 is not supported yet?

Open mutonby opened this issue 1 year ago • 8 comments

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

mutonby avatar Dec 23 '24 23:12 mutonby

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.

gongzhang avatar Dec 26 '24 02:12 gongzhang

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?

aubford avatar Feb 01 '25 22:02 aubford

You can use the developer role like this:

SystemMessage(
    content=developer_prompt, additional_kwargs={"__openai_role__": "developer"}
)

dalmia avatar Feb 03 '25 08:02 dalmia

@dalmia Thanks! this is just what i need to!

m4a1carbin4 avatar Feb 04 '25 10:02 m4a1carbin4

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.

tonyvperez avatar Feb 05 '25 03:02 tonyvperez

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.

logancyang avatar Feb 08 '25 00:02 logancyang

Unsupported value: 'messages[3].role' does not support 'function' with this model.

nav-dev-2000 avatar Feb 11 '25 10:02 nav-dev-2000

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)

fcamblor avatar Feb 17 '25 10:02 fcamblor

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!

sydney-runkle avatar Apr 17 '25 21:04 sydney-runkle