fix(chatgpt): normalize string responses input

This commit is contained in:
afoninsky 2026-04-08 22:41:24 +02:00
parent 2dac54b732
commit bcde4729f8
No known key found for this signature in database
GPG key ID: 79690EED417BC43E
2 changed files with 31 additions and 0 deletions

View file

@ -73,6 +73,7 @@ class ChatGPTResponsesAPIConfig(OpenAIResponsesAPIConfig):
litellm_params,
headers,
)
request["input"] = self._normalize_chatgpt_input(request.get("input"))
base_instructions = get_chatgpt_default_instructions()
existing_instructions = request.get("instructions")
if existing_instructions:
@ -105,6 +106,18 @@ class ChatGPTResponsesAPIConfig(OpenAIResponsesAPIConfig):
return {k: v for k, v in request.items() if k in allowed_keys}
@staticmethod
def _normalize_chatgpt_input(input_value: Any) -> Any:
if isinstance(input_value, str):
return [
{
"role": "user",
"content": [{"type": "input_text", "text": input_value}],
}
]
return input_value
def transform_response_api_response(
self,
model: str,

View file

@ -107,6 +107,24 @@ class TestChatGPTResponsesAPITransformation:
"You are Codex, based on GPT-5."
)
def test_chatgpt_normalizes_string_input_for_responses_api(self):
config = ChatGPTResponsesAPIConfig()
request = config.transform_responses_api_request(
model="chatgpt/gpt-5.4",
input="hi",
response_api_optional_request_params={},
litellm_params=GenericLiteLLMParams(),
headers={},
)
assert request["input"] == [
{
"role": "user",
"content": [{"type": "input_text", "text": "hi"}],
}
]
@pytest.mark.parametrize(
"model_name",
[