Chat UI README
huggingface/chat-ui · Apache-2.0 · 源码版本 7fc0f672
上手导读
安装与准备
按仓库版本要求配置推理端点与存储后运行前端。
试用示例
先接一个测试模型,检查短对话、长对话和刷新后的会话恢复。
Chat UI
A chat interface for LLMs. It is a SvelteKit app and it powers the HuggingChat app on hf.co/chat.
Note
Chat UI only supports OpenAI-compatible APIs via OPENAI_BASE_URL and the /models endpoint. Provider-specific integrations (legacy MODELS env var, GGUF discovery, embeddings, web-search helpers, etc.) are removed, but any service that speaks the OpenAI protocol (llama.cpp server, Ollama, OpenRouter, etc.) will work by default.
Note
The old version is still available on the legacy branch
Quickstart
Chat UI speaks to OpenAI-compatible APIs only. The fastest way to get running is with the Hugging Face Inference Providers router plus your personal Hugging Face access token.
Step 1 – Create .env.local:
OPENAI_BASE_URL=https://router.huggingface.co/v1 OPENAI_API_KEY=hf_************************
OPENAI_API_KEY can come from any OpenAI-compatible endpoint you plan to call. Pick the combo that matches your setup and drop the values into .env.local:
| Provider | Example OPENAI_BASE_URL |
Example key env |
|---|---|---|
| Hugging Face Inference Providers router | https://router.huggingface.co/v1 |
OPENAI_API_KEY=hf_xxx (or HF_TOKEN legacy alias) |
llama.cpp server (llama.cpp --server --api) |
http://127.0.0.1:8080/v1 |
OPENAI_API_KEY=sk-local-demo (any string works; llama.cpp ignores it) |
| Ollama (with OpenAI-compatible bridge) | http://127.0.0.1:11434/v1 |
OPENAI_API_KEY=ollama |
| OpenRouter | https://openrouter.ai/api/v1 |
OPENAI_API_KEY=sk-or-v1-... |
| Poe | https://api.poe.com/v1 |
OPENAI_API_KEY=pk_... |
Check the root .env template for the full list of optional variables you can override.
Step 2 – Install and launch the dev server:
git clone https://github.com/huggingface/chat-ui
cd chat-ui
npm install
npm run dev -- --openYou now have Chat UI running locally. Open the browser and start chatting.
Database Options
Chat history, users, settings, files, and stats all live in MongoDB. You can point Chat UI at any MongoDB 6/7 deployment.
Tip
For quick local development, you can skip this section. When MONGODB_URL is not set, Chat UI falls back to an embedded MongoDB that persists to ./db.
MongoDB Atlas (managed)
- Create a free cluster at mongodb.com.
- Add your IP (or
0.0.0.0/0for development) to the network access list. - Create a database user and copy the connection string.
- Paste that string into
MONGODB_URLin.env.local. Keep the defaultMONGODB_DB_NAME=chat-uior change it per environment.
Atlas keeps MongoDB off your laptop, which is ideal for teams or cloud deployments.
Local MongoDB (container)
If you prefer to run MongoDB in a container:
docker run -d -p 27017:27017 --name mongo-chatui mongo:latest
Then set MONGODB_URL=mongodb://localhost:27017 in .env.local.
Launch
After configuring your environment variables, start Chat UI with:
npm install npm run dev
The dev server listens on http://localhost:5173 by default. Use npm run build / npm run preview for production builds.
Optional Docker Image
The chat-ui-db image bundles MongoDB inside the container:
docker run \
-p 3000:3000 \
-e OPENAI_BASE_URL=https://router.huggingface.co/v1 \
-e OPENAI_API_KEY=hf_*** \
-v chat-ui-data:/data \
ghcr.io/huggingface/chat-ui-db:latestAll environment variables accepted in .env.local can be provided as -e flags.
Extra parameters
Theming
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_DESCRIPTION="Making the community's best AI chat models available to everyone." PUBLIC_APP_DATA_SHARING=
PUBLIC_APP_NAMEThe name used as a title throughout the app.PUBLIC_APP_ASSETSIs used to find logos & favicons instatic/$PUBLIC_APP_ASSETS, current options arechatuiandhuggingchat.PUBLIC_APP_DATA_SHARINGCan be set to 1 to add a toggle in the user settings that lets your users opt-in to data sharing with models creator.
Models
Models are discovered from ${OPENAI_BASE_URL}/models, and you can optionally override their metadata via the MODELS env var (JSON5). Legacy provider‑specific integrations and GGUF discovery are removed. Authorization uses OPENAI_API_KEY (preferred). HF_TOKEN remains a legacy alias.
LLM Router (Optional)
Chat UI can perform server-side smart routing using a local heuristic — no separate router service or selection model is called. The UI exposes a virtual model alias called "Omni" (configurable) that, when selected, chooses the best route/model for each message: image inputs go to a multimodal route, MCP-tool-enabled requests go to an agentic route, and everything else goes to a default route.
- Provide a routes policy JSON via
LLM_ROUTER_ROUTES_PATH. No sample file ships with this branch, so you must point the variable to a JSON array you create yourself (for example, commit one in your project likeconfig/routes.chat.json). Each route entry needsname,description,primary_model, and optionalfallback_models. The router recognizes the route namesdefault,multimodal, andagentic. - The default route name is configurable via
LLM_ROUTER_DEFAULT_ROUTE(default:default). If the selected route's models all fail, calls fall back toLLM_ROUTER_FALLBACK_MODEL. - 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:
- Pick a route locally based on the request signals (image attached, MCP server enabled, or default).
- 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 in order, thenLLM_ROUTER_FALLBACK_MODEL.
Tool and multimodal shortcuts:
- Multimodal: If
LLM_ROUTER_ENABLE_MULTIMODAL=trueand the user sends an image, the router bypasses the policy file and uses the model specified inLLM_ROUTER_MULTIMODAL_MODEL. Route name:multimodal. - Tools: If
LLM_ROUTER_ENABLE_TOOLS=trueand the user has at least one MCP server enabled, the router bypasses the policy file and usesLLM_ROUTER_TOOLS_MODEL. If that model is missing or misconfigured, it falls back to the heuristic route. Route name:agentic.
MCP Tools (Optional)
Chat UI can call tools exposed by Model Context Protocol (MCP) servers and feed results back to the model using OpenAI function calling. You can preconfigure trusted servers via env, let users add their own, and optionally have the Omni router auto‑select a tools‑capable model.
Configure servers (base list for all users):
# JSON array of servers: name, url, optional headers MCP_SERVERS=[ {"name": "Web Search (Exa)", "url": "https://mcp.exa.ai/mcp"}, {"name": "Hugging Face MCP Login", "url": "https://hf.co/mcp?login"} ] # Forward the signed-in user's Hugging Face token to the official HF MCP login endpoint # when no Authorization header is set on that server entry. MCP_FORWARD_HF_USER_TOKEN=true
Enable router tool path (Omni):
- Set
LLM_ROUTER_ENABLE_TOOLS=trueand choose a tools‑capable target withLLM_ROUTER_TOOLS_MODEL=<model id or name>. - The target must support OpenAI tools/function calling. Chat UI surfaces a “tools” badge on models that advertise this; you can also force‑enable it per‑model in settings (see below).
Use tools in the UI:
- Open “MCP Servers” from the top‑right menu or from the
+menu in the chat input to add servers, toggle them on, and run Health Check. The server card lists available tools. - When a model calls a tool, the message shows a compact “tool” block with parameters, a progress bar while running, and the result (or error). Results are also provided back to the model for follow‑up.
Per‑model overrides:
- In Settings → Model, you can toggle “Tool calling (functions)” and “Multimodal input” per model. These overrides apply even if the provider metadata doesn’t advertise the capability.
ML Intern
ML Intern is an experimental mode that plans and runs machine-learning work on the Hugging Face Hub: reproducing papers, finetuning and evaluating models, building datasets, and deploying demos as Spaces. It reads papers, models and datasets, writes scripts, and runs them as Hugging Face Jobs and sandboxes, within a compute budget you set for each conversation.
Try it on HuggingChat at huggingface.co/chat/?mode=ml-intern.
-
Getting started with ML Intern: set up your account and billing, write your first task, and keep spending under control.
-
Running Chat UI with ML Intern locally: configure and run ML Intern in your own Chat UI, choose models, and find your way around the code.
-
ML Intern in Slack: add the bot to your workspace, connect your account, and work with it in threads. To run your own, see the Slack integration guide.
Building
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.
Getting started with ML Intern
ML Intern is a mode in HuggingChat that plans and runs machine-learning work for you, using the Hugging Face Hub as its workspace. Describe a task in plain language and ML Intern reads the relevant papers, models and datasets, writes the scripts, runs them on Hugging Face compute, and reports back. For example, it can:
- reproduce a paper at small scale
- finetune a model and evaluate the checkpoint
- generate or curate a dataset and push it to the Hub
- build a demo and deploy it as a Space
- run a model against a benchmark
Before you start
You need:
- A Hugging Face account. Sign up at huggingface.co.
- Credits for compute. ML Intern runs Hugging Face Jobs and sandboxes, billed to your Hugging Face credits or to an organization you belong to (see Step 3). Chatting with the model is billed separately, as Inference Providers usage.
Step 1: Open HuggingChat and switch on ML Intern
- Go to huggingface.co/chat and sign in with your Hugging Face account.
- In a new conversation, turn on the ML Intern switch under the message box. The placeholder and suggested prompts change to match.
You can also go straight to huggingface.co/chat/?mode=ml-intern, which opens a new conversation with ML Intern already on. This link works well for bookmarks, or for sharing with people you're onboarding.
The mode is a property of the conversation. You can switch it on or off until you send the first message; after that it stays as it is for the rest of the conversation. To use ML Intern, start a new conversation with the switch on.
Step 2: Enable the Hub tools ML Intern uses
ML Intern works through the Hugging Face MCP server and can only use the tools you have switched on there. For the best results, open your MCP settings and enable all of them.
The first time you turn on ML Intern, a short onboarding dialog links to this page and to your billing settings.
Step 3: Choose who pays
By default, Jobs and sandboxes bill to your personal account. To bill an organization instead (for example, a lab, a company, or a program that gives you credits):
- Join the organization on Hugging Face. If someone invited you, accept the invitation from your email or notifications.
- In HuggingChat, open Settings → Application → Billing.
- Choose the organization, or one of its resource groups if the organization uses them to allocate credits. Your organization's admin can tell you which one to use.
This setting covers inference and the Jobs and sandboxes ML Intern launches. Spaces, dashboards and repositories that ML Intern creates always stay on your personal account.
Step 4: Describe your task
Write what you want done, as specifically as you can. Links and Hub ids help: type @ to mention a model, dataset or Space by its id, and paste paper URLs directly. Some examples:
Reproduce <paper title> (https://huggingface.co/papers/<id>) at small scale and report where the results diverge.Finetune @<model-id> on @<dataset-id> and evaluate the checkpoint.Build a Gradio demo Space for @<model-id>.Compare @<model-a> and @<model-b> for <task> on my inputs.Generate a synthetic function-calling dataset and push it to the Hub.Evaluate @<model-id> on @<benchmark-dataset-id> and score it.
The suggested prompts above the message box show worked versions of each. ML Intern plans the work first, then carries it out step by step. A progress row above the message box shows where it is in the plan.
Step 5: Set a compute budget
Every ML Intern conversation has its own compute budget, which caps what that conversation can spend on Jobs and sandboxes. It starts at $0, so ML Intern can't launch any compute until you give it a budget.
Once the conversation starts, the budget appears in the status bar above the message box. Click it to set or change the amount. Each launch reserves its worst-case cost (the hardware's price times the job's timeout), then settles to what it actually used when it finishes.
Two other limits also apply:
- Your credit balance is the ceiling account-wide: Jobs stop when it runs out.
- Organizations can also set a spend limit on a resource group.
The compute budget only covers Jobs and sandboxes that ML Intern launches. It doesn't cover chatting with the model, anything those Jobs start themselves, or other Hugging Face products.
Following along
While ML Intern works, you can:
- Open "Resources" from the status bar to see everything the conversation has created:
- running and finished Jobs and sandboxes
- repositories and Spaces it pushed to
- the scripts it wrote, with every version and the Jobs that ran each one
- the images its tools returned, such as sample grids and plots
- Watch training live. When a training run logs to Trackio, a live metrics dashboard opens in a side panel.
- Compare models side by side. Asked to choose between models, or to feed one model's output into another, ML Intern deploys a public gr.Workflow Space that runs them on the same input. You can rerun it on your own inputs. Runs bill the inference quota of whoever presses Run, not the conversation's compute budget.
- Answer its questions. ML Intern sometimes asks you to choose between options or confirm a step before it continues.
- Resume after a failure. If a turn fails partway, use Resume to continue from where it stopped rather than starting the whole turn again.
Running ML Intern yourself
ML Intern is part of Chat UI, the open-source app behind HuggingChat. To run it locally or work on it, see Running Chat UI with ML Intern locally.
原作者与许可证
文档来自 huggingface/chat-ui 的上述提交,保留原文并调整了站内排版与链接。
查看仓库许可证原文 ↗Copyright 2018- The Hugging Face team. All rights reserved.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.