Skip to content
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

Unsuported role system for openai-o1-mini #974

Open
AlexEnrique opened this issue Feb 23, 2025 · 10 comments
Open

Unsuported role system for openai-o1-mini #974

AlexEnrique opened this issue Feb 23, 2025 · 10 comments
Assignees

Comments

@AlexEnrique
Copy link

Got an error while using this:

await Agent(OPENAI_O1_MINI, system_prompt='you are a helpful assistant').run('hi')

Error from the model

BadRequestError: Error code: 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'}}

Looking at the docs of OpenAI, I saw that system prompts were replaced by developer prompts
(see https://platform.openai.com/docs/api-reference/chat/create)

@Kludex
Copy link
Member

Kludex commented Feb 23, 2025

Which openai version are you running? pip show openai

@AlexEnrique
Copy link
Author

Sorry for not providing on the first message.

Tested with openai versions 1.62.0 and 1.64.0 and pydantic-ai version 0.0.24

@Kludex
Copy link
Member

Kludex commented Feb 24, 2025

Can you please share a MRE?

@AlexEnrique
Copy link
Author

MRE

import os

from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIModel

model = OpenAIModel(
    model_name='o1-mini',
    api_key=os.getenv('OPENAI_API_KEY'),
)


agent = Agent(
    model=model,
    system_prompt='You are a helpful assistant.',
)

agent.run_sync('Hi')

@Kludex
Copy link
Member

Kludex commented Feb 24, 2025

It seems that with:

from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIModel

model = OpenAIModel('o1-mini') # , system_prompt_role='developer')
agent = Agent(model=model, system_prompt='You are a helpful assistant.')

print(agent.run_sync('Hi'))

I have:

openai.BadRequestError: Error code: 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'}}

And... If I use the system_prompt_role:

from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIModel

model = OpenAIModel('o1-mini', system_prompt_role='developer')
agent = Agent(model=model, system_prompt='You are a helpful assistant.')

print(agent.run_sync('Hi'))

I have this error instead:

openai.BadRequestError: Error code: 400 - {'error': {'message': "Unsupported value: 'messages[0].role' does not support 'developer' with this model.", 'type': 'invalid_request_error', 'param': 'messages[0].role', 'code': 'unsupported_value'}}

So... 🤷‍♂

I've read on their docs that it's recommended to use o3-mini instead, which works as expected:

from pydantic_ai import Agent

agent = Agent(model='openai:o3-mini', system_prompt='You are a helpful assistant.')

print(agent.run_sync('Hi'))

@Kludex
Copy link
Member

Kludex commented Feb 24, 2025

For what I've found in other forums, it just seems that o1-mini and similar don't support the system role.

@Kludex
Copy link
Member

Kludex commented Feb 24, 2025

Anyway, since we have the parameter system_prompt_role, I'll be closing this issue.

The problem here is that the model doesn't support either developer or system role.

@Kludex Kludex closed this as completed Feb 24, 2025
@Kludex
Copy link
Member

Kludex commented Feb 24, 2025

You can use the user in system_prompt_role.

@drdavella
Copy link

@Kludex this seems like a reasonable workaround, but shouldn't it be possible to automatically set the system_prompt_role based on the known model name string so that users do not have to do it explicitly?

@Kludex Kludex reopened this Feb 24, 2025
@Kludex
Copy link
Member

Kludex commented Feb 24, 2025

I think it's a valid point. 👍

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

3 participants