From a355dce139be08af23b3dc97a0d46422253e9f15 Mon Sep 17 00:00:00 2001 From: Tomas Date: Thu, 5 Dec 2024 00:36:21 +0800 Subject: [PATCH] feat: deal with error message for connection failures --- realtime_agent/agent.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/realtime_agent/agent.py b/realtime_agent/agent.py index 88eb895..c334302 100644 --- a/realtime_agent/agent.py +++ b/realtime_agent/agent.py @@ -11,7 +11,7 @@ from agora_realtime_ai_api.rtc import Channel, ChatMessage, RtcEngine, RtcOptions from .logger import setup_logger -from .realtime.struct import FunctionCallOutputItemParam, InputAudioBufferCommitted, InputAudioBufferSpeechStarted, InputAudioBufferSpeechStopped, InputAudioTranscription, ItemCreate, ItemCreated, ItemInputAudioTranscriptionCompleted, RateLimitsUpdated, ResponseAudioDelta, ResponseAudioDone, ResponseAudioTranscriptDelta, ResponseAudioTranscriptDone, ResponseContentPartAdded, ResponseContentPartDone, ResponseCreate, ResponseCreated, ResponseDone, ResponseFunctionCallArgumentsDelta, ResponseFunctionCallArgumentsDone, ResponseOutputItemAdded, ResponseOutputItemDone, ServerVADUpdateParams, SessionUpdate, SessionUpdateParams, SessionUpdated, Voices, to_json +from .realtime.struct import ErrorMessage, FunctionCallOutputItemParam, InputAudioBufferCommitted, InputAudioBufferSpeechStarted, InputAudioBufferSpeechStopped, InputAudioTranscription, ItemCreate, ItemCreated, ItemInputAudioTranscriptionCompleted, RateLimitsUpdated, ResponseAudioDelta, ResponseAudioDone, ResponseAudioTranscriptDelta, ResponseAudioTranscriptDone, ResponseContentPartAdded, ResponseContentPartDone, ResponseCreate, ResponseCreated, ResponseDone, ResponseFunctionCallArgumentsDelta, ResponseFunctionCallArgumentsDone, ResponseOutputItemAdded, ResponseOutputItemDone, ServerVADUpdateParams, SessionUpdate, SessionUpdateParams, SessionUpdated, Voices, to_json from .realtime.connection import RealtimeApiConnection from .tools import ClientToolCallResponse, ToolContext from .utils import PCMWriter @@ -109,9 +109,14 @@ async def setup_and_run_agent( start_session_message = await anext(connection.listen()) # assert isinstance(start_session_message, messages.StartSession) - logger.info( - f"Session started: {start_session_message.session.id} model: {start_session_message.session.model}" - ) + if isinstance(start_session_message, SessionUpdated): + logger.info( + f"Session started: {start_session_message.session.id} model: {start_session_message.session.model}" + ) + elif isinstance(start_session_message, ErrorMessage): + logger.info( + f"Error: {start_session_message.error}" + ) agent = cls( connection=connection,