Skip to content

Commit

Permalink
use generic api error text with llm id
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-i committed Dec 11, 2023
1 parent affdb36 commit 0838954
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ class BaseChatHandler:

routing_type: HandlerRoutingType = ...

API_KEY_EXCEPTION_RESPONSES = {
OpenAIAuthenticationError: "Oops! It seems there's an issue with your OpenAI API key. Please update your OpenAI API key in the chat Settings. You can find your OpenAI API key at [https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys)."
}
API_KEY_EXCEPTIONS = (OpenAIAuthenticationError,)

def __init__(
self,
Expand Down Expand Up @@ -128,13 +126,11 @@ def is_api_key_error(self, e: Exception):
"""
Checks if the exception is a known API key error.
"""
return isinstance(e, tuple(self.API_KEY_EXCEPTION_RESPONSES.keys()))
return isinstance(e, self.API_KEY_EXCEPTIONS)

def handle_api_key_error(self, e: Exception, message: HumanChatMessage):
response = self.API_KEY_EXCEPTION_RESPONSES.get(
e,
"Oops! It seems there's an issue with your OpenAI API key. Please update your OpenAI API key in the chat Settings. You can find your OpenAI API key at [https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys).",
)
llm_id = f" {self.llm.id}" if self.llm and self.llm.id else ""
response = f"Oops! It seems there's an issue with your{llm_id} API key. Please update your{llm_id} API key in the chat Settings."
self.reply(response, message)

async def _default_handle_exc(self, e: Exception, message: HumanChatMessage):
Expand Down

0 comments on commit 0838954

Please sign in to comment.