Skip to content

Conversation

@riunyfir
Copy link
Contributor

@riunyfir riunyfir commented Nov 2, 2025

Description:

This PR fixes a bug where init_chat_model fails when used with Hugging Face models. The issue was that ChatHuggingFace requires an llm object (such as HuggingFaceEndpoint), but the code was attempting to pass model_id directly.

The fix:

  • Creates a HuggingFaceEndpoint instance using the model as repo_id
  • Properly separates ChatHuggingFace-specific parameters (tokenizer, system_message, custom_get_token_ids, verbose, metadata, tags) from HuggingFaceEndpoint parameters (temperature, max_new_tokens, etc.)
  • Passes the HuggingFaceEndpoint instance to ChatHuggingFace as the required llm parameter

This 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 that ChatHuggingFace expects.

Issue:

N/A (bug fix without associated issue)

Dependencies:

No new dependencies. This fix uses existing langchain_huggingface package imports.

@github-actions github-actions bot added the langchain Related to the package `langchain` label Nov 2, 2025
Copy link
Collaborator

@ccurme ccurme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Is it possible to do this without dropping support for HuggingFacePipeline models?

@mdrxy mdrxy changed the title fix init_chat_model for Hugging Face models fix: init_chat_model for Hugging Face models Nov 7, 2025
@github-actions github-actions bot added the fix label Nov 7, 2025
@mdrxy
Copy link
Collaborator

mdrxy commented Nov 7, 2025

BTW, this is targeting langchain-classic. It should instead target langchain (in the langchain_v1 folder. We are not adding new features to classic.

@mdrxy
Copy link
Collaborator

mdrxy commented Nov 7, 2025

Please also resolve CI issues

@mdrxy mdrxy changed the title fix: init_chat_model for Hugging Face models fix(langchain): init_chat_model for Hugging Face models Nov 7, 2025
@github-actions github-actions bot added fix and removed fix labels Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix langchain Related to the package `langchain` waiting-on-author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants