fix: incorrect HuggingFace initialization in init_chat_model #34000
+54
−3
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.
Summary
This PR fixes a bug in the HuggingFace backend of init_chat_model where all kwargs were passed directly to HuggingFacePipeline.from_model_id().
This caused validation errors such as:
Validation Error
Root Cause
The previous implementation passed parameters like temperature, max_tokens, timeout, etc. to HuggingFacePipeline, which does not accept these arguments.
As a result, Pydantic validation inside ChatHuggingFace failed.
What this PR fixes
If no task is provided, we set:
🛠️ Added Default Task for Decoder-Only Models
Allowed params:
{"task", "model_kwargs", "device"}Other parameters (temperature, max_tokens, etc.) are ignored for the pipeline and used only by LangChain.
Before
This sent all kwargs → leading to ValidationError.
After (Fixed)
Example Code That Now Works
Test Case:
Result
The HuggingFace initialization now correctly separates pipeline parameters and LangChain LLM settings, preventing validation errors.