Articles → LANGCHAIN → Call The Huggingface API In Langchain

Call The Huggingface API In Langchain






Install Python Packages




pip install -U huggingface_hub ipywidgets




  1. huggingface_hub
  2. 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


Picture showing





Posted By  -  Karan Gupta
 
Posted On  -  Friday, May 15, 2026

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250