processors(rtvi): user decices if bot interrupts on update config
This commit is contained in:
@@ -81,11 +81,6 @@ class RTVIAction(BaseModel):
|
|||||||
return super().model_post_init(__context)
|
return super().model_post_init(__context)
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Client -> Pipecat messages.
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
class RTVIServiceOptionConfig(BaseModel):
|
class RTVIServiceOptionConfig(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
value: Any
|
value: Any
|
||||||
@@ -100,6 +95,16 @@ class RTVIConfig(BaseModel):
|
|||||||
config: List[RTVIServiceConfig]
|
config: List[RTVIServiceConfig]
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Client -> Pipecat messages.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
class RTVIUpdateConfig(BaseModel):
|
||||||
|
config: List[RTVIServiceConfig]
|
||||||
|
interrupt: bool = False
|
||||||
|
|
||||||
|
|
||||||
class RTVIActionRunArgument(BaseModel):
|
class RTVIActionRunArgument(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
value: Any
|
value: Any
|
||||||
@@ -489,8 +494,8 @@ class RTVIProcessor(FrameProcessor):
|
|||||||
case "get-config":
|
case "get-config":
|
||||||
await self._handle_get_config(message.id)
|
await self._handle_get_config(message.id)
|
||||||
case "update-config":
|
case "update-config":
|
||||||
config = RTVIConfig.model_validate(message.data)
|
update_config = RTVIUpdateConfig.model_validate(message.data)
|
||||||
await self._handle_update_config(message.id, config)
|
await self._handle_update_config(message.id, update_config)
|
||||||
case "action":
|
case "action":
|
||||||
action = RTVIActionRun.model_validate(message.data)
|
action = RTVIActionRun.model_validate(message.data)
|
||||||
await self._handle_action(message.id, action)
|
await self._handle_action(message.id, action)
|
||||||
@@ -545,17 +550,14 @@ class RTVIProcessor(FrameProcessor):
|
|||||||
await handler(self, service.name, option)
|
await handler(self, service.name, option)
|
||||||
self._update_config_option(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:
|
for service_config in data.config:
|
||||||
await self._update_service_config(service_config)
|
await self._update_service_config(service_config)
|
||||||
|
|
||||||
async def _handle_update_config(self, request_id: str, data: RTVIConfig):
|
async def _handle_update_config(self, request_id: str, data: RTVIUpdateConfig):
|
||||||
# NOTE(aleix): The bot might be talking while we receive a new
|
await self._update_config(RTVIConfig(config=data.config), data.interrupt)
|
||||||
# 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)
|
|
||||||
await self._handle_get_config(request_id)
|
await self._handle_get_config(request_id)
|
||||||
|
|
||||||
async def _handle_function_call_result(self, data):
|
async def _handle_function_call_result(self, data):
|
||||||
@@ -583,7 +585,7 @@ class RTVIProcessor(FrameProcessor):
|
|||||||
async def _maybe_send_bot_ready(self):
|
async def _maybe_send_bot_ready(self):
|
||||||
if self._pipeline_started and self._client_ready:
|
if self._pipeline_started and self._client_ready:
|
||||||
await self._send_bot_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):
|
async def _send_bot_ready(self):
|
||||||
if not self._params.send_bot_ready:
|
if not self._params.send_bot_ready:
|
||||||
|
|||||||
Reference in New Issue
Block a user