-
Notifications
You must be signed in to change notification settings - Fork 16.3k
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
langchain_community: add error handling in HuggingFaceInferenceAPIEmbeddings #29792
Closed
brian-ogrady
wants to merge
8
commits into
langchain-ai:master
from
brian-ogrady:add-hf-api-error-check
Closed
langchain_community: add error handling in HuggingFaceInferenceAPIEmbeddings #29792
brian-ogrady
wants to merge
8
commits into
langchain-ai:master
from
brian-ogrady:add-hf-api-error-check
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
wasn't registered per the contribution guide: https://python.langchain.com/docs/contributing/how_to/integrations/
These appear to pass.
Removing trailing whitespace from newline Linting a bit more :q Even more linting Lint + test failure Trailing commas, linting indentation Call me lintman Gonna have to squash these commits eventually Gonna have to squash these commits eventually again Gonna have to squash these commits eventually again again fix fix fix fix
5026f3b
to
aaf105e
Compare
woops! @efriis please ignore this last commit here. Accidentally committed some unstaged changes when squashing my commits. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
community
Related to langchain-community
Ɑ: embeddings
Related to text embedding models module
size:L
This PR changes 100-499 lines, ignoring generated files.
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.
When using a custom HuggingFace API Endpoint there can be an error in the JSON response. I propose added two checks when calling the
embed_documents
method of theHuggingFaceInferenceAPIEmbeddings
class:JSONDecodeError
While working with the
![Screenshot 2025-02-13 at 5 04 36 PM](https://private-user-images.githubusercontent.com/181596055/413080377-0901728a-a865-432a-88d4-9477ef12d8db.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MTQyMzksIm5iZiI6MTczOTYxMzkzOSwicGF0aCI6Ii8xODE1OTYwNTUvNDEzMDgwMzc3LTA5MDE3MjhhLWE4NjUtNDMyYS04OGQ0LTk0NzdlZjEyZDhkYi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNVQxMDA1MzlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0xMGUxZDI5YjgzNDk5ZTdmMjc0YjgyODcyZjM1Nzg5OTU0NTllODhiMWY1ZTI0Njk1MzhmODQzZTc0YzcwZmQ5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.WnN7DDB2iECNmnc7B7yecfoF-U9VlNKH9s23J81gy8I)
HuggingFaceInferenceAPIEmbeddings
class, I sometimes receive a nebulous errorValueError: could not convert string to float: 'e'
This results because the
embed_documents
method, which is called during the execution of theadd_documents
method of a vector store, can return a JSON response like the following:{'error': 'Input validation error:
inputscannot be empty', 'error_type': 'Validation'}
The initial
ValueError
raised fromadd_documents
is misleading because it makes the underlying error returned in the JSON response. I propose surfacing this error by adding a check duringembed_documents
to return the JSON error in a Pythonic manner.I have detailed this request in the discussions.
If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.