refactor: formaliza contratos de streaming e ciclo de vida dos provedores
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from voice_assistant.agent.adapter import StreamingAgentAdapter
|
||||
from voice_assistant.tts.adapter import TTSAdapter
|
||||
import asyncio
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from contextlib import contextmanager
|
||||
@@ -1858,12 +1860,12 @@ def test_websocket_streaming_agent_and_tts():
|
||||
"""
|
||||
created_stt.clear()
|
||||
|
||||
class StreamingTestAgent:
|
||||
class StreamingTestAgent(StreamingAgentAdapter):
|
||||
async def stream(self, session_id, turn_id, text):
|
||||
yield "Olá, como posso ajudar?"
|
||||
yield " Estou à disposição."
|
||||
|
||||
class StreamingTestTTS:
|
||||
class StreamingTestTTS(TTSAdapter):
|
||||
async def synthesize(self, text):
|
||||
yield text.encode("utf-8")
|
||||
|
||||
@@ -1961,11 +1963,11 @@ def test_websocket_interrupt_during_streaming_tts():
|
||||
tts_started = threading.Event()
|
||||
tts_cancelled = threading.Event()
|
||||
|
||||
class SlowStreamingAgent:
|
||||
class SlowStreamingAgent(StreamingAgentAdapter):
|
||||
async def stream(self, session_id, turn_id, text):
|
||||
yield "Olá, esta é uma resposta longa."
|
||||
|
||||
class SlowStreamingTTS:
|
||||
class SlowStreamingTTS(TTSAdapter):
|
||||
async def synthesize(self, text):
|
||||
try:
|
||||
tts_started.set()
|
||||
@@ -2100,11 +2102,11 @@ def test_websocket_session_end_during_streaming_tts():
|
||||
|
||||
tts_cancelled = threading.Event()
|
||||
|
||||
class SlowStreamingAgent:
|
||||
class SlowStreamingAgent(StreamingAgentAdapter):
|
||||
async def stream(self, session_id, turn_id, text):
|
||||
yield "Esta é uma resposta longa."
|
||||
|
||||
class SlowStreamingTTS:
|
||||
class SlowStreamingTTS(TTSAdapter):
|
||||
async def synthesize(self, text):
|
||||
try:
|
||||
yield b"\x01\x02\x03\x04"
|
||||
@@ -2297,11 +2299,11 @@ def test_websocket_interrupt_wins_pending_tts_completion():
|
||||
|
||||
tts_cancelled = threading.Event()
|
||||
|
||||
class ControlledAgent:
|
||||
class ControlledAgent(StreamingAgentAdapter):
|
||||
async def stream(self, session_id, turn_id, text):
|
||||
yield "Esta resposta será interrompida."
|
||||
|
||||
class ControlledTTS:
|
||||
class ControlledTTS(TTSAdapter):
|
||||
async def synthesize(self, text):
|
||||
try:
|
||||
yield b"\x01\x02\x03\x04"
|
||||
|
||||
Reference in New Issue
Block a user