test cleanup

This commit is contained in:
Chad Bailey
2024-05-31 14:16:53 +00:00
parent 9778d86607
commit ba42cffcc2
7 changed files with 22 additions and 23 deletions

View File

@@ -307,7 +307,7 @@ class UserStoppedSpeakingFrame(ControlFrame):
@dataclass @dataclass
class TTSStartedFrame(ControlFrame): class TTSStartedFrame(ControlFrame):
"""Used to indicate the beginning of a TTS response. Following """Used to indicate the beginning of a TTS response. Following
AudioRawFrames are part of the TTS response until an TTSEndFrame. These AudioRawFrames are part of the TTS response until an TTSStoppedFrame. These
frames can be used for aggregating audio frames in a transport to optimize frames can be used for aggregating audio frames in a transport to optimize
the size of frames sent to the session, without needing to control this in the size of frames sent to the session, without needing to control this in
the TTS service. the TTS service.

View File

@@ -1,5 +1,5 @@
from typing import List from typing import List
from pipecat.frames.frames import EndFrame, EndPipeFrame from pipecat.frames.frames import EndFrame
from pipecat.pipeline.pipeline import Pipeline from pipecat.pipeline.pipeline import Pipeline
@@ -16,8 +16,7 @@ class SequentialMergePipeline(Pipeline):
while True: while True:
frame = await pipeline.sink.get() frame = await pipeline.sink.get()
if isinstance( if isinstance(
frame, EndFrame) or isinstance( frame, EndFrame):
frame, EndPipeFrame):
break break
await self.sink.put(frame) await self.sink.put(frame)

View File

@@ -1,6 +1,6 @@
import dataclasses import dataclasses
from typing import Text from typing import Text
from pipecat.frames.frames import AudioFrame, Frame, TextFrame, TranscriptionFrame from pipecat.frames.frames import AudioRawFrame, Frame, TextFrame, TranscriptionFrame
import pipecat.frames.protobufs.frames_pb2 as frame_protos import pipecat.frames.protobufs.frames_pb2 as frame_protos
from pipecat.serializers.abstract_frame_serializer import FrameSerializer from pipecat.serializers.abstract_frame_serializer import FrameSerializer
@@ -8,7 +8,7 @@ from pipecat.serializers.abstract_frame_serializer import FrameSerializer
class ProtobufFrameSerializer(FrameSerializer): class ProtobufFrameSerializer(FrameSerializer):
SERIALIZABLE_TYPES = { SERIALIZABLE_TYPES = {
TextFrame: "text", TextFrame: "text",
AudioFrame: "audio", AudioRawFrame: "audio",
TranscriptionFrame: "transcription" TranscriptionFrame: "transcription"
} }

View File

@@ -17,8 +17,8 @@ from functools import partial
from typing import Any, Callable, Mapping from typing import Any, Callable, Mapping
from daily import ( from daily import (
CallClient,
Daily, Daily,
CallClient,
EventHandler, EventHandler,
VirtualCameraDevice, VirtualCameraDevice,
VirtualMicrophoneDevice, VirtualMicrophoneDevice,

View File

@@ -9,9 +9,9 @@ from pipecat.processors.aggregators.gated import GatedAggregator
from pipecat.pipeline.parallel_pipeline import ParallelPipeline from pipecat.pipeline.parallel_pipeline import ParallelPipeline
from pipecat.frames.frames import ( from pipecat.frames.frames import (
AudioFrame, AudioRawFrame,
EndFrame, EndFrame,
ImageFrame, ImageRawFrame,
LLMResponseEndFrame, LLMResponseEndFrame,
LLMResponseStartFrame, LLMResponseStartFrame,
Frame, Frame,
@@ -45,26 +45,26 @@ class TestDailyFrameAggregators(unittest.IsolatedAsyncioTestCase):
async def test_gated_accumulator(self): async def test_gated_accumulator(self):
gated_aggregator = GatedAggregator( gated_aggregator = GatedAggregator(
gate_open_fn=lambda frame: isinstance( gate_open_fn=lambda frame: isinstance(
frame, ImageFrame), gate_close_fn=lambda frame: isinstance( frame, ImageRawFrame), gate_close_fn=lambda frame: isinstance(
frame, LLMResponseStartFrame), start_open=False, ) frame, LLMResponseStartFrame), start_open=False, )
frames = [ frames = [
LLMResponseStartFrame(), LLMResponseStartFrame(),
TextFrame("Hello, "), TextFrame("Hello, "),
TextFrame("world."), TextFrame("world."),
AudioFrame(b"hello"), AudioRawFrame(b"hello", 1, 1),
ImageFrame(b"image", (0, 0)), ImageRawFrame(b"image", (0, 0)),
AudioFrame(b"world"), AudioRawFrame(b"world", 1, 1),
LLMResponseEndFrame(), LLMResponseEndFrame(),
] ]
expected_output_frames = [ expected_output_frames = [
ImageFrame(b"image", (0, 0)), ImageRawFrame(b"image", (0, 0)),
LLMResponseStartFrame(), LLMResponseStartFrame(),
TextFrame("Hello, "), TextFrame("Hello, "),
TextFrame("world."), TextFrame("world."),
AudioFrame(b"hello"), AudioRawFrame(b"hello", 1, 1),
AudioFrame(b"world"), AudioRawFrame(b"world", 1, 1),
LLMResponseEndFrame(), LLMResponseEndFrame(),
] ]
for frame in frames: for frame in frames:

View File

@@ -2,7 +2,7 @@ import asyncio
import unittest import unittest
from unittest.mock import AsyncMock, patch, Mock from unittest.mock import AsyncMock, patch, Mock
from pipecat.frames.frames import AudioFrame, EndFrame, TextFrame, TTSEndFrame, TTSStartFrame from pipecat.frames.frames import AudioRawFrame, EndFrame, TextFrame, TTSStoppedFrame, TTSStartedFrame
from pipecat.pipeline.pipeline import Pipeline from pipecat.pipeline.pipeline import Pipeline
from pipecat.transports.websocket_transport import WebSocketFrameProcessor, WebsocketTransport from pipecat.transports.websocket_transport import WebSocketFrameProcessor, WebsocketTransport
@@ -52,10 +52,10 @@ class TestWebSocketTransportService(unittest.IsolatedAsyncioTestCase):
processor = WebSocketFrameProcessor(audio_frame_size=4) processor = WebSocketFrameProcessor(audio_frame_size=4)
source_frames = [ source_frames = [
TTSStartFrame(), TTSStartedFrame(),
AudioFrame(b"1234"), AudioRawFrame(b"1234", 1, 1),
AudioFrame(b"5678"), AudioRawFrame(b"5678", 1, 1),
TTSEndFrame(), TTSStoppedFrame(),
TextFrame("hello world") TextFrame("hello world")
] ]
@@ -65,9 +65,9 @@ class TestWebSocketTransportService(unittest.IsolatedAsyncioTestCase):
frames.append(output_frame) frames.append(output_frame)
self.assertEqual(len(frames), 3) self.assertEqual(len(frames), 3)
self.assertIsInstance(frames[0], AudioFrame) self.assertIsInstance(frames[0], AudioRawFrame)
self.assertEqual(frames[0].data, b"1234") self.assertEqual(frames[0].data, b"1234")
self.assertIsInstance(frames[1], AudioFrame) self.assertIsInstance(frames[1], AudioRawFrame)
self.assertEqual(frames[1].data, b"5678") self.assertEqual(frames[1].data, b"5678")
self.assertIsInstance(frames[2], TextFrame) self.assertIsInstance(frames[2], TextFrame)
self.assertEqual(frames[2].text, "hello world") self.assertEqual(frames[2].text, "hello world")