feat(openai): Accept the input_audio content part in chat completions (#33606)

This commit is contained in:
Jason Wiemels
2026-08-19 13:37:50 -07:00
committed by GitHub
parent 746418a1ec
commit defb2a3100
6 changed files with 150 additions and 7 deletions
@@ -6,8 +6,8 @@ import tempfile
import unittest
from sglang.srt.entrypoints.openai.protocol import (
ChatCompletionMessageContentAudioPart,
ChatCompletionMessageContentAudioURL,
ChatCompletionMessageContentAudioURLPart,
ChatCompletionMessageContentImagePart,
ChatCompletionMessageContentImageURL,
ChatCompletionMessageContentTextPart,
@@ -911,7 +911,7 @@ class TestGenerateChatConv(CustomTestCase):
ChatCompletionMessageContentTextPart(
type="text", text="Transcribe this"
),
ChatCompletionMessageContentAudioPart(
ChatCompletionMessageContentAudioURLPart(
type="audio_url",
audio_url=ChatCompletionMessageContentAudioURL(
url="http://example.com/audio.wav"
@@ -925,6 +925,31 @@ class TestGenerateChatConv(CustomTestCase):
self.assertEqual(len(conv.audio_data), 1)
self.assertEqual(conv.audio_data[0], "http://example.com/audio.wav")
def test_user_message_with_inline_audio(self):
"""Inline input_audio reaches the parser as a data URI.
Built from raw dicts so the content parts go through validation the way
a request body does, which is where the conversion happens; the parser
itself only knows about `audio_url`.
"""
request = self._make_request(
[
{
"role": "user",
"content": [
{"type": "text", "text": "Transcribe this"},
{
"type": "input_audio",
"input_audio": {"data": "QUJD", "format": "wav"},
},
],
}
]
)
conv = generate_chat_conv(request, "chatml")
self.assertEqual(len(conv.audio_data), 1)
self.assertEqual(conv.audio_data[0], "data:audio/wav;base64,QUJD")
def test_user_message_image_at_prefix(self):
"""Test image_token_at_prefix=True puts image token before text."""
# Register a temporary template with image_token_at_prefix=True