[Feature] JoyAI-VL-Interaction streaming interaction serving layer (#4575)
Signed-off-by: lishunyang12 <125541396+lishunyang12@users.noreply.github.com> Signed-off-by: Yueqian Lin <linyueqian@outlook.com> Signed-off-by: lishunyang <lishunyang12@163.com> Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com> Co-authored-by: Yueqian Lin <linyueqian@outlook.com>
This commit is contained in:
45 files changed
+3699
-1
No files matched your search
@@ -0,0 +1,96 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm_omni.experimental.fullduplex.joyvl.decision.output_parser import parse_action
|
||||
from vllm_omni.experimental.fullduplex.joyvl.memory.brain import InteractionBrain
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
class _FakeSummarizer:
|
||||
def __init__(self):
|
||||
self.chunks = 0
|
||||
|
||||
async def summarize_chunk(self, chunk_index, frame_range, frames):
|
||||
self.chunks += 1
|
||||
return f"summary-of-chunk-{chunk_index}"
|
||||
|
||||
async def compress_to_long_term(self, existing, mids):
|
||||
return (existing + " | " if existing else "") + f"compressed({len(mids)})"
|
||||
|
||||
|
||||
class _FakeDelegation:
|
||||
def __init__(self):
|
||||
self._ready = {}
|
||||
|
||||
async def submit(self, question, note, frames):
|
||||
self._ready["t1"] = question
|
||||
return "t1"
|
||||
|
||||
async def poll(self, task_id):
|
||||
from vllm_omni.experimental.fullduplex.joyvl.bridges.delegation import DelegationResult
|
||||
|
||||
return DelegationResult(task_id, "ready", digest=f"answer to {self._ready[task_id]}")
|
||||
|
||||
|
||||
def test_query_freshness_and_archive_on_change():
|
||||
b = InteractionBrain()
|
||||
assert b.update_query("count bottles") is True
|
||||
assert b.update_query("count bottles") is False
|
||||
b.record_response("1 bottle")
|
||||
assert b.update_query("now describe") is True
|
||||
assert b.memory.qa_history[-1].query == "count bottles"
|
||||
assert b.memory.qa_history[-1].responses == [("0.0s", "1 bottle")]
|
||||
|
||||
|
||||
def test_query_in_frame_on_arrival_then_prefix_on_later_chunks():
|
||||
b = InteractionBrain(frame_seconds=1.0)
|
||||
b.tick(3)
|
||||
b.update_query("alert me if a fire breaks out")
|
||||
assert b.query_in_current_chunk is True
|
||||
assert "alert me if a fire breaks out" not in b.build_prefix()
|
||||
b.record_response("a fire is breaking out")
|
||||
b.close_chunk()
|
||||
assert b.query_in_current_chunk is False
|
||||
prefix = b.build_prefix()
|
||||
assert "alert me if a fire breaks out" in prefix
|
||||
assert "a fire is breaking out" in prefix
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_flush_archives_qa_and_summarizes():
|
||||
summ = _FakeSummarizer()
|
||||
b = InteractionBrain(summarizer=summ, chunk_frames=3, long_term_every_n_chunks=2, frame_seconds=1.0)
|
||||
b.update_query("watch the room")
|
||||
b.tick(3)
|
||||
assert b.should_flush() is True
|
||||
b.record_response("a person enters")
|
||||
await b.flush([("0.0s", "u0"), ("2.0s", "u2")])
|
||||
assert summ.chunks == 1
|
||||
assert b.chunk_index == 2
|
||||
assert b.should_flush() is False
|
||||
assert b.memory.qa_history[-1].responses == [("2.0s", "a person enters")]
|
||||
assert len(b.memory.mid_term_summaries) == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_long_term_compression_after_n_chunks():
|
||||
summ = _FakeSummarizer()
|
||||
b = InteractionBrain(summarizer=summ, chunk_frames=1, long_term_every_n_chunks=2, frame_seconds=1.0)
|
||||
for _ in range(2):
|
||||
await b.flush([("0.0s", "u")])
|
||||
assert b.memory.long_term_memory.startswith("compressed(")
|
||||
assert b.memory.mid_term_summaries == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delegation_submit_and_fold():
|
||||
b = InteractionBrain(delegation=_FakeDelegation())
|
||||
action = parse_action("</response> hold on <delegation> solve this")
|
||||
info = await b.submit_delegation(action, [])
|
||||
assert info["status"] == "submitted"
|
||||
folded = await b.fold_delegations()
|
||||
assert folded["status"] == "ready"
|
||||
assert b.memory.qa_history[-1].responses[0][1] == "answer to solve this"
|
||||
@@ -0,0 +1,282 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm_omni.experimental.fullduplex.joyvl.bridges.delegation import (
|
||||
DelegationResult,
|
||||
ImageEditDelegationBridge,
|
||||
ImageGenDelegationBridge,
|
||||
OpenAIDelegationBridge,
|
||||
)
|
||||
from vllm_omni.experimental.fullduplex.joyvl.decision.policy import JoyVLPolicy, sample_frames
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
def test_sample_frames_keeps_recent():
|
||||
assert sample_frames(["a", "b"], 4) == ["a", "b"]
|
||||
out = sample_frames([str(i) for i in range(10)], 4)
|
||||
assert out[-1] == "9" and len(out) == 4
|
||||
|
||||
|
||||
def test_build_messages_stable_head_and_query():
|
||||
p = JoyVLPolicy(num_frames=4)
|
||||
p.tick(2)
|
||||
p.set_query("count the bottles")
|
||||
msgs, user = p.build_messages([{"type": "image_url", "image_url": {"url": "x"}}])
|
||||
assert msgs[0]["role"] == "system" and "</silence>" in msgs[0]["content"]
|
||||
|
||||
assert any("count the bottles" in part.get("text", "") for part in user["content"])
|
||||
|
||||
|
||||
def test_commit_records_only_spoken():
|
||||
p = JoyVLPolicy()
|
||||
p.set_query("q")
|
||||
assert p.commit("</silence>").action.value == "silence"
|
||||
assert p.brain.response_records == []
|
||||
assert p.commit("</response> hello").action.value == "response"
|
||||
assert p.brain.response_records == [("0.0s", "hello")]
|
||||
|
||||
|
||||
def test_commit_dedup_default_is_exact_match_only():
|
||||
p = JoyVLPolicy() # threshold 1.0 == reference behavior
|
||||
assert p.commit("</response> a red ball appears").action.value == "response"
|
||||
assert p.commit("</response> a red ball appears").action.value == "silence" # exact repeat dropped
|
||||
assert p.commit("</response> a red ball is appearing").action.value == "response" # near-dup kept
|
||||
|
||||
|
||||
def test_commit_dedup_threshold_drops_near_duplicates():
|
||||
p = JoyVLPolicy(response_dedup_threshold=0.8)
|
||||
assert p.commit("</response> a red ball appears").action.value == "response"
|
||||
assert p.commit("</response> a red ball appears!").action.value == "silence" # near-dup dropped
|
||||
assert p.commit("</response> the sky is now blue").action.value == "response" # distinct kept
|
||||
|
||||
|
||||
def test_commit_dedup_rearms_after_silence():
|
||||
p = JoyVLPolicy(response_dedup_threshold=0.85)
|
||||
assert p.commit("</response> someone raises a hand").action.value == "response"
|
||||
# no gap: an immediate repeat is still suppressed
|
||||
assert p.commit("</response> someone raises a hand").action.value == "silence"
|
||||
# a genuine silent tick (hand lowered) re-arms; the recurrence speaks again
|
||||
assert p.commit("</silence>").action.value == "silence"
|
||||
assert p.commit("</response> someone raises a hand").action.value == "response"
|
||||
|
||||
|
||||
class _FakeBrain(OpenAIDelegationBridge):
|
||||
"""Override only the network call so submit/poll plumbing is exercised for real."""
|
||||
|
||||
def __init__(self, answer, gate=None):
|
||||
super().__init__("http://unused/v1", "background-model")
|
||||
self._answer = answer
|
||||
self._gate = gate
|
||||
|
||||
async def _complete(self, messages):
|
||||
if self._gate is not None:
|
||||
await self._gate.wait()
|
||||
return self._answer
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_openai_delegation_bridge_is_nonblocking_and_resolves():
|
||||
gate = asyncio.Event()
|
||||
bridge = _FakeBrain("the bottle is on the left shelf", gate=gate)
|
||||
frames = [("0.0s", "data:image/jpeg;base64,AAA")]
|
||||
task_id = await bridge.submit("where is the bottle?", "let me check", frames)
|
||||
|
||||
# poll must not block on the slow background brain
|
||||
assert (await bridge.poll(task_id)).status == "pending"
|
||||
|
||||
gate.set()
|
||||
await asyncio.sleep(0)
|
||||
for _ in range(10):
|
||||
result = await bridge.poll(task_id)
|
||||
if result.status != "pending":
|
||||
break
|
||||
await asyncio.sleep(0)
|
||||
assert result.is_ready
|
||||
assert "bottle is on the left shelf" in result.digest
|
||||
assert (await bridge.poll("missing")).status == "error"
|
||||
|
||||
|
||||
class _FakeImageBrain(ImageGenDelegationBridge):
|
||||
async def _call_images(self, payload):
|
||||
# echo the prompt back so the test can assert it was passed through
|
||||
return {"data": [{"b64_json": "QUJD"}]} # "ABC"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_image_delegation_bridge_returns_media_not_text():
|
||||
bridge = _FakeImageBrain("http://unused/v1")
|
||||
task_id = await bridge.submit("draw a red dragon", "", [])
|
||||
for _ in range(10):
|
||||
result = await bridge.poll(task_id)
|
||||
if result.status != "pending":
|
||||
break
|
||||
await asyncio.sleep(0)
|
||||
assert result.is_ready
|
||||
# the image rides in media as a data URL; digest is only a short text placeholder
|
||||
assert result.media == "data:image/png;base64,QUJD"
|
||||
assert "QUJD" not in result.digest and "red dragon" in result.digest
|
||||
|
||||
|
||||
class _FakeEditBrain(ImageEditDelegationBridge):
|
||||
def __init__(self, base_url, model):
|
||||
super().__init__(base_url, model)
|
||||
self.seen_frame = None
|
||||
|
||||
async def _call_chat(self, frame, instruction):
|
||||
self.seen_frame = frame
|
||||
return {"choices": [{"message": {"content": [{"image_url": {"url": "data:image/png;base64,Q0FSVA=="}}]}}]}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_image_edit_delegation_conditions_on_frame_and_returns_media():
|
||||
bridge = _FakeEditBrain("http://unused/v1", "Qwen-Image-Edit")
|
||||
frames = [("0.0s", "data:image/jpeg;base64,OLD"), ("1.0s", "data:image/jpeg;base64,NOW")]
|
||||
task_id = await bridge.submit("把画面变成卡通风格", "", frames)
|
||||
for _ in range(10):
|
||||
result = await bridge.poll(task_id)
|
||||
if result.status != "pending":
|
||||
break
|
||||
await asyncio.sleep(0)
|
||||
assert result.is_ready
|
||||
assert bridge.seen_frame == "data:image/jpeg;base64,NOW" # latest frame, not the old one
|
||||
assert result.media == "data:image/png;base64,Q0FSVA=="
|
||||
assert result.media not in result.digest # image rides in media, not context
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_image_edit_delegation_errors_without_frame():
|
||||
bridge = _FakeEditBrain("http://unused/v1", "Qwen-Image-Edit")
|
||||
task_id = await bridge.submit("cartoonify", "", [])
|
||||
for _ in range(10):
|
||||
result = await bridge.poll(task_id)
|
||||
if result.status != "pending":
|
||||
break
|
||||
await asyncio.sleep(0)
|
||||
assert result.status == "error"
|
||||
|
||||
|
||||
class _NamedBridge:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
async def submit(self, question, note, frames):
|
||||
return f"{self.name}-1"
|
||||
|
||||
async def poll(self, task_id):
|
||||
return DelegationResult(task_id, "ready", digest=self.name)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_routing_delegation_dispatches_by_request():
|
||||
from vllm_omni.experimental.fullduplex.joyvl.bridges.delegation import RoutingDelegationBridge
|
||||
|
||||
chat, image, edit = _NamedBridge("chat"), _NamedBridge("image"), _NamedBridge("edit")
|
||||
r = RoutingDelegationBridge(chat=chat, image=image, edit=edit)
|
||||
|
||||
async def route(q):
|
||||
tid = await r.submit(q, "", [])
|
||||
return (await r.poll(tid)).digest
|
||||
|
||||
assert await route("把你看到的画面变成卡通风格") == "edit" # restyle current view
|
||||
assert await route("画一只红色的龙") == "image" # generate a new image
|
||||
assert await route("这道数学题的答案是什么") == "chat" # hard question -> chat brain
|
||||
|
||||
|
||||
class _Delegation:
|
||||
async def submit(self, question, note, frames):
|
||||
return "t1"
|
||||
|
||||
async def poll(self, task_id):
|
||||
return DelegationResult(task_id, "ready", digest="background answer")
|
||||
|
||||
|
||||
def test_build_delegation_off_unless_backend_configured():
|
||||
from vllm_omni.experimental.fullduplex.joyvl.serving.config import InteractionConfig
|
||||
from vllm_omni.experimental.fullduplex.joyvl.serving.server import SessionManager
|
||||
|
||||
# No backend URL -> delegation disabled (None), NOT a silent stub that folds fake answers.
|
||||
assert SessionManager._build_delegation(InteractionConfig()) is None
|
||||
assert SessionManager._build_delegation(InteractionConfig(delegation_kind="router")) is None
|
||||
# Stub only on explicit opt-in.
|
||||
assert SessionManager._build_delegation(InteractionConfig(delegation_kind="stub")) is not None
|
||||
# A real chat backend -> a live bridge.
|
||||
cfg = InteractionConfig(delegation_backend_url="http://x/v1", delegation_model="m")
|
||||
assert SessionManager._build_delegation(cfg) is not None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delegation_cancel_drops_task():
|
||||
from vllm_omni.experimental.fullduplex.joyvl.bridges.delegation import StubDelegationBridge
|
||||
|
||||
b = StubDelegationBridge(ready_after_ticks=1)
|
||||
task_id = await b.submit("q", "", [])
|
||||
b.cancel(task_id)
|
||||
# after cancel the task is gone -> poll reports it as unknown rather than leaking
|
||||
assert (await b.poll(task_id)).status == "error"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delegation_aclose_clears_pending():
|
||||
from vllm_omni.experimental.fullduplex.joyvl.bridges.delegation import StubDelegationBridge
|
||||
|
||||
b = StubDelegationBridge(ready_after_ticks=5)
|
||||
task_id = await b.submit("q", "", [])
|
||||
await b.aclose()
|
||||
assert (await b.poll(task_id)).status == "error"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_session_reset_cancels_and_awaits_consolidation():
|
||||
from vllm_omni.experimental.fullduplex.joyvl.serving.config import InteractionConfig
|
||||
from vllm_omni.experimental.fullduplex.joyvl.serving.session import InteractionSession
|
||||
|
||||
class _Backend:
|
||||
async def generate(self, *a, **k):
|
||||
return "</silence>", None
|
||||
|
||||
async def aclose(self):
|
||||
pass
|
||||
|
||||
class _Summarizer:
|
||||
async def summarize_chunk(self, *a, **k):
|
||||
await asyncio.sleep(100) # hang so the consolidation task is in-flight
|
||||
return "x"
|
||||
|
||||
async def compress_to_long_term(self, *a, **k):
|
||||
return ""
|
||||
|
||||
async def aclose(self):
|
||||
pass
|
||||
|
||||
sess = InteractionSession("s", InteractionConfig(), _Backend(), summarizer=_Summarizer())
|
||||
sess._spawn_consolidation(1, [("0.0s", "u")])
|
||||
assert len(sess._consolidating) == 1
|
||||
await sess.reset() # must cancel AND await the in-flight task, not just clear the set
|
||||
assert len(sess._consolidating) == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_manager_aclose_closes_without_error():
|
||||
from vllm_omni.experimental.fullduplex.joyvl.serving.config import InteractionConfig
|
||||
from vllm_omni.experimental.fullduplex.joyvl.serving.server import SessionManager
|
||||
|
||||
mgr = SessionManager(InteractionConfig(enable_memory=False, enable_delegation=False))
|
||||
await mgr.aclose()
|
||||
await mgr.aclose() # idempotent
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delegation_submit_and_fold():
|
||||
p = JoyVLPolicy(delegation=_Delegation())
|
||||
action = p.commit("</response> hold on <delegation> hard question")
|
||||
assert action.action.value == "delegate"
|
||||
info = await p.submit_if_delegate(action)
|
||||
assert info["status"] == "submitted"
|
||||
folded = await p.fold_delegations()
|
||||
assert folded["status"] == "ready"
|
||||
assert p.brain.memory.qa_history[-1].responses[0][1] == "background answer"
|
||||
@@ -0,0 +1,172 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import asyncio
|
||||
from collections.abc import AsyncIterator
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm_omni.experimental.fullduplex.core import protocol as ev
|
||||
from vllm_omni.experimental.fullduplex.core.adapter import DuplexCapability, OutputChunk
|
||||
from vllm_omni.experimental.fullduplex.core.runtime import DuplexRuntime
|
||||
from vllm_omni.experimental.fullduplex.core.session import DuplexSession, DuplexSessionConfig
|
||||
from vllm_omni.experimental.fullduplex.joyvl.adapter import JoyVLDuplexAdapter
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
async def _feed(events):
|
||||
for e in events:
|
||||
yield e
|
||||
|
||||
|
||||
def _collector():
|
||||
out: list[dict] = []
|
||||
|
||||
async def emit(event: dict) -> None:
|
||||
out.append(event)
|
||||
|
||||
return out, emit
|
||||
|
||||
|
||||
class _FakeAdapter:
|
||||
def __init__(self, chunks, barge_after=None):
|
||||
self._chunks = chunks
|
||||
self._barge_after = barge_after
|
||||
|
||||
def capabilities(self):
|
||||
return DuplexCapability(frozenset({"text"}), frozenset({"text"}), proactive=False)
|
||||
|
||||
async def on_input(self, session, modality, data):
|
||||
pass
|
||||
|
||||
def should_respond(self, session):
|
||||
return True
|
||||
|
||||
async def respond(self, session) -> AsyncIterator[OutputChunk]:
|
||||
for i, c in enumerate(self._chunks):
|
||||
if self._barge_after is not None and i == self._barge_after:
|
||||
session.barge_in()
|
||||
yield OutputChunk("text", c)
|
||||
|
||||
async def on_barge_in(self, session):
|
||||
pass
|
||||
|
||||
async def on_playback_ack(self, session, cursor):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_runtime_basic_response():
|
||||
session = DuplexSession("s", DuplexSessionConfig(output_modalities=("text",)))
|
||||
rt = DuplexRuntime(session, _FakeAdapter(["a", "b"]))
|
||||
out, emit = _collector()
|
||||
await rt.run(_feed([{"type": ev.INPUT_COMMIT}, {"type": ev.CLOSE}]), emit)
|
||||
types = [e["type"] for e in out]
|
||||
assert types == [ev.RESPONSE_CREATED, ev.RESPONSE_DELTA, ev.RESPONSE_DELTA, ev.RESPONSE_DONE]
|
||||
assert [e["data"] for e in out if e["type"] == ev.RESPONSE_DELTA] == ["a", "b"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_runtime_barge_in_drops_stale_output():
|
||||
session = DuplexSession("s")
|
||||
rt = DuplexRuntime(session, _FakeAdapter(["a", "b", "c"], barge_after=1))
|
||||
out, emit = _collector()
|
||||
await rt.run(_feed([{"type": ev.INPUT_COMMIT}, {"type": ev.CLOSE}]), emit)
|
||||
data = [e["data"] for e in out if e["type"] == ev.RESPONSE_DELTA]
|
||||
assert data == ["a"]
|
||||
assert ev.RESPONSE_DONE not in [e["type"] for e in out]
|
||||
|
||||
|
||||
class _SlowAdapter:
|
||||
def capabilities(self):
|
||||
return DuplexCapability(frozenset({"text"}), frozenset({"text"}), proactive=False)
|
||||
|
||||
async def on_input(self, session, modality, data):
|
||||
pass
|
||||
|
||||
def should_respond(self, session):
|
||||
return True
|
||||
|
||||
async def respond(self, session) -> AsyncIterator[OutputChunk]:
|
||||
for c in ["a", "b", "c", "d", "e"]:
|
||||
await asyncio.sleep(0.02)
|
||||
yield OutputChunk("text", c)
|
||||
|
||||
async def on_barge_in(self, session):
|
||||
pass
|
||||
|
||||
async def on_playback_ack(self, session, cursor):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_runtime_cancel_event_interrupts_active_response():
|
||||
session = DuplexSession("s")
|
||||
rt = DuplexRuntime(session, _SlowAdapter())
|
||||
out, emit = _collector()
|
||||
|
||||
async def feed():
|
||||
yield {"type": ev.INPUT_COMMIT}
|
||||
await asyncio.sleep(0.03)
|
||||
yield {"type": ev.RESPONSE_CANCEL}
|
||||
yield {"type": ev.CLOSE}
|
||||
|
||||
await rt.run(feed(), emit)
|
||||
deltas = [e["data"] for e in out if e["type"] == ev.RESPONSE_DELTA]
|
||||
types = [e["type"] for e in out]
|
||||
assert len(deltas) < 5
|
||||
assert ev.RESPONSE_CANCELLED in types
|
||||
assert ev.RESPONSE_DONE not in types
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_runtime_new_response_supersedes_inflight_without_blocking():
|
||||
# A second response trigger arriving while the first is still streaming must
|
||||
# supersede it (barge-in) rather than block the input loop until it finishes.
|
||||
session = DuplexSession("s")
|
||||
rt = DuplexRuntime(session, _SlowAdapter())
|
||||
out, emit = _collector()
|
||||
|
||||
async def feed():
|
||||
yield {"type": ev.INPUT_COMMIT}
|
||||
await asyncio.sleep(0.03) # let the first response emit ~one chunk
|
||||
yield {"type": ev.INPUT_COMMIT} # supersedes the in-flight first response
|
||||
await asyncio.sleep(0.2) # let the second response finish
|
||||
yield {"type": ev.CLOSE}
|
||||
|
||||
await rt.run(feed(), emit)
|
||||
created = [e for e in out if e["type"] == ev.RESPONSE_CREATED]
|
||||
done = [e for e in out if e["type"] == ev.RESPONSE_DONE]
|
||||
# two responses created; only the latest one completes (the first was cancelled)
|
||||
assert len(created) == 2
|
||||
assert len(done) == 1
|
||||
assert done[0]["response_index"] == created[-1]["response_index"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_joyvl_adapter_speaks_then_silences():
|
||||
replies = iter(["</response> a fire is breaking out", "</silence>"])
|
||||
|
||||
async def fake_generate(messages):
|
||||
return next(replies)
|
||||
|
||||
adapter = JoyVLDuplexAdapter(fake_generate, num_frames=4)
|
||||
cfg = DuplexSessionConfig(input_modalities=("video", "text"), output_modalities=("text",), proactive=True)
|
||||
rt = DuplexRuntime(DuplexSession("s", cfg), adapter)
|
||||
out, emit = _collector()
|
||||
await rt.run(
|
||||
_feed(
|
||||
[
|
||||
{"type": ev.INPUT_APPEND, "modality": "text", "data": "alert me if a fire breaks out"},
|
||||
{"type": ev.INPUT_APPEND, "modality": "video", "data": "data:image/jpeg;base64,AAA"},
|
||||
{"type": ev.INPUT_APPEND, "modality": "video", "data": "data:image/jpeg;base64,BBB"},
|
||||
{"type": ev.CLOSE},
|
||||
]
|
||||
),
|
||||
emit,
|
||||
)
|
||||
deltas = [e["data"] for e in out if e["type"] == ev.RESPONSE_DELTA]
|
||||
assert "a fire is breaking out" in deltas
|
||||
|
||||
assert deltas.count("a fire is breaking out") == 1
|
||||
Reference in new issue
Block a user