Merge pull request #1050 from pipecat-ai/fix_rtvi_warning_msg
Ignoring transport messages that are not intended to RTVI.
This commit is contained in:
@@ -62,6 +62,9 @@ from pipecat.utils.string import match_endofsentence
|
|||||||
|
|
||||||
RTVI_PROTOCOL_VERSION = "0.3.0"
|
RTVI_PROTOCOL_VERSION = "0.3.0"
|
||||||
|
|
||||||
|
RTVI_MESSAGE_LABEL = "rtvi-ai"
|
||||||
|
RTVIMessageLiteral = Literal["rtvi-ai"]
|
||||||
|
|
||||||
ActionResult = Union[bool, int, float, str, list, dict]
|
ActionResult = Union[bool, int, float, str, list, dict]
|
||||||
|
|
||||||
|
|
||||||
@@ -154,7 +157,7 @@ class RTVIActionFrame(DataFrame):
|
|||||||
|
|
||||||
|
|
||||||
class RTVIMessage(BaseModel):
|
class RTVIMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: str
|
type: str
|
||||||
id: str
|
id: str
|
||||||
data: Optional[Dict[str, Any]] = None
|
data: Optional[Dict[str, Any]] = None
|
||||||
@@ -170,7 +173,7 @@ class RTVIErrorResponseData(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class RTVIErrorResponse(BaseModel):
|
class RTVIErrorResponse(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["error-response"] = "error-response"
|
type: Literal["error-response"] = "error-response"
|
||||||
id: str
|
id: str
|
||||||
data: RTVIErrorResponseData
|
data: RTVIErrorResponseData
|
||||||
@@ -182,7 +185,7 @@ class RTVIErrorData(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class RTVIError(BaseModel):
|
class RTVIError(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["error"] = "error"
|
type: Literal["error"] = "error"
|
||||||
data: RTVIErrorData
|
data: RTVIErrorData
|
||||||
|
|
||||||
@@ -192,7 +195,7 @@ class RTVIDescribeConfigData(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class RTVIDescribeConfig(BaseModel):
|
class RTVIDescribeConfig(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["config-available"] = "config-available"
|
type: Literal["config-available"] = "config-available"
|
||||||
id: str
|
id: str
|
||||||
data: RTVIDescribeConfigData
|
data: RTVIDescribeConfigData
|
||||||
@@ -203,14 +206,14 @@ class RTVIDescribeActionsData(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class RTVIDescribeActions(BaseModel):
|
class RTVIDescribeActions(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["actions-available"] = "actions-available"
|
type: Literal["actions-available"] = "actions-available"
|
||||||
id: str
|
id: str
|
||||||
data: RTVIDescribeActionsData
|
data: RTVIDescribeActionsData
|
||||||
|
|
||||||
|
|
||||||
class RTVIConfigResponse(BaseModel):
|
class RTVIConfigResponse(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["config"] = "config"
|
type: Literal["config"] = "config"
|
||||||
id: str
|
id: str
|
||||||
data: RTVIConfig
|
data: RTVIConfig
|
||||||
@@ -221,7 +224,7 @@ class RTVIActionResponseData(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class RTVIActionResponse(BaseModel):
|
class RTVIActionResponse(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["action-response"] = "action-response"
|
type: Literal["action-response"] = "action-response"
|
||||||
id: str
|
id: str
|
||||||
data: RTVIActionResponseData
|
data: RTVIActionResponseData
|
||||||
@@ -233,7 +236,7 @@ class RTVIBotReadyData(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class RTVIBotReady(BaseModel):
|
class RTVIBotReady(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["bot-ready"] = "bot-ready"
|
type: Literal["bot-ready"] = "bot-ready"
|
||||||
id: str
|
id: str
|
||||||
data: RTVIBotReadyData
|
data: RTVIBotReadyData
|
||||||
@@ -246,7 +249,7 @@ class RTVILLMFunctionCallMessageData(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class RTVILLMFunctionCallMessage(BaseModel):
|
class RTVILLMFunctionCallMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["llm-function-call"] = "llm-function-call"
|
type: Literal["llm-function-call"] = "llm-function-call"
|
||||||
data: RTVILLMFunctionCallMessageData
|
data: RTVILLMFunctionCallMessageData
|
||||||
|
|
||||||
@@ -256,7 +259,7 @@ class RTVILLMFunctionCallStartMessageData(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class RTVILLMFunctionCallStartMessage(BaseModel):
|
class RTVILLMFunctionCallStartMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["llm-function-call-start"] = "llm-function-call-start"
|
type: Literal["llm-function-call-start"] = "llm-function-call-start"
|
||||||
data: RTVILLMFunctionCallStartMessageData
|
data: RTVILLMFunctionCallStartMessageData
|
||||||
|
|
||||||
@@ -269,22 +272,22 @@ class RTVILLMFunctionCallResultData(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class RTVIBotLLMStartedMessage(BaseModel):
|
class RTVIBotLLMStartedMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["bot-llm-started"] = "bot-llm-started"
|
type: Literal["bot-llm-started"] = "bot-llm-started"
|
||||||
|
|
||||||
|
|
||||||
class RTVIBotLLMStoppedMessage(BaseModel):
|
class RTVIBotLLMStoppedMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["bot-llm-stopped"] = "bot-llm-stopped"
|
type: Literal["bot-llm-stopped"] = "bot-llm-stopped"
|
||||||
|
|
||||||
|
|
||||||
class RTVIBotTTSStartedMessage(BaseModel):
|
class RTVIBotTTSStartedMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["bot-tts-started"] = "bot-tts-started"
|
type: Literal["bot-tts-started"] = "bot-tts-started"
|
||||||
|
|
||||||
|
|
||||||
class RTVIBotTTSStoppedMessage(BaseModel):
|
class RTVIBotTTSStoppedMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["bot-tts-stopped"] = "bot-tts-stopped"
|
type: Literal["bot-tts-stopped"] = "bot-tts-stopped"
|
||||||
|
|
||||||
|
|
||||||
@@ -293,19 +296,19 @@ class RTVITextMessageData(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class RTVIBotTranscriptionMessage(BaseModel):
|
class RTVIBotTranscriptionMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["bot-transcription"] = "bot-transcription"
|
type: Literal["bot-transcription"] = "bot-transcription"
|
||||||
data: RTVITextMessageData
|
data: RTVITextMessageData
|
||||||
|
|
||||||
|
|
||||||
class RTVIBotLLMTextMessage(BaseModel):
|
class RTVIBotLLMTextMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["bot-llm-text"] = "bot-llm-text"
|
type: Literal["bot-llm-text"] = "bot-llm-text"
|
||||||
data: RTVITextMessageData
|
data: RTVITextMessageData
|
||||||
|
|
||||||
|
|
||||||
class RTVIBotTTSTextMessage(BaseModel):
|
class RTVIBotTTSTextMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["bot-tts-text"] = "bot-tts-text"
|
type: Literal["bot-tts-text"] = "bot-tts-text"
|
||||||
data: RTVITextMessageData
|
data: RTVITextMessageData
|
||||||
|
|
||||||
@@ -317,7 +320,7 @@ class RTVIAudioMessageData(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class RTVIBotTTSAudioMessage(BaseModel):
|
class RTVIBotTTSAudioMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["bot-tts-audio"] = "bot-tts-audio"
|
type: Literal["bot-tts-audio"] = "bot-tts-audio"
|
||||||
data: RTVIAudioMessageData
|
data: RTVIAudioMessageData
|
||||||
|
|
||||||
@@ -330,39 +333,39 @@ class RTVIUserTranscriptionMessageData(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class RTVIUserTranscriptionMessage(BaseModel):
|
class RTVIUserTranscriptionMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["user-transcription"] = "user-transcription"
|
type: Literal["user-transcription"] = "user-transcription"
|
||||||
data: RTVIUserTranscriptionMessageData
|
data: RTVIUserTranscriptionMessageData
|
||||||
|
|
||||||
|
|
||||||
class RTVIUserLLMTextMessage(BaseModel):
|
class RTVIUserLLMTextMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["user-llm-text"] = "user-llm-text"
|
type: Literal["user-llm-text"] = "user-llm-text"
|
||||||
data: RTVITextMessageData
|
data: RTVITextMessageData
|
||||||
|
|
||||||
|
|
||||||
class RTVIUserStartedSpeakingMessage(BaseModel):
|
class RTVIUserStartedSpeakingMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["user-started-speaking"] = "user-started-speaking"
|
type: Literal["user-started-speaking"] = "user-started-speaking"
|
||||||
|
|
||||||
|
|
||||||
class RTVIUserStoppedSpeakingMessage(BaseModel):
|
class RTVIUserStoppedSpeakingMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["user-stopped-speaking"] = "user-stopped-speaking"
|
type: Literal["user-stopped-speaking"] = "user-stopped-speaking"
|
||||||
|
|
||||||
|
|
||||||
class RTVIBotStartedSpeakingMessage(BaseModel):
|
class RTVIBotStartedSpeakingMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["bot-started-speaking"] = "bot-started-speaking"
|
type: Literal["bot-started-speaking"] = "bot-started-speaking"
|
||||||
|
|
||||||
|
|
||||||
class RTVIBotStoppedSpeakingMessage(BaseModel):
|
class RTVIBotStoppedSpeakingMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["bot-stopped-speaking"] = "bot-stopped-speaking"
|
type: Literal["bot-stopped-speaking"] = "bot-stopped-speaking"
|
||||||
|
|
||||||
|
|
||||||
class RTVIMetricsMessage(BaseModel):
|
class RTVIMetricsMessage(BaseModel):
|
||||||
label: Literal["rtvi-ai"] = "rtvi-ai"
|
label: RTVIMessageLiteral = RTVI_MESSAGE_LABEL
|
||||||
type: Literal["metrics"] = "metrics"
|
type: Literal["metrics"] = "metrics"
|
||||||
data: Mapping[str, Any]
|
data: Mapping[str, Any]
|
||||||
|
|
||||||
@@ -875,7 +878,11 @@ class RTVIProcessor(FrameProcessor):
|
|||||||
|
|
||||||
async def _handle_transport_message(self, frame: TransportMessageUrgentFrame):
|
async def _handle_transport_message(self, frame: TransportMessageUrgentFrame):
|
||||||
try:
|
try:
|
||||||
message = RTVIMessage.model_validate(frame.message)
|
transport_message = frame.message
|
||||||
|
if transport_message.get("label") != RTVI_MESSAGE_LABEL:
|
||||||
|
logger.warning(f"Ignoring not RTVI message: {transport_message}")
|
||||||
|
return
|
||||||
|
message = RTVIMessage.model_validate(transport_message)
|
||||||
await self._message_queue.put(message)
|
await self._message_queue.put(message)
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
await self.send_error(f"Invalid RTVI transport message: {e}")
|
await self.send_error(f"Invalid RTVI transport message: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user