Bug fix: "IndexError: list index out of range" in langchain_openai/embeddings #29150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Title:
langchain_openai: Improve error handling in embeddings/base.py
Description
This PR fixes a bug in the
embeddings/base.py
file where API-related errors were not handled properly. Specifically:IndexError: list index out of range
when the API key was expired or invalid.New behavior:
ValueError: Not enough available money, Please go to recharge.
ValueError: Please check sk-************6GzDaH key from the platform and follow their guidelines.
This ensures clearer and more descriptive error messages for users, and potentially improves handling for other API-related issues.
Issue
No specific GitHub issue is referenced, but the PR addresses improper error handling in
embeddings/base.py
.Dependencies
No additional dependencies are required for this change.
Testing Instructions
Please test the following code with the updated implementation:
Expected results:
Raises:
ValueError: Not enough available money, Please go to recharge.
Raises:
ValueError: Please check sk-************6GzDaH key from the platform and follow their guidelines.