[Core] Generalized turn-based /v1/realtime implementation (#8339)
Signed-off-by: Nick Cao <ncao@redhat.com> Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
1 parent
25fb257667
commit
65699fe94c
16 files changed
+716
-799
No files matched your search
@@ -1,62 +1,17 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Unit tests for realtime streaming helpers (PR #2581 /v1/realtime path)."""
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
"""Unit tests for AsyncOmni input streaming parameter validation."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
import torch
|
||||
from vllm.sampling_params import RequestOutputKind, SamplingParams
|
||||
|
||||
from vllm_omni.entrypoints.async_omni import AsyncOmni
|
||||
from vllm_omni.entrypoints.openai.realtime_connection import RealtimeConnection
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def realtime_conn() -> RealtimeConnection:
|
||||
return RealtimeConnection.__new__(RealtimeConnection)
|
||||
|
||||
|
||||
class TestRealtimeConnectionTensorAndPcm:
|
||||
def test_tensor_to_numpy_none(self) -> None:
|
||||
assert RealtimeConnection._tensor_to_numpy(None) is None
|
||||
|
||||
def test_tensor_to_numpy_1d_numpy(self) -> None:
|
||||
arr = np.array([1.0, 2.0], dtype=np.float64)
|
||||
out = RealtimeConnection._tensor_to_numpy(arr)
|
||||
assert out is not None
|
||||
assert out.dtype == np.float32
|
||||
assert out.shape == (2,)
|
||||
|
||||
def test_tensor_to_numpy_2d_numpy_flattened(self) -> None:
|
||||
arr = np.array([[0.5], [-0.5]], dtype=np.float32)
|
||||
out = RealtimeConnection._tensor_to_numpy(arr)
|
||||
assert out is not None
|
||||
assert out.shape == (2,)
|
||||
|
||||
def test_tensor_to_numpy_torch(self) -> None:
|
||||
t = torch.tensor([[0.25, -0.25]], dtype=torch.float32)
|
||||
out = RealtimeConnection._tensor_to_numpy(t)
|
||||
assert out is not None
|
||||
assert out.shape == (2,)
|
||||
np.testing.assert_allclose(out, [0.25, -0.25], rtol=1e-5)
|
||||
|
||||
def test_pcm16_b64_roundtrip(self) -> None:
|
||||
audio = np.array([0.0, 1.0, -1.0], dtype=np.float32)
|
||||
b64 = RealtimeConnection._pcm16_b64(audio)
|
||||
raw = base64.b64decode(b64)
|
||||
assert len(raw) == 6
|
||||
pcm = np.frombuffer(raw, dtype=np.int16)
|
||||
assert pcm[0] == 0
|
||||
assert pcm[1] == 32767
|
||||
assert pcm[2] == -32767
|
||||
|
||||
|
||||
class TestAsyncOmniStreamingParamsValidation:
|
||||
def test_accepts_streaming_friendly_params(self) -> None:
|
||||
p = SamplingParams(
|
||||
|
||||
Reference in new issue
Block a user