title | emoji | colorFrom | colorTo | sdk | pinned |
---|---|---|---|---|---|
Chat Ui |
📚 |
purple |
blue |
docker |
false |
Find the docs at hf.co/docs/chat-ui.
A chat interface using open source models, eg OpenAssistant or Llama. It is a SvelteKit app and it powers the HuggingChat app on hf.co/chat.
- Quickstart
- No Setup Deploy
- Setup
- Launch
- Extra parameters
- Common issues
- Deploying to a HF Space
- Building
- Config changes for HuggingChat
- Populate database
- Building the docker images locally
Note on models in this build: This branch only supports OpenAI-compatible APIs via
OPENAI_BASE_URL
and the/models
endpoint. The legacyMODELS
env var, GGUF discovery, llama.cpp/TGI/Ollama/provider-specific endpoints, and embedding/web-search features are removed.
You can deploy a chat-ui instance in a single command using the docker image. Get your Hugging Face token from here if you plan to use the HF router.
docker run \
-p 3000 \
-e MONGODB_URL=mongodb://host.docker.internal:27017 \
-e OPENAI_BASE_URL=https://router.huggingface.co/v1 \
-e OPENAI_API_KEY=hf_*** \
-v db:/data \
ghcr.io/huggingface/chat-ui-db:latest
Take a look at the .env
file for all environment variables. In this build, only OpenAI-compatible endpoints are supported via OPENAI_BASE_URL
and OPENAI_API_KEY
(with HF_TOKEN
supported as a legacy alias). Other providers are not available.
Note: This build is OpenAI-compatible only. Local llama.cpp, TGI, Ollama and other provider endpoints are disabled.
Step 1 (make sure you have MongoDB running locally):
docker run -d -p 27017:27017 --name mongo-chatui mongo:latest
Read more here.
Step 2 (clone chat-ui):
git clone https://github.com/huggingface/chat-ui
cd chat-ui
Step 3 (start chat-ui):
npm install
npm run dev -- --open
Read more here.
If you don't want to configure, setup, and launch your own Chat UI yourself, you can use this option as a fast deploy alternative.
You can deploy your own customized Chat UI instance with any supported LLM of your choice on Hugging Face Spaces. To do so, use the chat-ui template available here.
Set OPENAI_BASE_URL
(for example https://router.huggingface.co/v1
) and OPENAI_API_KEY
in Space secrets. HF_TOKEN
remains supported as a legacy alias if you already have it configured. Create your personal token in your User Access Tokens settings.
Read the full tutorial here.
The default config for Chat UI is stored in the .env
file. You will need to override some values to get Chat UI to run locally. This is done in .env.local
.
Start by creating a .env.local
file in the root of the repository. The bare minimum config you need to get Chat UI to run locally is the following:
MONGODB_URL=<the URL to your MongoDB instance>
OPENAI_BASE_URL=<OpenAI-compatible API base URL, e.g. https://router.huggingface.co/v1>
# Authorization
OPENAI_API_KEY=<your access token>
# or
OPENAI_API_KEY=<your provider API key>
The chat history is stored in a MongoDB instance, and having a DB instance available is needed for Chat UI to work.
You can use a local MongoDB instance. The easiest way is to spin one up using docker:
docker run -d -p 27017:27017 --name mongo-chatui mongo:latest
In which case the url of your DB will be MONGODB_URL=mongodb://localhost:27017
.
Alternatively, you can use a free MongoDB Atlas instance for this, Chat UI should fit comfortably within their free tier. After which you can set the MONGODB_URL
variable in .env.local
to match your instance.
If you use the Hugging Face router, you will need a Hugging Face access token to run Chat UI locally. You can get one from your Hugging Face profile.
After you're done with the .env.local
file you can run Chat UI locally with:
npm install
npm run dev
The login feature is disabled by default and users are attributed a unique ID based on their browser. But if you want to use OpenID to authenticate your users, you can add the following to your .env.local
file:
OPENID_CONFIG=`{
PROVIDER_URL: "<your OIDC issuer>",
CLIENT_ID: "<your OIDC client ID>",
CLIENT_SECRET: "<your OIDC client secret>",
SCOPES: "openid profile",
TOLERANCE: // optional
RESOURCE: // optional
}`
These variables will enable the openID sign-in modal for users.
You can set the env variable TRUSTED_EMAIL_HEADER
to point to the header that contains the user's email address. This will allow you to authenticate users from the header. This setup is usually combined with a proxy that will be in front of chat-ui and will handle the auth and set the header.
Warning
Make sure to only allow requests to chat-ui through your proxy which handles authentication, otherwise users could authenticate as anyone by setting the header manually! Only set this up if you understand the implications and know how to do it correctly.
Here is a list of header names for common auth providers:
- Tailscale Serve:
Tailscale-User-Login
- Cloudflare Access:
Cf-Access-Authenticated-User-Email
- oauth2-proxy:
X-Forwarded-Email
You can use a few environment variables to customize the look and feel of chat-ui. These are by default:
PUBLIC_APP_NAME=ChatUI
PUBLIC_APP_ASSETS=chatui
PUBLIC_APP_COLOR=blue
PUBLIC_APP_DESCRIPTION="Making the community's best AI chat models available to everyone."
PUBLIC_APP_DATA_SHARING=
PUBLIC_APP_NAME
The name used as a title throughout the app.PUBLIC_APP_ASSETS
Is used to find logos & favicons instatic/$PUBLIC_APP_ASSETS
, current options arechatui
andhuggingchat
.PUBLIC_APP_COLOR
Can be any of the tailwind colors.PUBLIC_APP_DATA_SHARING
Can be set to 1 to add a toggle in the user settings that lets your users opt-in to data sharing with models creator.
This build does not use the MODELS
env var or GGUF discovery. Configure models via OPENAI_BASE_URL
only; Chat UI will fetch ${OPENAI_BASE_URL}/models
and populate the list automatically. Authorization uses OPENAI_API_KEY
(preferred). HF_TOKEN
remains a legacy alias.
Chat UI can perform client-side routing using an Arch Router model without running a separate router service. The UI exposes a virtual model alias called "Omni" (configurable) that, when selected, chooses the best route/model for each message.
- Provide a routes policy JSON via
LLM_ROUTER_ROUTES_PATH
(defaults tollm-router/routes.chat.json
). Each route definesname
,description
,primary_model
, and optionalfallback_models
. - Configure the Arch router selection endpoint with
LLM_ROUTER_ARCH_BASE_URL
(OpenAI-compatible/chat/completions
) andLLM_ROUTER_ARCH_MODEL
(e.g.router/omni
). The Arch call reusesOPENAI_API_KEY
for auth. - Map
other
to a concrete route viaLLM_ROUTER_OTHER_ROUTE
(default:casual_conversation
). If Arch selection fails, calls fall back toLLM_ROUTER_FALLBACK_MODEL
. - Selection timeout can be tuned via
LLM_ROUTER_ARCH_TIMEOUT_MS
(default 10000). - Omni alias configuration:
PUBLIC_LLM_ROUTER_ALIAS_ID
(defaultomni
),PUBLIC_LLM_ROUTER_DISPLAY_NAME
(defaultOmni
), and optionalPUBLIC_LLM_ROUTER_LOGO_URL
.
When you select Omni in the UI, Chat UI will:
- Call the Arch endpoint once (non-streaming) to pick the best route for the last turns.
- Emit RouterMetadata immediately (route and actual model used) so the UI can display it.
- Stream from the selected model via your configured
OPENAI_BASE_URL
. On errors, it tries route fallbacks.
Most likely you are running chat-ui over HTTP. The recommended option is to setup something like NGINX to handle HTTPS and proxy the requests to chat-ui. If you really need to run over HTTP you can add COOKIE_SECURE=false
and COOKIE_SAMESITE=lax
to your .env.local
.
Make sure to set your PUBLIC_ORIGIN
in your .env.local
to the correct URL as well.
Create a DOTENV_LOCAL
secret to your HF space with the content of your .env.local, and they will be picked up automatically when you run.
Ensure the secret includes at least: MONGODB_URL
, OPENAI_BASE_URL
, and OPENAI_API_KEY
.
To create a production version of your app:
npm run build
You can preview the production build with npm run preview
.
To deploy your app, you may need to install an adapter for your target environment.
The config file for HuggingChat is stored in the chart/env/prod.yaml
file. It is the source of truth for the environment variables used for our CI/CD pipeline. For HuggingChat, as we need to customize the app color, as well as the base path, we build a custom docker image. You can find the workflow here.
Tip
If you want to make changes to the model config used in production for HuggingChat, you should do so against chart/env/prod.yaml
.
If you want to run an exact copy of HuggingChat locally, you will need to do the following first:
- Create an OAuth App on the hub with
openid profile email
permissions. Make sure to set the callback URL to something likehttp://localhost:5173/chat/login/callback
which matches the right path for your local instance. - Create a HF Token with your Hugging Face account. You will need a Pro account to be able to access some of the larger models available through HuggingChat.
- Run an instance of mongoDB, however you want. (Local or remote)
You can then create a new .env.SECRET_CONFIG
file with the following content
MONGODB_URL=<link to your mongo DB from step 3>
OPENAI_API_KEY=<your token from step 2>
OPENAI_BASE_URL=https://router.huggingface.co/v1
OPENID_CONFIG=`{
PROVIDER_URL: "https://huggingface.co",
CLIENT_ID: "<your client ID from step 1>",
CLIENT_SECRET: "<your client secret from step 1>",
}`
MESSAGES_BEFORE_LOGIN=<can be any numerical value, or set to 0 to require login>
You can then run npm run updateLocalEnv
in the root of chat-ui. This will create a .env.local
file which combines the chart/env/prod.yaml
and the .env.SECRET_CONFIG
file. You can then run npm run dev
to start your local instance of HuggingChat.
Warning
The MONGODB_URL
used for this script will be fetched from .env.local
. Make sure it's correct! The command runs directly on the database.
You can populate the database using faker data using the populate
script:
npm run populate <flags here>
At least one flag must be specified, the following flags are available:
reset
- resets the databaseall
- populates all tablesusers
- populates the users tablesettings
- populates the settings table for existing usersassistants
- populates the assistants table for existing usersconversations
- populates the conversations table for existing users
For example, you could use it like so:
npm run populate reset
to clear out the database. Then login in the app to create your user and run the following command:
npm run populate users settings assistants conversations
to populate the database with fake data, including fake conversations and assistants for your user.
You can build the docker images locally using the following commands:
docker build -t chat-ui-db:latest --build-arg INCLUDE_DB=true .
docker build -t chat-ui:latest --build-arg INCLUDE_DB=false .
docker build -t huggingchat:latest --build-arg INCLUDE_DB=false --build-arg APP_BASE=/chat --build-arg PUBLIC_APP_COLOR=yellow --build-arg SKIP_LLAMA_CPP_BUILD=true .
If you want to run the images with your local .env.local you have two options
DOTENV_LOCAL=$(<.env.local) docker run --network=host -e DOTENV_LOCAL chat-ui-db
docker run --network=host --mount type=bind,source="$(pwd)/.env.local",target=/app/.env.local chat-ui-db