Repository navigation
feat: audio text to text support - #1396
Conversation
Component PR ChecklistUse this checklist when adding or modifying components in Protocol Compliance
Content Blocks
Integration
|
ajbozarth
left a comment
There was a problem hiding this comment.
Some feedback from Claude — nicely done overall, faithful to the image pattern and well-tested. One correctness item on the MP3 path (inline) I'd like addressed before merge; the rest are questions and nits.
Introduces AudioBlock (base64 audio with auto-detected format from data URIs), AudioUrlBlock (http/https audio URL), and get_audio_from_component helper. Exports all three from mellea/core/__init__.py. This is the core change for coming OpenAI API multimodal support for chat with audio similar to chat with images. Signed-off-by: Mark Sturdevant <[email protected]>
Add wiring for chat with audio similar to images. Signed-off-by: Mark Sturdevant <[email protected]> Assisted-by: IBM Bob
Add wiring for Instruction with audio similar to images. Signed-off-by: Mark Sturdevant <[email protected]>
Signed-off-by: Mark Sturdevant <[email protected]>
…nctional * audio parameter implementation similar to images * no special parsing like PIL handling is applicable Signed-off-by: Mark Sturdevant <[email protected]>
* Relies on llama-server with gemma for local audio-text-to-text support to test with OpenAI API audio input. Signed-off-by: Mark Sturdevant <[email protected]>
When the format is extracted from the data prefix, we get a MIME subtype. But when we use the format, we need it to be a valid OpenAI API format. There is a mismatch, but we can do some mapping. mpeg -> mp3 might be the only standard mapping needed, but there are some other non-standard or legacy mime subtypes that we also map now. When no mapping is needed or it is not known, we just use the subtype and pass it on. So the simple case like "wav" just works. Unsupported formats, or future things to map, will also pass through and should produce a reasonable error for invalid format (400). Signed-off-by: Mark Sturdevant <[email protected]> Assisted-by: IBM Bob
…because standards Signed-off-by: Mark Sturdevant <[email protected]> Assisted-by: IBM Bob
0624a11 to
9aae264
Compare
… Ollama and Watsonx Add explicit guards so AudioBlock/AudioUrlBlock passed to OllamaModelBackend and any multimodal block passed to WatsonxAIBackend raise ValueError instead of silently dropping the data. Add mocked unit tests for the new guards and for OpenAI audio payload shape. Signed-off-by: Mark Sturdevant <[email protected]> Assisted-by: IBM Bob
There was a problem hiding this comment.
should we also update docs/examples/README.md to include these?
| mime = value.split(";")[0].split("data:")[1] # e.g. "audio/wav" | ||
| subtype = mime.split("/")[-1] # e.g. "wav" | ||
| # Normalise non-standard / legacy MIME subtypes to OpenAI format tokens. | ||
| # OpenAI Chat Completions input_audio.format accepts: wav, mp3, ogg, flac. |
There was a problem hiding this comment.
There was a problem hiding this comment.
I do think I should fix the comment (I somehow have a ruff fix todo anyway).
for openai that is correct, but open source servers (not openai cloud) tend to accept whatever their decoder libraries accept. So flac would be a good example of that. So other than the comment, I'm leaning into passing through because 1 - easier maintenance because the openai type support will change and 2 - there is evidence that vllm, for example, supports different formats.
Speculative mapping is questionable, but the initial map is based on common legacy mime types and common supported formats. So I don't see a need to make it just { mpeg -> mp3} but open to opinions on that.
There was a problem hiding this comment.
updated comment so it is more accurate about the supported openai 2.
Also clarified a bit about the pass through of others and the mapping because that seemed a little contrary to the wording in the comments otherwise.
ajbozarth
left a comment
There was a problem hiding this comment.
LGTM — all my prior review points are addressed (MIME normalization, silent-drop guards on Ollama/Watsonx, RST cleanup). Approving.
Two inline nits below echo Paul's open points.
Non-blocking scope note (couldn't anchor inline — file isn't in this diff): the new Ollama/Watsonx guards close the silent-drop gap, but the HF chat path (_generate_from_context → to_chat → apply_chat_template) still stringifies messages and drops a stray audio= silently, same as it already does for images=. Pre-existing image behavior, not a regression from this PR, so fine to leave — fast-follow issue if anyone wants parity. (LiteLLM is unaffected; it serializes audio via message_to_openai_message.)
| mime = value.split(";")[0].split("data:")[1] # e.g. "audio/wav" | ||
| subtype = mime.split("/")[-1] # e.g. "wav" | ||
| # Normalise non-standard / legacy MIME subtypes to OpenAI format tokens. | ||
| # OpenAI Chat Completions input_audio.format accepts: wav, mp3, ogg, flac. |
There was a problem hiding this comment.
Nit (+1 to @psschwei): the comment lists wav, mp3, ogg, flac, but the OpenAI input_audio schema only accepts wav and mp3. Code is still correct (unknown subtypes pass through to a 400), but worth trimming the comment to wav, mp3 — and note x-flac→flac normalizes to a value OpenAI will reject anyway.
There was a problem hiding this comment.
fixed comment
nit: OpenAI the company/cloud will reject, but flac will work for servers/models that support it
| @@ -0,0 +1,71 @@ | |||
| # pytest: openai, e2e, qualitative | |||
There was a problem hiding this comment.
Nit (+1 to @psschwei): add these examples to docs/examples/README.md so they're discoverable.
Signed-off-by: Mark Sturdevant <[email protected]>
Signed-off-by: Mark Sturdevant <[email protected]>
Signed-off-by: Mark Sturdevant <[email protected]>
Signed-off-by: Mark Sturdevant <[email protected]>
019bb64
* feat: add AudioBlock and AudioUrlBlock Introduces AudioBlock (base64 audio with auto-detected format from data URIs), AudioUrlBlock (http/https audio URL), and get_audio_from_component helper. Exports all three from mellea/core/__init__.py. This is the core change for coming OpenAI API multimodal support for chat with audio similar to chat with images. Signed-off-by: Mark Sturdevant <[email protected]> * feat: add audio to Message and chat Add wiring for chat with audio similar to images. Signed-off-by: Mark Sturdevant <[email protected]> Assisted-by: IBM Bob * feat: add audio to instruction Add wiring for Instruction with audio similar to images. Signed-off-by: Mark Sturdevant <[email protected]> * feat: add support for audio parts in openai_compatible_helpers Signed-off-by: Mark Sturdevant <[email protected]> * feat: add audio support to chat and instruct in stdlib session and functional * audio parameter implementation similar to images * no special parsing like PIL handling is applicable Signed-off-by: Mark Sturdevant <[email protected]> * feat: add examples and e2e test for audio-text-models * Relies on llama-server with gemma for local audio-text-to-text support to test with OpenAI API audio input. Signed-off-by: Mark Sturdevant <[email protected]> * fix: mime subtypes for audio need to map to valid openai api formats When the format is extracted from the data prefix, we get a MIME subtype. But when we use the format, we need it to be a valid OpenAI API format. There is a mismatch, but we can do some mapping. mpeg -> mp3 might be the only standard mapping needed, but there are some other non-standard or legacy mime subtypes that we also map now. When no mapping is needed or it is not known, we just use the subtype and pass it on. So the simple case like "wav" just works. Unsupported formats, or future things to map, will also pass through and should produce a reasonable error for invalid format (400). Signed-off-by: Mark Sturdevant <[email protected]> Assisted-by: IBM Bob * fix: replaced RST blocks and fixed dedenting in test_audio_openai.py because standards Signed-off-by: Mark Sturdevant <[email protected]> Assisted-by: IBM Bob * fix(backends): raise ValueError for unsupported audio/image inputs in Ollama and Watsonx Add explicit guards so AudioBlock/AudioUrlBlock passed to OllamaModelBackend and any multimodal block passed to WatsonxAIBackend raise ValueError instead of silently dropping the data. Add mocked unit tests for the new guards and for OpenAI audio payload shape. Signed-off-by: Mark Sturdevant <[email protected]> Assisted-by: IBM Bob * docs: add examples to docs/examples/README.md Signed-off-by: Mark Sturdevant <[email protected]> * fix: improve comment about supported audio input Signed-off-by: Mark Sturdevant <[email protected]> * fix: ruff format fix Signed-off-by: Mark Sturdevant <[email protected]> * fix: fix missing raises in docstring Signed-off-by: Mark Sturdevant <[email protected]> --------- Signed-off-by: Mark Sturdevant <[email protected]>

Pull Request
Issue
Fixes #1394
Description
Adds support for audio similar to images in chat and instruct.
Testing
Attribution
Adding a new component, requirement, sampling strategy, or tool?
If your PR adds or modifies one of the types below, check the matching box. A checklist of type-specific review items will be posted as a comment.
NOTE: Please ensure you have an issue that has been acknowledged by a core contributor and routed you to open a pull request against this repository. Otherwise, please open an issue before continuing with this pull request.