Skip to content

feat: handle audio and image output models from OpenRouter#9

Merged
sena-labs merged 2 commits into
mainfrom
claude/laughing-beaver-f67164
May 7, 2026
Merged

feat: handle audio and image output models from OpenRouter#9
sena-labs merged 2 commits into
mainfrom
claude/laughing-beaver-f67164

Conversation

@sena-labs
Copy link
Copy Markdown
Owner

Summary

  • Add _format_image_output() helper that converts message.images entries into markdown image tags
  • In _non_stream_response: fall back to audio.transcript when content is empty/None (audio-only models), and append generated images as markdown after text content
  • In _stream_response: use delta.audio.transcript as streamed text when delta.content is absent (audio-streaming models)
  • Add 23 unit tests in section 34 of test_pipe.py covering all new code paths

Motivation

OpenRouter exposes 5 audio-output models and 7 image-output models. These models return an empty content field and put their output in message.audio or message.images. Without this fix, using them through the pipe produces a blank response in Open WebUI.

Test plan

  • python test_pipe.pyTotal: 425 | ✓ Passed: 425 | ✗ Failed: 0
  • Manual test with openai/gpt-4o-audio-preview or similar audio model (requires live API key)
  • Manual test with openai/gpt-image-1 or similar image model (requires live API key)

🤖 Generated with Claude Code

OpenRouter exposes models that return audio transcripts (message.audio)
and generated images (message.images) instead of text in message.content.
Without this fix those models return an empty response in Open WebUI.

- Add _format_image_output() to render image URLs as markdown image tags
- In _non_stream_response: fall back to audio.transcript when content is
  empty/None, and append any images as markdown after the text content
- In _stream_response: use delta.audio.transcript as the streamed text
  when delta.content is absent (audio-streaming models)
- Add 23 unit tests covering all new paths (section 34 in test_pipe.py)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 7, 2026 14:54
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for OpenRouter models that return outputs via message.audio.transcript (audio-output models) and message.images (image-output models), so Open WebUI doesn’t show blank responses for these model types.

Changes:

  • Add _format_image_output() to render message.images items as markdown image tags.
  • Update non-streaming and streaming response formatting to fall back to audio transcripts when content is empty/None, and to append generated images after text.
  • Add unit tests covering image formatting and audio transcript fallbacks for both non-streaming and streaming paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
openrouter_pipe.py Adds image-output formatting helper; updates _non_stream_response and _stream_response to handle audio transcripts and image outputs.
test_pipe.py Adds a new test section validating _format_image_output plus audio/image handling in non-streaming and streaming responses.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread openrouter_pipe.py Outdated
Comment thread openrouter_pipe.py Outdated
Address Copilot review comments on PR #9:

- _format_image_output: reject unsafe URL schemes (only http/https and
  data:image/* are allowed) and percent-encode ')' to avoid breaking
  markdown link syntax — consistent with _insert_citations behaviour
- _non_stream_response: prefix image_md with '\n\n' when final_parts is
  non-empty so the image tag is never glued directly to preceding text
- Add 6 new unit tests covering unsafe scheme rejection, ')' encoding,
  blank-line separator, and image-only (no leading newlines) case

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@sena-labs sena-labs merged commit 7019ea1 into main May 7, 2026
4 checks passed
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.

2 participants