fix init_chat_model for Hugging Face models #33786
Open
+18
−2
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.
Description:
This PR fixes a bug where
init_chat_modelfails when used with Hugging Face models. The issue was thatChatHuggingFacerequires anllmobject (such asHuggingFaceEndpoint), but the code was attempting to passmodel_iddirectly.The fix:
HuggingFaceEndpointinstance using the model asrepo_idChatHuggingFace-specific parameters (tokenizer, system_message, custom_get_token_ids, verbose, metadata, tags) fromHuggingFaceEndpointparameters (temperature, max_new_tokens, etc.)HuggingFaceEndpointinstance toChatHuggingFaceas the requiredllmparameterThis change ensures that
init_chat_model("huggingface:microsoft/Phi-3-mini-4k-instruct", temperature=0.7)works correctly by creating the appropriate underlying LLM wrapper thatChatHuggingFaceexpects.Issue:
N/A (bug fix without associated issue)
Dependencies:
No new dependencies. This fix uses existing
langchain_huggingfacepackage imports.