huggingface: Undefined model_id fix (#31358)

**Description:** This change fixes the undefined model_id issue when
instantiating
[ChatHuggingFace](https://github.com/langchain-ai/langchain/blob/master/libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py#L306)
**Issue:** Fixes https://github.com/langchain-ai/langchain/issues/31357


@baskaryan @hwchase17
This commit is contained in:
अंkur गोswami 2025-05-30 01:29:35 +05:30 committed by GitHub
parent b7f34749b1
commit 729526ff7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -775,12 +775,12 @@ class ChatHuggingFace(BaseChatModel):
elif _is_huggingface_pipeline(self.llm): elif _is_huggingface_pipeline(self.llm):
from transformers import AutoTokenizer # type: ignore[import] from transformers import AutoTokenizer # type: ignore[import]
self.model_id = self.model_id or self.llm.model_id
self.tokenizer = ( self.tokenizer = (
AutoTokenizer.from_pretrained(self.model_id) AutoTokenizer.from_pretrained(self.model_id)
if self.tokenizer is None if self.tokenizer is None
else self.tokenizer else self.tokenizer
) )
self.model_id = self.llm.model_id
return return
elif _is_huggingface_endpoint(self.llm): elif _is_huggingface_endpoint(self.llm):
self.model_id = self.llm.repo_id or self.llm.model self.model_id = self.llm.repo_id or self.llm.model