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

Fix Exception #21

Merged
merged 7 commits into from
Sep 13, 2024
Merged

Fix Exception #21

merged 7 commits into from
Sep 13, 2024

Conversation

yiranwu0
Copy link
Collaborator

@yiranwu0 yiranwu0 commented Sep 2, 2024

Why are these changes needed?

Fix exceptions of non-OpenAI generations:

  1. Remove meaningless exceptions that just catches the error and throw it. This also adds confusion to debugging when an error happens.
  2. Remove retries: Some retries are also useless. If we catch any errors and throw it, the retry is not needed. If no error is caught, we don't need retry.

Fix Gemini retry:

  1. Remove retry in GeminiClient. It should be in OpenAIWrapper.
  2. OpenAIWrapper only catches OpenAI rate limits. This PR adds catches of google's rate limits so that different keys can be tried.

Future todo:

  1. Add exception catches of non-openai models to OpenAIWrapper. Currently only gemini is added.
  2. (Optional Feature): Add a wait time option for OpenAIWrapper to wait out the rate limits.

Related issue number

Checks

@Hk669
Copy link
Collaborator

Hk669 commented Sep 2, 2024

thanks @yiranwu0 for the changes. can you confirm if the updated code is working as expected with all the clients. have you tested it? if not @marklysze and i can give it a try.

cc @marklysze

@marklysze
Copy link
Collaborator

LGTM. @marklysze could you take a look too?

Yep, I'll have a look and test now.

@marklysze
Copy link
Collaborator

marklysze commented Sep 5, 2024

Thanks for raising this PR @yiranwu0, better bubbling of exceptions and centralised retries is definitely needed with all the client classes in place.

From what I understand from the code changes, the client-specific exceptions are added to client.py and then handled in the try/except around the client.create(params). Then it's logged and raised if it's the last client.

I was testing with Bedrock and checked out the exceptions that could be raised, and there's quite a lot of possible exceptions (boto and aws exceptions and click Click to see a full list of static exceptions). So, I was wondering whether, rather than trying to add each client's full list of exceptions into client.py and catch them, would it be possible to create either a generic ClientException class or an exception class in each client class (e.g. BedrockClientException, GeminiClientException) and then raise that, if we want to handle client-specific exceptions. Other options are to create our own set of exceptions for specific common scenarios, like ClientRateLimitException, and then we raise those specific ones from the client class and any others can be generic, like ClientException.

Amazon Bedrock is probably going to be the one with the most exceptions, though Anthropic with Bedrock may also have a few. Additionally, some exceptions may have the same name, so if we continue with the proposed approach then perhaps we should prefix them, e.g. InternalServerError becomes GeminiInternalServerError.

Let me know what you think...

@yiranwu0
Copy link
Collaborator Author

yiranwu0 commented Sep 7, 2024

Hello @marklysze, thank you for testing it!
I don't think we need to attend to all exceptions from different clients, we only want to catch the few "time rate limits" exception and handle that in client.py because we can try different configs. For other exceptions, I think we should raise the original exception, so that user can debug from that, or search online.

However, I think it is good if we can have all the rate limit exceptions wrapped in an exception of our own, so that we only need to catch one exception. But that needs more thinking and could be done in the next PR.

@marklysze
Copy link
Collaborator

Thanks @yiranwu0, sounds like a plan! I'll look at the rest of the client classes and test :)

…here stop error, removed try/except for Ollama
@marklysze
Copy link
Collaborator

Hey @yiranwu0, I've updated the code as follows:

  • Removed try/except from Ollama client
  • Added main exceptions for non-OpenAI clients into client.py
  • Prefixed exceptions with the client name, e.g. gemini_InternalServerError and anthorpic_InternalServerError, to avoid conflicts
  • Changed variables for exceptions in ImportError to be of type Exception instead of None as None can't be used in an except clause. Also moved the except clause to the end of the three exception blocks.
  • Tested non-function and function workflows with the following (to ensure they are still working): Anthorpic, Cohere, Groq, Mistral, Ollama, Together.AI. (I haven't tested Gemini).
  • Added a note for users to also install fix-busted-json if trying to use the Ollama client.

It caught exceptions when they arose. Though I can't test all exceptions.

@yiranwu0
Copy link
Collaborator Author

Hello @marklysze, your change looks good! I already tested Gemini. If there are good, we can merge it!

@marklysze
Copy link
Collaborator

Hello @marklysze, your change looks good! I already tested Gemini. If there are good, we can merge it!

Okay, great... I'm good with it!

Copy link
Collaborator

@Hk669 Hk669 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. Thanks @yiranwu0 and @marklysze

@sonichi sonichi merged commit 6712b64 into main Sep 13, 2024
146 of 153 checks passed
@sonichi sonichi deleted the fixexception branch September 13, 2024 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants