From c2c9b4a57c9713ba2846ca305b831bdaab827b39 Mon Sep 17 00:00:00 2001 From: Andrii Ieroshenko Date: Tue, 19 Dec 2023 14:49:57 -0800 Subject: [PATCH] updates per @dlqqq comments --- .../jupyter_ai/chat_handlers/base.py | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/jupyter-ai/jupyter_ai/chat_handlers/base.py b/packages/jupyter-ai/jupyter_ai/chat_handlers/base.py index b694e0413..fa9685509 100644 --- a/packages/jupyter-ai/jupyter_ai/chat_handlers/base.py +++ b/packages/jupyter-ai/jupyter_ai/chat_handlers/base.py @@ -144,24 +144,20 @@ async def handle_exc(self, e: Exception, message: HumanChatMessage): implementation is provided, however chat handlers (subclasses) should implement this method to provide a more helpful error response. """ - self.log.error(e) - if self.config_manager.lm_provider.is_api_key_exc(e): - self.handle_api_key_exc(e, message) - else: - await self._default_handle_exc(e, message) - - def handle_api_key_exc(self, e: Exception, message: HumanChatMessage): - provider_name = "" - if hasattr(self.config_manager, "lm_provider"): - provider_name = getattr(self.config_manager.lm_provider, "name", "") - response = f"Oops! There's a problem connecting to {provider_name}. Please update your {provider_name} API key in the chat settings." - self.reply(response, message) + await self._default_handle_exc(e, message) async def _default_handle_exc(self, e: Exception, message: HumanChatMessage): """ The default definition of `handle_exc()`. This is the default used when the `handle_exc()` excepts. """ + self.log.error(e) + lm_provider = self.config_manager.lm_provider + if lm_provider and lm_provider.is_api_key_exc(e): + provider_name = getattr(self.config_manager.lm_provider, "name", "") + response = f"Oops! There's a problem connecting to {provider_name}. Please update your {provider_name} API key in the chat settings." + self.reply(response, message) + return formatted_e = traceback.format_exc() response = ( f"Sorry, an error occurred. Details below:\n\n```\n{formatted_e}\n```"