-
Notifications
You must be signed in to change notification settings - Fork 19.4k
fix(langchain): correctly initialize huggingface models in init_chat_model #33167
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(langchain): correctly initialize huggingface models in init_chat_model #33167
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaronseq12 thanks for the contribution -- there seem to be a lot of typos in this PR, do you want to try and resolve?
|
@eyurtsev yup got some time free, will be working on this! |
- Move exception messages to variables to satisfy EM101 rule - Use shorter, more concise error messages to satisfy TRY003 rule
|
Linting Issues Fixed I've resolved the Ruff linting errors that were preventing this PR from passing checks: Issues Resolved: EM101 Rule Violations:
TRY003 Rule Violations:
Changes Made:
The PR should now pass all linting checks while maintaining the same functional behavior for HuggingFace model initialization. |
| import_error_msg = "Please install langchain-huggingface to use HuggingFace models." | ||
| raise ImportError(import_error_msg) from e | ||
|
|
||
| # The 'task' kwarg is required by from_model_id but not the base constructor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is only passed to HuggingFacePipeline.from_model_id here, no?
Description:
This change fixes a
ValidationErrorthat occurred when usinginit_chat_modelwithmodel_provider="huggingface".The previous implementation incorrectly passed all keyword arguments directly to the
ChatHuggingFaceconstructor, which expects anllmobject rather than amodel_id. This caused a Pydantic error when arguments liketaskwere provided.The fix updates the logic to first correctly instantiate a
HuggingFacePipelineobject using thefrom_model_idclass method, which properly handles arguments liketask. This initialized pipeline object is then passed to theChatHuggingFacewrapper, resolving the issue.A unit test has been added to verify the fix and prevent regressions.
Closes #28226
Issue:
Fixes #28226
Dependencies:
None