Skip to content

Commit

Permalink
updates per @dlqqq comments
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-i committed Dec 19, 2023
1 parent 1684cf6 commit c2c9b4a
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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```"
Expand Down

0 comments on commit c2c9b4a

Please sign in to comment.