From 07f4cb0dbbb501db4a69b0ddf5f030bec57e32e6 Mon Sep 17 00:00:00 2001 From: Anuj Verma Date: Sun, 22 Jun 2025 13:12:59 +0530 Subject: [PATCH] fix(exception): Exception handling if model access is not proper --- chatbot/utils.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/chatbot/utils.py b/chatbot/utils.py index 53b5137..a887e6d 100644 --- a/chatbot/utils.py +++ b/chatbot/utils.py @@ -134,10 +134,15 @@ def read_agent_response(event_stream): data = event['chunk']['bytes'] agent_answer = data.decode('utf8') elif 'trace' in event: - print(f"orchestration trace = {event['trace']['trace']['orchestrationTrace']}") - if 'observation' in event['trace']['trace']['orchestrationTrace']: - if event['trace']['trace']['orchestrationTrace']['observation']['type'] == "ASK_USER": - ask_user = True + tr = event['trace']['trace'] # Trace object in seperate variable + orch = tr.get('orchestrationTrace') # Trying to get orchestrationTrace from trace. Diretly calling orchestrationTrace from trace was throwing exception if model access was not properly provided + if orch: + print(f"orchestration trace = {event['trace']['trace']['orchestrationTrace']}") # This line was throwing key error on orchestrationTrace, if model access is not valid, fixed in above line + if 'observation' in event['trace']['trace']['orchestrationTrace']: + if event['trace']['trace']['orchestrationTrace']['observation']['type'] == "ASK_USER": + ask_user = True + else: + ask_user = False else: ask_user = False else: