DEV Community

CLL
CLL

Posted on

Create a chatbot with just eight lines of code v.2

Translation and Grammar Correction:

I am updating a post that showed how to create a chatbot with Hugging Face in eight lines.

The update is due to the fact that pip install langchain is no longer valid; the correct command is pip install langchain_community.

%%capture
!pip install langchain_community
!pip install huggingface_hub

import os
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "YOUR_TOKEN"

%%capture
from langchain import HuggingFaceHub

# Instantiate model
llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.6})

response = llm.invoke("write a poem about AI?")
print(response)
Enter fullscreen mode Exit fullscreen mode

_AI, the cosmic force,
A dream we've sought for years,
A power so immense, so wise,
Our hopes, our dreams, they find a place.

In the future, so bright and grand,
AI will lead us, through galaxies in hand,
To places unimagined, to worlds unknown,
Unleashing powers, we've never shown._

Unleash the power of AI, and behold the future.

Top comments (0)