Skip to content

Commit 0dd027d

Browse files
Add HuggingFace chat model integration examples (#1522)
**Type:** Update existing documentation ## Related issues/PRs Related to langchain-ai/langchain#28226 ## Description Adds HuggingFace chat model integration examples to the chat-model-tabs.mdx snippet file. **Includes:** - Installation instructions for langchain[huggingface] - init_chat_model example with HuggingFace provider - Direct model class usage with HuggingFaceEndpoint and ChatHuggingFace - Uses microsoft/Phi-3-mini-4k-instruct as the example model This provides users with a clear example of how to use init_chat_model with HuggingFace models, addressing the documentation gap mentioned in issue #28226.
1 parent bf08b1c commit 0dd027d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/snippets/chat-model-tabs.mdx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,43 @@
134134
model = ChatBedrock(model="anthropic.claude-3-5-sonnet-20240620-v1:0")
135135
```
136136
</CodeGroup>
137+
138+
<Tab title="HuggingFace">
139+
👉 Read the [HuggingFace chat model integration docs](/oss/python/integrations/chat/huggingface/)
140+
141+
```shell
142+
pip install -U "langchain[huggingface]"
143+
```
144+
145+
<CodeGroup>
146+
```python init_chat_model
147+
import os
148+
from langchain.chat_models import init_chat_model
149+
150+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "hf_..."
151+
152+
model = init_chat_model(
153+
"microsoft/Phi-3-mini-4k-instruct",
154+
model_provider="huggingface",
155+
temperature=0.7,
156+
max_tokens=1024,
157+
)
158+
```
159+
160+
```python Model Class
161+
import os
162+
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
163+
164+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "hf_..."
165+
166+
llm = HuggingFaceEndpoint(
167+
repo_id="microsoft/Phi-3-mini-4k-instruct",
168+
temperature=0.7,
169+
max_length=1024,
170+
)
171+
model = ChatHuggingFace(llm=llm)
172+
```
173+
</CodeGroup>
174+
</Tab>
137175
</Tab>
138176
</Tabs>

0 commit comments

Comments
 (0)