Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve API key error handling #530

Open
andrii-i opened this issue Dec 19, 2023 · 1 comment
Open

Improve API key error handling #530

andrii-i opened this issue Dec 19, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@andrii-i
Copy link
Collaborator

andrii-i commented Dec 19, 2023

Problem

API key error handling can be further improved:

My high-level thought is that while this is a good starting point, this strategy is a little unintuitive. It requires manually detecting and handling API key exceptions. In the future, we should probably wrap the LangChain methods in an exception handler that raises some custom ApiKeyInvalid exception in this case. That way, we show the same error message in magics and in chat.

Originally posted by @dlqqq in #513 (comment)

Proposed solution

Implement API key error handling as described above.

@andrii-i andrii-i added the enhancement New feature or request label Dec 19, 2023
@andrii-i andrii-i changed the title Improve API error handling Improve API key error handling Dec 19, 2023
@andrii-i
Copy link
Collaborator Author

andrii-i commented Dec 20, 2023

@dlqqq Looked a little bit into this suggestion. Each LLM raises API key error in its own way using different error types and error messages. Exception handler that would wrap the LangChain methods and would raise some custom ApiKeyInvalid exception would still need to detect that exception is an API key error "manually".

For example, below is how we could wrap langchain methods that throw API key errors, get_llm_chain and self.llm_chain.apredict of DefaultChatHandler.process_message. Note that self.is_api_exception(e) or some other form of "manual" detection is still needed for API error identification which makes this approach less of an improvement. What do you think?

    async def process_message(self, message: HumanChatMessage):
        try:
            self.get_llm_chain()
            response = await self.llm_chain.apredict(
                input=message.body, stop=["\nHuman:"]
            )
            self.reply(response, message)
        except Exception as e:
            if self.is_api_exception(e):
                raise APIExceptionError(e)
            else:
                raise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant