Skip to content

OpenAI o1 models support 'developer' role instead of 'system' role. #2863

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

Open
dolukhanov opened this issue Apr 23, 2025 · 3 comments
Open
Assignees
Milestone

Comments

@dolukhanov
Copy link

Bug description
According to the OpenAI Guide and the Model Spec the former 'system' role' has now been replaced by the 'developer' role.

The o1 range of models reject the system role within a prompt

Environment
Java: 21
Spring AI: M7
Spring Boot: 3.4.4

Steps to reproduce

Create a Prompt containing a SystemMessage and a UserMessage using an o1 model e.g. o1-mini-2024-09-12

The call fails with:

Caused by: org.springframework.ai.retry.NonTransientAiException: 400 - {
  "error": {
    "message": "Unsupported value: 'messages[0].role' does not support 'system' with this model.",
    "type": "invalid_request_error",
    "param": "messages[0].role",
    "code": "unsupported_value"
  }

Expected behavior
A successful call to Open AI

Minimal Complete Reproducible example

@Component
public class TestOpenAI
{
    private final static Logger log = LoggerFactory.getLogger( TestOpenAI.class );

    private OpenAiChatModel openAiChatModel;

    public TestOpenAI( OpenAiChatModel openAiChatModel )
    {
        this.openAiChatModel = openAiChatModel;
    }

    @PostConstruct
    public void run()
    {
        log.info( "Running OpenAI" );

        OpenAiChatOptions options = OpenAiChatOptions.builder().model( "o1-mini-2024-09-12" ).build();

        SystemMessage systemMessage = new SystemMessage(
                "You are a helpful assistant knowledgable about AI Platforms" );

        UserMessage userMessage = new UserMessage( "Tell me about OpenAI" );

        List<Message> openAiMessages = List.of( systemMessage, userMessage );
        Prompt prompt = new Prompt( openAiMessages, options );

        ChatResponse call = openAiChatModel.call( prompt );
        Generation generation = call.getResults().get( 0 );

        System.out.println( generation.getOutput().getText() );

    }
}
@dolukhanov
Copy link
Author

Pull request added.

@markpollack
Copy link
Member

The PR adds a new message type, but doesn't solve the ease of use problem in sending this new message type for openai when using chat client. needs some more thought.

@andresssantos
Copy link
Contributor

Created PR #3089

I followed @dolukhanov's implementation and tried to add support for the developer role in the ChatClient to help deliver this in time.

@markpollack @ilayaperumalg There might be something I missed, so please review and let me know if any adjustments are needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants