From 30a3b24287017cbbcb2f1e22f4e431a932cdff82 Mon Sep 17 00:00:00 2001 From: carolin-tavus Date: Thu, 3 Jul 2025 14:02:54 +0000 Subject: [PATCH 1/2] Add persona validation (check that microphone is enabled) --- src/pipecat/transports/services/tavus.py | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/pipecat/transports/services/tavus.py b/src/pipecat/transports/services/tavus.py index 10ae001e0..4e8ab208a 100644 --- a/src/pipecat/transports/services/tavus.py +++ b/src/pipecat/transports/services/tavus.py @@ -126,6 +126,31 @@ class TavusApi: response = await r.json() logger.debug(f"Fetched Tavus persona: {response}") return response["persona_name"] + + async def _validate_persona(self, persona_id: str): + """Validate that the persona's microphone is enabled. + + Args: + persona_id: ID of the persona to validate. + """ + if self._dev_room_url is not None: + return + + url = f"{self.BASE_URL}/personas/{persona_id}" + async with self._session.get(url, headers=self._headers) as r: + r.raise_for_status() + response = await r.json() + logger.debug(f"Fetched Tavus persona: {response}") + try: + transport_settings = response.get("layers", {}).get("transport", {}) + microphone_enabled = transport_settings.get("input_settings", {}).get("microphone", "") + if microphone_enabled != "enabled": + raise Exception("Microphone is not enabled for this persona. Please update the persona or use the persona pipecat-stream.") + except Exception as e: + logger.error(f"Error validating persona {persona_id}: {e}") + raise e + logger.info(f"Persona {persona_id} is valid") + return True class TavusCallbacks(BaseModel): @@ -200,6 +225,7 @@ class TavusTransportClient: async def _initialize(self) -> str: """Initialize the conversation and return the room URL.""" + await self._api._validate_persona(self._persona_id) response = await self._api.create_conversation(self._replica_id, self._persona_id) self._conversation_id = response["conversation_id"] return response["conversation_url"] From cb81f3d50e0fd3253dd8ea797be5a74563fda2e4 Mon Sep 17 00:00:00 2001 From: carolin-tavus Date: Thu, 3 Jul 2025 14:38:20 +0000 Subject: [PATCH 2/2] format --- src/pipecat/transports/services/tavus.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pipecat/transports/services/tavus.py b/src/pipecat/transports/services/tavus.py index 4e8ab208a..060c0ec61 100644 --- a/src/pipecat/transports/services/tavus.py +++ b/src/pipecat/transports/services/tavus.py @@ -126,10 +126,10 @@ class TavusApi: response = await r.json() logger.debug(f"Fetched Tavus persona: {response}") return response["persona_name"] - + async def _validate_persona(self, persona_id: str): """Validate that the persona's microphone is enabled. - + Args: persona_id: ID of the persona to validate. """ @@ -143,9 +143,13 @@ class TavusApi: logger.debug(f"Fetched Tavus persona: {response}") try: transport_settings = response.get("layers", {}).get("transport", {}) - microphone_enabled = transport_settings.get("input_settings", {}).get("microphone", "") + microphone_enabled = transport_settings.get("input_settings", {}).get( + "microphone", "" + ) if microphone_enabled != "enabled": - raise Exception("Microphone is not enabled for this persona. Please update the persona or use the persona pipecat-stream.") + raise Exception( + "Microphone is not enabled for this persona. Please update the persona or use the persona pipecat-stream." + ) except Exception as e: logger.error(f"Error validating persona {persona_id}: {e}") raise e