From be923687fbcee22a126f93407ca4740d3399c141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Wed, 28 Aug 2024 15:13:27 -0700 Subject: [PATCH] processors(rtvi): user decices if bot interrupts on update config --- src/pipecat/processors/frameworks/rtvi.py | 34 ++++++++++++----------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/pipecat/processors/frameworks/rtvi.py b/src/pipecat/processors/frameworks/rtvi.py index 7ca1c3620..653a883d0 100644 --- a/src/pipecat/processors/frameworks/rtvi.py +++ b/src/pipecat/processors/frameworks/rtvi.py @@ -81,11 +81,6 @@ class RTVIAction(BaseModel): return super().model_post_init(__context) -# -# Client -> Pipecat messages. -# - - class RTVIServiceOptionConfig(BaseModel): name: str value: Any @@ -100,6 +95,16 @@ class RTVIConfig(BaseModel): config: List[RTVIServiceConfig] +# +# Client -> Pipecat messages. +# + + +class RTVIUpdateConfig(BaseModel): + config: List[RTVIServiceConfig] + interrupt: bool = False + + class RTVIActionRunArgument(BaseModel): name: str value: Any @@ -489,8 +494,8 @@ class RTVIProcessor(FrameProcessor): case "get-config": await self._handle_get_config(message.id) case "update-config": - config = RTVIConfig.model_validate(message.data) - await self._handle_update_config(message.id, config) + update_config = RTVIUpdateConfig.model_validate(message.data) + await self._handle_update_config(message.id, update_config) case "action": action = RTVIActionRun.model_validate(message.data) await self._handle_action(message.id, action) @@ -545,17 +550,14 @@ class RTVIProcessor(FrameProcessor): await handler(self, service.name, option) self._update_config_option(service.name, option) - async def _update_config(self, data: RTVIConfig): + async def _update_config(self, data: RTVIConfig, interrupt: bool): + if interrupt: + await self.interrupt_bot() for service_config in data.config: await self._update_service_config(service_config) - async def _handle_update_config(self, request_id: str, data: RTVIConfig): - # NOTE(aleix): The bot might be talking while we receive a new - # config. Let's interrupt it for now and update the config. Another - # solution is to wait until the bot stops speaking and then apply the - # config, but this definitely is more complicated to achieve. - await self.interrupt_bot() - await self._update_config(data) + async def _handle_update_config(self, request_id: str, data: RTVIUpdateConfig): + await self._update_config(RTVIConfig(config=data.config), data.interrupt) await self._handle_get_config(request_id) async def _handle_function_call_result(self, data): @@ -583,7 +585,7 @@ class RTVIProcessor(FrameProcessor): async def _maybe_send_bot_ready(self): if self._pipeline_started and self._client_ready: await self._send_bot_ready() - await self._update_config(self._config) + await self._update_config(self._config, False) async def _send_bot_ready(self): if not self._params.send_bot_ready: