examples: fix simple-chatbot

This commit is contained in:
Aleix Conchillo Flaqué
2024-05-13 13:19:11 -07:00
parent d380b02a44
commit ed31c7924e
6 changed files with 63 additions and 86 deletions

View File

@@ -4,6 +4,8 @@
# SPDX-License-Identifier: BSD 2-Clause License
#
from typing import List
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
from pipecat.frames.frames import (
Frame,
@@ -22,7 +24,7 @@ class LLMResponseAggregator(FrameProcessor):
def __init__(
self,
*,
messages: list[dict] | None,
messages: List[dict],
role: str,
start_frame,
end_frame,
@@ -65,9 +67,6 @@ class LLMResponseAggregator(FrameProcessor):
# and T2 would be dropped.
async def process_frame(self, frame: Frame, direction: FrameDirection):
if not self._messages:
return
send_aggregation = False
if isinstance(frame, self._start_frame):
@@ -116,7 +115,7 @@ class LLMResponseAggregator(FrameProcessor):
class LLMAssistantResponseAggregator(LLMResponseAggregator):
def __init__(self, messages: list[dict]):
def __init__(self, messages: List[dict] = []):
super().__init__(
messages=messages,
role="assistant",
@@ -127,7 +126,7 @@ class LLMAssistantResponseAggregator(LLMResponseAggregator):
class LLMUserResponseAggregator(LLMResponseAggregator):
def __init__(self, messages: list[dict]):
def __init__(self, messages: List[dict] = []):
super().__init__(
messages=messages,
role="user",

View File

@@ -33,7 +33,7 @@ class BaseInputTransport(FrameProcessor):
self._running = True
# Start media threads.
if self._params.audio_in_enabled:
if self._params.audio_in_enabled or self._params.vad_enabled:
self._audio_in_queue = queue.Queue()
self._audio_in_thread = threading.Thread(target=self._audio_in_thread_handler)
self._audio_out_thread = threading.Thread(target=self._audio_out_thread_handler)
@@ -41,7 +41,7 @@ class BaseInputTransport(FrameProcessor):
self._stopped_event = asyncio.Event()
async def start(self):
if self._params.audio_in_enabled:
if self._params.audio_in_enabled or self._params.vad_enabled:
self._audio_in_thread.start()
self._audio_out_thread.start()
@@ -62,7 +62,7 @@ class BaseInputTransport(FrameProcessor):
#
async def cleanup(self):
if self._params.audio_in_enabled:
if self._params.audio_in_enabled or self._params.vad_enabled:
self._audio_in_thread.join()
self._audio_out_thread.join()