Skip to content

Commit 4cd2603

Browse files
authored
Add test to document OpenAI o1-mini behavior on system role (#977)
1 parent d2255e7 commit 4cd2603

File tree

4 files changed

+140
-1
lines changed

4 files changed

+140
-1
lines changed

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,8 @@ def vcr_config():
197197
'filter_headers': ['authorization', 'x-api-key'],
198198
'decode_compressed_response': True,
199199
}
200+
201+
202+
@pytest.fixture(scope='session')
203+
def openai_key() -> str:
204+
return os.getenv('OPENAI_API_KEY', 'mock-api-key')
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
interactions:
2+
- request:
3+
headers:
4+
accept:
5+
- application/json
6+
accept-encoding:
7+
- gzip, deflate
8+
connection:
9+
- keep-alive
10+
content-length:
11+
- '149'
12+
content-type:
13+
- application/json
14+
cookie:
15+
- __cf_bm=k1xoKY2.Jtgshh4aAfJbgzfCta3eg2_pKpOubx52AqY-1740396355-1.0.1.1-piAnJhOpL2bGY4paQ8VURT3k0nvStOyXvtsja2kOYPgRmSNpE1vUf87UU.AnB_di_8lc63rtIkZjSJSSZPPgDQ;
16+
_cfuvid=9Q7wbAVWuVxqmo8CZYy4FZvphfjrBGzqwRIt0TKETsE-1740396355005-0.0.1.1-604800000
17+
host:
18+
- api.openai.com
19+
method: POST
20+
parsed_body:
21+
messages:
22+
- content: You are a helpful assistant.
23+
role: developer
24+
- content: Hello
25+
role: user
26+
model: o1-mini
27+
n: 1
28+
stream: false
29+
uri: https://api.openai.com/v1/chat/completions
30+
response:
31+
headers:
32+
access-control-expose-headers:
33+
- X-Request-ID
34+
alt-svc:
35+
- h3=":443"; ma=86400
36+
connection:
37+
- keep-alive
38+
content-length:
39+
- '224'
40+
content-type:
41+
- application/json
42+
openai-organization:
43+
- pydantic-28gund
44+
openai-processing-ms:
45+
- '23'
46+
openai-version:
47+
- '2020-10-01'
48+
strict-transport-security:
49+
- max-age=31536000; includeSubDomains; preload
50+
parsed_body:
51+
error:
52+
code: unsupported_value
53+
message: 'Unsupported value: ''messages[0].role'' does not support ''developer'' with this model.'
54+
param: messages[0].role
55+
type: invalid_request_error
56+
status:
57+
code: 400
58+
message: Bad Request
59+
version: 1
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
interactions:
2+
- request:
3+
headers:
4+
accept:
5+
- application/json
6+
accept-encoding:
7+
- gzip, deflate
8+
connection:
9+
- keep-alive
10+
content-length:
11+
- '146'
12+
content-type:
13+
- application/json
14+
host:
15+
- api.openai.com
16+
method: POST
17+
parsed_body:
18+
messages:
19+
- content: You are a helpful assistant.
20+
role: system
21+
- content: Hello
22+
role: user
23+
model: o1-mini
24+
n: 1
25+
stream: false
26+
uri: https://api.openai.com/v1/chat/completions
27+
response:
28+
headers:
29+
access-control-expose-headers:
30+
- X-Request-ID
31+
alt-svc:
32+
- h3=":443"; ma=86400
33+
connection:
34+
- keep-alive
35+
content-length:
36+
- '221'
37+
content-type:
38+
- application/json
39+
openai-organization:
40+
- pydantic-28gund
41+
openai-processing-ms:
42+
- '15'
43+
openai-version:
44+
- '2020-10-01'
45+
set-cookie:
46+
- __cf_bm=k1xoKY2.Jtgshh4aAfJbgzfCta3eg2_pKpOubx52AqY-1740396355-1.0.1.1-piAnJhOpL2bGY4paQ8VURT3k0nvStOyXvtsja2kOYPgRmSNpE1vUf87UU.AnB_di_8lc63rtIkZjSJSSZPPgDQ;
47+
path=/; expires=Mon, 24-Feb-25 11:55:55 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
48+
- _cfuvid=9Q7wbAVWuVxqmo8CZYy4FZvphfjrBGzqwRIt0TKETsE-1740396355005-0.0.1.1-604800000; path=/; domain=.api.openai.com;
49+
HttpOnly; Secure; SameSite=None
50+
strict-transport-security:
51+
- max-age=31536000; includeSubDomains; preload
52+
parsed_body:
53+
error:
54+
code: unsupported_value
55+
message: 'Unsupported value: ''messages[0].role'' does not support ''system'' with this model.'
56+
param: messages[0].role
57+
type: invalid_request_error
58+
status:
59+
code: 400
60+
message: Bad Request
61+
version: 1

tests/models/test_openai.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from .mock_async_stream import MockAsyncStream
3030

3131
with try_import() as imports_successful:
32-
from openai import NOT_GIVEN, AsyncOpenAI, OpenAIError
32+
from openai import NOT_GIVEN, AsyncOpenAI, BadRequestError, OpenAIError
3333
from openai.types import chat
3434
from openai.types.chat.chat_completion import Choice
3535
from openai.types.chat.chat_completion_chunk import (
@@ -560,6 +560,20 @@ async def test_system_prompt_role(
560560
]
561561

562562

563+
@pytest.mark.parametrize('system_prompt_role', ['system', 'developer'])
564+
@pytest.mark.vcr
565+
async def test_openai_o1_mini_system_role(
566+
allow_model_requests: None,
567+
system_prompt_role: Literal['system', 'developer'],
568+
openai_key: str,
569+
) -> None:
570+
model = OpenAIModel('o1-mini', api_key=openai_key, system_prompt_role=system_prompt_role)
571+
agent = Agent(model=model, system_prompt='You are a helpful assistant.')
572+
573+
with pytest.raises(BadRequestError, match=r".*Unsupported value: 'messages\[0\]\.role' does not support.*"):
574+
await agent.run('Hello')
575+
576+
563577
@pytest.mark.parametrize('parallel_tool_calls', [True, False])
564578
async def test_parallel_tool_calls(allow_model_requests: None, parallel_tool_calls: bool) -> None:
565579
c = completion_message(

0 commit comments

Comments
 (0)