Skip to content

Fix response api support #45463

Merged
SunMarc merged 9 commits intomainfrom
better-response-api-support
Apr 16, 2026
Merged

Fix response api support #45463
SunMarc merged 9 commits intomainfrom
better-response-api-support

Conversation

@SunMarc
Copy link
Copy Markdown
Member

@SunMarc SunMarc commented Apr 15, 2026

What does this PR do?

This PR updates the support for response api. I was mainly basing myself on chat completion api but there are minor differences with it e.g input_image vs image_url for type or input_text vs text, different types of input structure accepted. Also i've simplified a bit the processing of the inputs.

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Comment on lines -964 to -969
if "base64" in url:
image_data = re.sub("^data:image/.+;base64,", "", url)
image = Image.open(BytesIO(base64.b64decode(image_data)))
file = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
image.save(file.name)
url = file.name
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed as suggested by @zucchini-nlp

Comment on lines -973 to -978
audio_data = base64.b64decode(input_audio["data"])
suffix = f".{input_audio.get('format', 'wav')}" if isinstance(input_audio, dict) else ".wav"
file = tempfile.NamedTemporaryFile(suffix=suffix, delete=False)
file.write(audio_data)
file.flush()
parsed["content"].append({"type": "audio", "url": file.name})
Copy link
Copy Markdown
Member Author

@SunMarc SunMarc Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, we delegate this to the processor

@SunMarc
Copy link
Copy Markdown
Member Author

SunMarc commented Apr 15, 2026

run-slow: cli

@github-actions
Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: ["cli"]
quantizations: []

@github-actions
Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN 9344bef3 workflow commit (merge commit)
PR 16eb0207 branch commit (from PR)
main 03487329 base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

@SunMarc SunMarc requested a review from vasqu April 16, 2026 12:42
@SunMarc
Copy link
Copy Markdown
Member Author

SunMarc commented Apr 16, 2026

run-slow: cli

@github-actions
Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: ["cli"]
quantizations: []

@github-actions
Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN b0ff8d2f workflow commit (merge commit)
PR 2c1dd925 branch commit (from PR)
main bc7ee236 base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

Copy link
Copy Markdown
Member

@zucchini-nlp zucchini-nlp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay for me, let's just check if breaking "dict-format-inputs" is fine

Comment on lines +193 to +195
3. **Messages list** (multi-turn, with ``role`` keys):
``input=[{"role": "user", "content": [...]}, {"role": "assistant", ...}]``
→ passed through as-is.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should multi-turn it be added in the docs? I see that now we show #2 input type in this PR, but prob I am not aware and it's already available somewhere else

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we show type 2 input as it is simpler. I'll add a small section about multi turn conversation as I think most users will most likely use an existing client.

Comment on lines -212 to -214
elif isinstance(inp, dict):
messages = [{"role": "system", "content": instructions}] if instructions else []
messages.append(inp)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flagging that this looks breaking, up to you and Lysandre tho 😄

Copy link
Copy Markdown
Member Author

@SunMarc SunMarc Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's fine ! response api is supposed to only allow string or List. It was my mistake to add it in the first place.

@SunMarc SunMarc enabled auto-merge April 16, 2026 17:44
@SunMarc SunMarc added this pull request to the merge queue Apr 16, 2026
Merged via the queue into main with commit 9b1a47c Apr 16, 2026
18 checks passed
@SunMarc SunMarc deleted the better-response-api-support branch April 16, 2026 20:54
shaun0927 added a commit to shaun0927/transformers that referenced this pull request Apr 17, 2026
OpenAI-compatible tool-calling payloads may encode assistant tool-call
messages with explicit null content rather than omitting the field.
The serve path already handled missing content, but iterated over None
for the explicit-null case and raised TypeError before the tool calls
reached apply_chat_template.

This keeps the fix intentionally small: normalize None to an empty
content list and pin the behavior with focused LLM/VLM regression tests.

Constraint: Recent serve/tool-call fixes (huggingface#45348, huggingface#45418, huggingface#45463) make compatibility regressions in this path especially review-sensitive
Rejected: Broader serve content refactor | unnecessary scope for a one-line crash fix
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep follow-up discussion focused on the explicit null-content case; do not mix unrelated serve cleanup into the PR
Tested: Direct local repro before/after; pytest -q tests/cli/test_serve.py -k 'tool_use_fields_forwarded'
Not-tested: Full repo CI; end-to-end HTTP serve session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants