Example

from phi.agent import Agent, RunResponse
from phi.model.huggingface import HuggingFaceChat

agent = Agent(
    model=HuggingFaceChat(
        id="meta-llama/Meta-Llama-3-8B-Instruct",
        max_tokens=4096,
    ),
    markdown=True
)

# Get the response in a variable
# run: RunResponse = agent.run("Share a 2 sentence horror story.")
# print(run.content)

# Print the response on the terminal
agent.print_response("Share a 2 sentence horror story.")

Usage

Get your API key from HuggingFace here.

1

Create a virtual environment

Open the Terminal and create a python virtual environment.

python3 -m venv ~/.venvs/aienv
source ~/.venvs/aienv/bin/activate
2

Install libraries

pip install -U huggingface_hub phidata
3

Export Environment Variables

export HF_TOKEN=***
4

Run HuggingFace Agent

python cookbook/providers/huggingface/basic.py

Information