mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
fix(chatgpt): normalize string responses input
This commit is contained in:
parent
2dac54b732
commit
bcde4729f8
2 changed files with 31 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue