Prerequisites
- Sign up for a Hugging Face account
- Create a Hugging Face API token
Setup
- Add the Hugging Face API token to your environment variables
.env
- The Starter-Kit already includes the necessary configuration for Hugging Face in
src/lib/ai/huggingface.ts
, if you have selected the Hugging Face Provider via the CLI. This file initializes the Hugging Face client with your API token.
Usage
To use Hugging Face AI in your application, you can create an API route that interacts with the Hugging Face client. This route can be used to generate images, text, and more using the AI models provided by Hugging Face. Create a new file in your API routes directory (e.g.,app/api/huggingface/route.ts
). You can use the Hugging Face client to interact with the AI models and generate the desired output.
Here’s an example of how to set up a route that uses the Llama 3.2 1B model to generate text:
textGeneration
method from the Hugging Face client to generate text using the Llama model. You can replace the model and inputs with your desired model and prompt.