mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-10 08:28:25 +00:00
fix(chatgpt): an in-sequence system message reaches Codex as role=developer
The Codex backend answers 400 {"detail":"System messages are not allowed"} to any
role=system input item, which is what the /v1/messages adapter makes of a mid-turn
system message. role=developer is accepted.
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
parent
93b79d2587
commit
e53ce7a30e
2 changed files with 19 additions and 0 deletions
|
|
@ -90,6 +90,13 @@ class ChatGPTResponsesAPIConfig(OpenAIResponsesAPIConfig):
|
|||
request["instructions"] = f"{base_instructions}\n\n{existing_instructions}"
|
||||
else:
|
||||
request["instructions"] = base_instructions
|
||||
# The Codex backend rejects role=system input items ("System messages are not allowed")
|
||||
# but accepts role=developer, which is what an in-sequence system message means there.
|
||||
if isinstance(request.get("input"), list):
|
||||
request["input"] = [
|
||||
{**item, "role": "developer"} if isinstance(item, dict) and item.get("role") == "system" else item
|
||||
for item in request["input"]
|
||||
]
|
||||
request["store"] = False
|
||||
request["stream"] = True
|
||||
include: Final = list(request.get("include") or [])
|
||||
|
|
|
|||
|
|
@ -71,6 +71,18 @@ class TestChatGPTResponsesAPITransformation:
|
|||
|
||||
assert "service_tier" not in request
|
||||
|
||||
def test_system_input_items_become_developer(self):
|
||||
system_item = {"type": "message", "role": "system", "content": [{"type": "input_text", "text": "be brief"}]}
|
||||
user_item = {"type": "message", "role": "user", "content": [{"type": "input_text", "text": "hi"}]}
|
||||
request = ChatGPTResponsesAPIConfig().transform_responses_api_request(
|
||||
model="gpt-6.1-sol",
|
||||
input=[user_item, system_item],
|
||||
response_api_optional_request_params={},
|
||||
litellm_params=GenericLiteLLMParams(),
|
||||
headers={},
|
||||
)
|
||||
assert request["input"] == [user_item, {**system_item, "role": "developer"}]
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"model_name",
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue