Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/entrypoints/openai_api/test_serving_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@

pytestmark = [pytest.mark.core_model, pytest.mark.cpu]


@pytest.mark.asyncio
@pytest.mark.parametrize("model", [None, "test-model", "alias", "missing-model"])
async def test_diffusion_speech_checks_all_served_model_names(mocker, monkeypatch, tmp_path, model):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[suggestion] This test sits between pytestmark and the module setup (logger, helpers), separate from the other diffusion speech tests. Moving it into TestSpeechAPI alongside the other for_diffusion cases would keep them together.

monkeypatch.setenv("SPEAKER_SAMPLES_DIR", str(tmp_path))
server = OmniOpenAIServingSpeech.for_diffusion(
diffusion_engine=mocker.MagicMock(),
model_name="test-model",
served_model_names=["test-model", "alias"],
)
generation = mocker.patch.object(server, "_create_diffusion_speech", new_callable=mocker.AsyncMock)
response = await server.create_speech(OpenAICreateSpeechRequest(input="Hello", model=model))
if model == "missing-model":
assert response.status_code == 404
assert json.loads(response.body)["error"]["type"] == "NotFoundError"
generation.assert_not_awaited()
else:
assert response is generation.return_value
generation.assert_awaited_once()


logger = logging.getLogger(__name__)


Expand Down
1 change: 1 addition & 0 deletions vllm_omni/entrypoints/openai/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ async def omni_init_app_state(
state.openai_serving_speech = OmniOpenAIServingSpeech.for_diffusion(
diffusion_engine=engine_client,
model_name=model_name,
served_model_names=served_model_names,
stage_configs=diffusion_stage_configs,
speech_cache_config=speech_cache_config,
allowed_local_media_path=getattr(args, "allowed_local_media_path", ""),
Expand Down
9 changes: 8 additions & 1 deletion vllm_omni/entrypoints/openai/serving_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ def for_diffusion(
allowed_media_domains: list[str] | None = None,
speech_cache_config: SpeechCacheConfig | None = None,
request_logger: RequestLogger | None = None,
served_model_names: list[str] | None = None,
) -> "OmniOpenAIServingSpeech":
"""Create a speech serving instance for pure diffusion TTS models.

Expand All @@ -457,6 +458,7 @@ def for_diffusion(
instance.speech_cache_config = speech_cache_config or SpeechCacheConfig()
instance._diffusion_mode = True
instance._diffusion_engine = diffusion_engine
instance._diffusion_model_names = frozenset(served_model_names or [model_name])
instance._allowed_local_media_path = allowed_local_media_path
instance._media_connector = MediaConnector(
allowed_local_media_path=allowed_local_media_path,
Expand Down Expand Up @@ -2534,7 +2536,10 @@ def _diffusion_error_response(message: str, status_code: int = 500) -> Response:
client-input validation failures so the response semantics match
the OpenAI-compatible behavior used by ``create_speech``.
"""
err_type = "BadRequestError" if 400 <= status_code < 500 else "server_error"
if status_code == 404:
err_type = "NotFoundError"
else:
err_type = "BadRequestError" if 400 <= status_code < 500 else "server_error"
error_body = json.dumps({"error": {"message": message, "type": err_type, "param": None, "code": status_code}})
return Response(content=error_body, media_type="application/json", status_code=status_code)

Expand Down Expand Up @@ -2594,6 +2599,8 @@ async def create_speech(
return self.create_error_response(sample_rate_error)

if self._diffusion_mode:
if request.model is not None and request.model not in self._diffusion_model_names:
return self._diffusion_error_response(f"The model `{request.model}` does not exist.", status_code=404)
return await self._create_diffusion_speech(request)

error_check_ret = await self._check_model(request)
Expand Down
Loading