Articles → LANGCHAIN → Call The Huggingface API In Langchain
Call The Huggingface API In Langchain
Install Python Packages
pip install -U huggingface_hub ipywidgets
- huggingface_hub
- ipywidgets
Example
from huggingface_hub import InferenceClientclient = InferenceClient( api_key="your_api_key")response = client.chat_completion( model="meta-llama/Llama-3.1-8B-Instruct", messages=[ { "role": "user", "content": "Explain Artificial Intelligence in simple words." } ], max_tokens=200)print(response.choices[0].message.content)
Output
| Posted By - | Karan Gupta |
| |
| Posted On - | Friday, May 15, 2026 |