fix(providers): sanitize azure responses input messages

This commit is contained in:
Xubin Ren 2026-04-02 05:11:56 +00:00 committed by Xubin Ren
parent 61d7411238
commit ded0967c18
2 changed files with 14 additions and 1 deletions

View File

@ -87,7 +87,7 @@ class AzureOpenAIProvider(LLMProvider):
) -> dict[str, Any]:
"""Build the Responses API request body from Chat-Completions-style args."""
deployment = model or self.default_model
instructions, input_items = convert_messages(messages)
instructions, input_items = convert_messages(self._sanitize_empty_content(messages))
body: dict[str, Any] = {
"model": deployment,

View File

@ -150,6 +150,19 @@ def test_build_body_image_conversion():
assert image_block["image_url"] == "https://example.com/img.png"
def test_build_body_sanitizes_single_dict_content_block():
"""Single content dicts should be preserved via shared message sanitization."""
provider = AzureOpenAIProvider(api_key="k", api_base="https://r.com", default_model="gpt-4o")
messages = [{
"role": "user",
"content": {"type": "text", "text": "Hi from dict content"},
}]
body = provider._build_body(messages, None, None, 4096, 0.7, None, None)
assert body["input"][0]["content"] == [{"type": "input_text", "text": "Hi from dict content"}]
# ---------------------------------------------------------------------------
# chat() — non-streaming
# ---------------------------------------------------------------------------