fix(langchain-classic): fix init_chat_model for HuggingFace models #33943
+107
−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.
Fixes #28226
The issue was that init_chat_model didn't properly handle HuggingFace model initialization. The main problems were:
HuggingFacePipeline.from_model_id requires a 'task' parameter, but it wasn't being provided (defaults to 'text-generation' for chat models)
Parameters needed to be properly separated between HuggingFacePipeline and ChatHuggingFace - generation parameters (temperature, max_tokens, etc.) should go to pipeline_kwargs, while other parameters (timeout, max_retries) should go to ChatHuggingFace
max_tokens needs to be mapped to max_new_tokens for HuggingFace pipeline
Changes:
(Replace this entire block of text)
Thank you for contributing to LangChain! Follow these steps to mark your pull request as ready for review. If any of these steps are not completed, your PR will not be considered for review.
PR title: Follows the format: {TYPE}({SCOPE}): {DESCRIPTION}
{TYPE}values:{SCOPE}values (optional):PR message: Delete this entire checklist and replace with
Lint and test: Run
make format,make lintandmake testfrom the root of the package(s) you've modified. We will not consider a PR unless these three are passing in CI. See contribution guidelines for more.Additional guidelines:
pyproject.tomlfiles (even optional ones) unless they are required for unit tests. Likewise, please do not update theuv.lockfiles unless you are adding a required dependency.