mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
fix(chatgpt): normalize Responses string input
This commit is contained in:
parent
4d7144160a
commit
50daae5b81
1 changed files with 24 additions and 0 deletions
|
|
@ -38,6 +38,27 @@ class ChatGPTResponsesAPIConfig(OpenAIResponsesAPIConfig):
|
|||
def custom_llm_provider(self) -> LlmProviders:
|
||||
return LlmProviders.CHATGPT
|
||||
|
||||
@staticmethod
|
||||
def _normalized_responses_input(
|
||||
request_input: str | list[Any], # mutable-ok: outbound Responses payload is a JSON list by spec
|
||||
) -> list[Any]: # mutable-ok: same — the ChatGPT backend requires the message-list form
|
||||
"""Return the ChatGPT-compatible form of a Responses API ``input`` value.
|
||||
|
||||
The public Responses API accepts the string shorthand; the ChatGPT OAuth
|
||||
backend requires the message-list form. Non-string values are returned
|
||||
unchanged.
|
||||
"""
|
||||
if isinstance(request_input, str):
|
||||
return [ # mutable-ok: ChatGPT backend requires a JSON message list
|
||||
{ # mutable-ok: message payload is inherently a JSON object
|
||||
"role": "user",
|
||||
"content": [ # mutable-ok: ditto
|
||||
{"type": "input_text", "text": request_input}, # mutable-ok: ditto
|
||||
],
|
||||
}
|
||||
]
|
||||
return request_input
|
||||
|
||||
def validate_environment(
|
||||
self,
|
||||
headers: dict,
|
||||
|
|
@ -73,6 +94,9 @@ class ChatGPTResponsesAPIConfig(OpenAIResponsesAPIConfig):
|
|||
litellm_params,
|
||||
headers,
|
||||
)
|
||||
request["input"] = self._normalized_responses_input(
|
||||
request_input=request.get("input", []),
|
||||
)
|
||||
base_instructions: Final = get_chatgpt_default_instructions()
|
||||
existing_instructions: Final = request.get("instructions")
|
||||
if existing_instructions:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue