maksym-work commited on
Commit
286d951
·
1 Parent(s): 612e60f

Update README.md to include configuration reference and remove outdated content

Browse files
Files changed (2) hide show
  1. README.md +10 -1120
  2. README_SETUP.md +1120 -0
README.md CHANGED
@@ -1,1120 +1,10 @@
1
- # Chat UI
2
-
3
- **Find the docs at [hf.co/docs/chat-ui](https://huggingface.co/docs/chat-ui/index).**
4
-
5
- ![Chat UI repository thumbnail](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/chatui-websearch.png)
6
-
7
- 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](https://huggingface.co/chat).
8
-
9
- 0. [Quickstart](#quickstart)
10
- 1. [No Setup Deploy](#no-setup-deploy)
11
- 2. [Setup](#setup)
12
- 3. [Launch](#launch)
13
- 4. [Web Search](#web-search)
14
- 5. [Text Embedding Models](#text-embedding-models)
15
- 6. [Extra parameters](#extra-parameters)
16
- 7. [Common issues](#common-issues)
17
- 8. [Deploying to a HF Space](#deploying-to-a-hf-space)
18
- 9. [Building](#building)
19
-
20
- ## Quickstart
21
-
22
- ### Docker image
23
-
24
- You can deploy a chat-ui instance in a single command using the docker image. Get your huggingface token from [here](https://huggingface.co/settings/tokens).
25
-
26
- ```bash
27
- docker run -p 3000 -e HF_TOKEN=hf_*** -v db:/data ghcr.io/huggingface/chat-ui-db:latest
28
- ```
29
-
30
- Take a look at the [`.env` file](https://github.com/huggingface/chat-ui/blob/main/.env) and the readme to see all the environment variables that you can set. We have endpoint support for all OpenAI API compatible local services as well as many other providers like Anthropic, Cloudflare, Google Vertex AI, etc.
31
-
32
- ### Local setup
33
-
34
- You can quickly start a locally running chat-ui & LLM text-generation server thanks to chat-ui's [llama.cpp server support](https://huggingface.co/docs/chat-ui/configuration/models/providers/llamacpp).
35
-
36
- **Step 1 (Start llama.cpp server):**
37
-
38
- Install llama.cpp w/ brew (for Mac):
39
-
40
- ```bash
41
- # install llama.cpp
42
- brew install llama.cpp
43
- ```
44
-
45
- or [build directly from the source](https://github.com/ggerganov/llama.cpp/blob/master/docs/build.md) for your target device:
46
-
47
- ```
48
- git clone https://github.com/ggerganov/llama.cpp && cd llama.cpp && make
49
- ```
50
-
51
- Next, start the server with the [LLM of your choice](https://huggingface.co/models?library=gguf):
52
-
53
- ```bash
54
- # start llama.cpp server (using hf.co/microsoft/Phi-3-mini-4k-instruct-gguf as an example)
55
- llama-server --hf-repo microsoft/Phi-3-mini-4k-instruct-gguf --hf-file Phi-3-mini-4k-instruct-q4.gguf -c 4096
56
- ```
57
-
58
- A local LLaMA.cpp HTTP Server will start on `http://localhost:8080`. Read more [here](https://huggingface.co/docs/chat-ui/configuration/models/providers/llamacpp).
59
-
60
- **Step 3 (make sure you have MongoDb running locally):**
61
-
62
- ```bash
63
- docker run -d -p 27017:27017 --name mongo-chatui mongo:latest
64
- ```
65
-
66
- Read more [here](#database).
67
-
68
- **Step 4 (clone chat-ui):**
69
-
70
- ```bash
71
- git clone https://github.com/huggingface/chat-ui
72
- cd chat-ui
73
- ```
74
-
75
- **Step 5 (tell chat-ui to use local llama.cpp server):**
76
-
77
- Add the following to your `.env.local`:
78
-
79
- ```ini
80
- MODELS=`[
81
- {
82
- "name": "microsoft/Phi-3-mini-4k-instruct",
83
- "endpoints": [{
84
- "type" : "llamacpp",
85
- "baseURL": "http://localhost:8080"
86
- }],
87
- },
88
- ]`
89
- ```
90
-
91
- Read more [here](https://huggingface.co/docs/chat-ui/configuration/models/providers/llamacpp).
92
-
93
- **Step 6 (start chat-ui):**
94
-
95
- ```bash
96
- npm install
97
- npm run dev -- --open
98
- ```
99
-
100
- Read more [here](#launch).
101
-
102
- <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/chat-ui/llamacpp-dark.png" height="auto"/>
103
-
104
- ## No Setup Deploy
105
-
106
- 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.
107
-
108
- You can deploy your own customized Chat UI instance with any supported [LLM](https://huggingface.co/models?pipeline_tag=text-generation&sort=trending) of your choice on [Hugging Face Spaces](https://huggingface.co/spaces). To do so, use the chat-ui template [available here](https://huggingface.co/new-space?template=huggingchat/chat-ui-template).
109
-
110
- Set `HF_TOKEN` in [Space secrets](https://huggingface.co/docs/hub/spaces-overview#managing-secrets) to deploy a model with gated access or a model in a private repository. It's also compatible with [Inference for PROs](https://huggingface.co/blog/inference-pro) curated list of powerful models with higher rate limits. Make sure to create your personal token first in your [User Access Tokens settings](https://huggingface.co/settings/tokens).
111
-
112
- Read the full tutorial [here](https://huggingface.co/docs/hub/spaces-sdks-docker-chatui#chatui-on-spaces).
113
-
114
- ## Setup
115
-
116
- 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`.
117
-
118
- 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:
119
-
120
- ```env
121
- MONGODB_URL=<the URL to your MongoDB instance>
122
- HF_TOKEN=<your access token>
123
- ```
124
-
125
- ### Database
126
-
127
- The chat history is stored in a MongoDB instance, and having a DB instance available is needed for Chat UI to work.
128
-
129
- You can use a local MongoDB instance. The easiest way is to spin one up using docker:
130
-
131
- ```bash
132
- docker run -d -p 27017:27017 --name mongo-chatui mongo:latest
133
- ```
134
-
135
- In which case the url of your DB will be `MONGODB_URL=mongodb://localhost:27017`.
136
-
137
- Alternatively, you can use a [free MongoDB Atlas](https://www.mongodb.com/pricing) 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.
138
-
139
- ### Hugging Face Access Token
140
-
141
- If you use a remote inference endpoint, you will need a Hugging Face access token to run Chat UI locally. You can get one from [your Hugging Face profile](https://huggingface.co/settings/tokens).
142
-
143
- ## Launch
144
-
145
- After you're done with the `.env.local` file you can run Chat UI locally with:
146
-
147
- ```bash
148
- npm install
149
- npm run dev
150
- ```
151
-
152
- ## Web Search
153
-
154
- Chat UI features a powerful Web Search feature. It works by:
155
-
156
- 1. Generating an appropriate search query from the user prompt.
157
- 2. Performing web search and extracting content from webpages.
158
- 3. Creating embeddings from texts using a text embedding model.
159
- 4. From these embeddings, find the ones that are closest to the user query using a vector similarity search. Specifically, we use `inner product` distance.
160
- 5. Get the corresponding texts to those closest embeddings and perform [Retrieval-Augmented Generation](https://huggingface.co/papers/2005.11401) (i.e. expand user prompt by adding those texts so that an LLM can use this information).
161
-
162
- ## Text Embedding Models
163
-
164
- By default (for backward compatibility), when `TEXT_EMBEDDING_MODELS` environment variable is not defined, [transformers.js](https://huggingface.co/docs/transformers.js) embedding models will be used for embedding tasks, specifically, [Xenova/gte-small](https://huggingface.co/Xenova/gte-small) model.
165
-
166
- You can customize the embedding model by setting `TEXT_EMBEDDING_MODELS` in your `.env.local` file. For example:
167
-
168
- ```env
169
- TEXT_EMBEDDING_MODELS = `[
170
- {
171
- "name": "Xenova/gte-small",
172
- "displayName": "Xenova/gte-small",
173
- "description": "locally running embedding",
174
- "chunkCharLength": 512,
175
- "endpoints": [
176
- {"type": "transformersjs"}
177
- ]
178
- },
179
- {
180
- "name": "intfloat/e5-base-v2",
181
- "displayName": "intfloat/e5-base-v2",
182
- "description": "hosted embedding model",
183
- "chunkCharLength": 768,
184
- "preQuery": "query: ", # See https://huggingface.co/intfloat/e5-base-v2#faq
185
- "prePassage": "passage: ", # See https://huggingface.co/intfloat/e5-base-v2#faq
186
- "endpoints": [
187
- {
188
- "type": "tei",
189
- "url": "http://127.0.0.1:8080/",
190
- "authorization": "TOKEN_TYPE TOKEN" // optional authorization field. Example: "Basic VVNFUjpQQVNT"
191
- }
192
- ]
193
- }
194
- ]`
195
- ```
196
-
197
- The required fields are `name`, `chunkCharLength` and `endpoints`.
198
- Supported text embedding backends are: [`transformers.js`](https://huggingface.co/docs/transformers.js), [`TEI`](https://github.com/huggingface/text-embeddings-inference) and [`OpenAI`](https://platform.openai.com/docs/guides/embeddings). `transformers.js` models run locally as part of `chat-ui`, whereas `TEI` models run in a different environment & accessed through an API endpoint. `openai` models are accessed through the [OpenAI API](https://platform.openai.com/docs/guides/embeddings).
199
-
200
- When more than one embedding models are supplied in `.env.local` file, the first will be used by default, and the others will only be used on LLM's which configured `embeddingModel` to the name of the model.
201
-
202
- ## Extra parameters
203
-
204
- ### OpenID connect
205
-
206
- 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:
207
-
208
- ```env
209
- OPENID_CONFIG=`{
210
- PROVIDER_URL: "<your OIDC issuer>",
211
- CLIENT_ID: "<your OIDC client ID>",
212
- CLIENT_SECRET: "<your OIDC client secret>",
213
- SCOPES: "openid profile",
214
- TOLERANCE: // optional
215
- RESOURCE: // optional
216
- }`
217
- ```
218
-
219
- These variables will enable the openID sign-in modal for users.
220
-
221
- ### Trusted header authentication
222
-
223
- 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.
224
-
225
- > [!WARNING]
226
- > 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.
227
-
228
- Here is a list of header names for common auth providers:
229
-
230
- - Tailscale Serve: `Tailscale-User-Login`
231
- - Cloudflare Access: `Cf-Access-Authenticated-User-Email`
232
- - oauth2-proxy: `X-Forwarded-Email`
233
-
234
- ### Theming
235
-
236
- You can use a few environment variables to customize the look and feel of chat-ui. These are by default:
237
-
238
- ```env
239
- PUBLIC_APP_NAME=ChatUI
240
- PUBLIC_APP_ASSETS=chatui
241
- PUBLIC_APP_COLOR=blue
242
- PUBLIC_APP_DESCRIPTION="Making the community's best AI chat models available to everyone."
243
- PUBLIC_APP_DATA_SHARING=
244
- PUBLIC_APP_DISCLAIMER=
245
- ```
246
-
247
- - `PUBLIC_APP_NAME` The name used as a title throughout the app.
248
- - `PUBLIC_APP_ASSETS` Is used to find logos & favicons in `static/$PUBLIC_APP_ASSETS`, current options are `chatui` and `huggingchat`.
249
- - `PUBLIC_APP_COLOR` Can be any of the [tailwind colors](https://tailwindcss.com/docs/customizing-colors#default-color-palette).
250
- - `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.
251
- - `PUBLIC_APP_DISCLAIMER` If set to 1, we show a disclaimer about generated outputs on login.
252
-
253
- ### Web Search config
254
-
255
- You can enable the web search through an API by adding `YDC_API_KEY` ([docs.you.com](https://docs.you.com)) or `SERPER_API_KEY` ([serper.dev](https://serper.dev/)) or `SERPAPI_KEY` ([serpapi.com](https://serpapi.com/)) or `SERPSTACK_API_KEY` ([serpstack.com](https://serpstack.com/)) or `SEARCHAPI_KEY` ([searchapi.io](https://www.searchapi.io/)) to your `.env.local`.
256
-
257
- You can also simply enable the local google websearch by setting `USE_LOCAL_WEBSEARCH=true` in your `.env.local` or specify a SearXNG instance by adding the query URL to `SEARXNG_QUERY_URL`.
258
-
259
- You can enable javascript when parsing webpages to improve compatibility with `WEBSEARCH_JAVASCRIPT=true` at the cost of increased CPU usage. You'll want at least 4 cores when enabling.
260
-
261
- ### Custom models
262
-
263
- You can customize the parameters passed to the model or even use a new model by updating the `MODELS` variable in your `.env.local`. The default one can be found in `.env` and looks like this :
264
-
265
- ```env
266
- MODELS=`[
267
- {
268
- "name": "mistralai/Mistral-7B-Instruct-v0.2",
269
- "displayName": "mistralai/Mistral-7B-Instruct-v0.2",
270
- "description": "Mistral 7B is a new Apache 2.0 model, released by Mistral AI that outperforms Llama2 13B in benchmarks.",
271
- "websiteUrl": "https://mistral.ai/news/announcing-mistral-7b/",
272
- "preprompt": "",
273
- "chatPromptTemplate" : "<s>{{#each messages}}{{#ifUser}}[INST] {{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}}{{content}} [/INST]{{/ifUser}}{{#ifAssistant}}{{content}}</s>{{/ifAssistant}}{{/each}}",
274
- "parameters": {
275
- "temperature": 0.3,
276
- "top_p": 0.95,
277
- "repetition_penalty": 1.2,
278
- "top_k": 50,
279
- "truncate": 3072,
280
- "max_new_tokens": 1024,
281
- "stop": ["</s>"]
282
- },
283
- "promptExamples": [
284
- {
285
- "title": "Write an email",
286
- "prompt": "As a restaurant owner, write a professional email to the supplier to get these products every week: \n\n- Wine (x10)\n- Eggs (x24)\n- Bread (x12)"
287
- }, {
288
- "title": "Code a game",
289
- "prompt": "Code a basic snake game in python, give explanations for each step."
290
- }, {
291
- "title": "Recipe help",
292
- "prompt": "How do I make a delicious lemon cheesecake?"
293
- }
294
- ]
295
- }
296
- ]`
297
-
298
- ```
299
-
300
- You can change things like the parameters, or customize the preprompt to better suit your needs. You can also add more models by adding more objects to the array, with different preprompts for example.
301
-
302
- #### chatPromptTemplate
303
-
304
- In 2025 most chat-completion endpoints (local or remotely hosted) support the OpenAI-compatible API and take arrays of messages.
305
-
306
- If not, when querying the model for a chat response, the `chatPromptTemplate` template is used. `messages` is an array of chat messages, it has the format `[{ content: string }, ...]`. To identify if a message is a user message or an assistant message the `ifUser` and `ifAssistant` block helpers can be used.
307
-
308
- The following is the default `chatPromptTemplate`, although newlines and indentiation have been added for readability. You can find the prompts used in production for HuggingChat [here](https://github.com/huggingface/chat-ui/blob/main/PROMPTS.md).
309
-
310
- ```prompt
311
- {{preprompt}}
312
- {{#each messages}}
313
- {{#ifUser}}{{@root.userMessageToken}}{{content}}{{@root.userMessageEndToken}}{{/ifUser}}
314
- {{#ifAssistant}}{{@root.assistantMessageToken}}{{content}}{{@root.assistantMessageEndToken}}{{/ifAssistant}}
315
- {{/each}}
316
- {{assistantMessageToken}}
317
- ```
318
-
319
- > [!INFO]
320
- > We also support Jinja2 templates for the `chatPromptTemplate` in addition to Handlebars templates. On startup we first try to compile with Jinja and if that fails we fall back to interpreting `chatPromptTemplate` as handlebars.
321
-
322
- #### Multi modal model
323
-
324
- We currently support [IDEFICS](https://huggingface.co/blog/idefics) (hosted on TGI), OpenAI and Claude 3 as multimodal models. You can enable it by setting `multimodal: true` in your `MODELS` configuration. For IDEFICS, you must have a [PRO HF Api token](https://huggingface.co/settings/tokens). For OpenAI, see the [OpenAI section](#openai-api-compatible-models). For Anthropic, see the [Anthropic section](#anthropic).
325
-
326
- ```env
327
- {
328
- "name": "HuggingFaceM4/idefics-80b-instruct",
329
- "multimodal" : true,
330
- "description": "IDEFICS is the new multimodal model by Hugging Face.",
331
- "preprompt": "",
332
- "chatPromptTemplate" : "{{#each messages}}{{#ifUser}}User: {{content}}{{/ifUser}}<end_of_utterance>\nAssistant: {{#ifAssistant}}{{content}}\n{{/ifAssistant}}{{/each}}",
333
- "parameters": {
334
- "temperature": 0.1,
335
- "top_p": 0.95,
336
- "repetition_penalty": 1.2,
337
- "top_k": 12,
338
- "truncate": 1000,
339
- "max_new_tokens": 1024,
340
- "stop": ["<end_of_utterance>", "User:", "\nUser:"]
341
- }
342
- }
343
- ```
344
-
345
- #### Running your own models using a custom endpoint
346
-
347
- If you want to, instead of hitting models on the Hugging Face Inference API, you can run your own models locally.
348
-
349
- A good option is to hit a [text-generation-inference](https://github.com/huggingface/text-generation-inference), or a llama.cpp endpoint. You will find an example for TGI in the official [Chat UI Spaces Docker template](https://huggingface.co/new-space?template=huggingchat/chat-ui-template) for instance: both this app and a text-generation-inference server run inside the same container.
350
-
351
- To do this, you can add your own endpoints to the `MODELS` variable in `.env.local`, by adding an `"endpoints"` key for each model in `MODELS`.
352
-
353
- ```env
354
- {
355
- // rest of the model config here
356
- "endpoints": [{
357
- "type" : "tgi",
358
- "url": "https://HOST:PORT",
359
- }]
360
- }
361
- ```
362
-
363
- If `endpoints` are left unspecified, ChatUI will look for the model on the hosted Hugging Face inference API using the model name.
364
-
365
- ##### OpenAI API compatible models
366
-
367
- Chat UI can be used with any API server that supports OpenAI API compatibility, for example [text-generation-webui](https://github.com/oobabooga/text-generation-webui/tree/main/extensions/openai), [LocalAI](https://github.com/go-skynet/LocalAI), [FastChat](https://github.com/lm-sys/FastChat/blob/main/docs/openai_api.md), [llama-cpp-python](https://github.com/abetlen/llama-cpp-python), and [ialacol](https://github.com/chenhunghan/ialacol) and [vllm](https://docs.vllm.ai/en/latest/serving/openai_compatible_server.html).
368
-
369
- The following example config makes Chat UI works with [text-generation-webui](https://github.com/oobabooga/text-generation-webui/tree/main/extensions/openai), the `endpoint.baseUrl` is the url of the OpenAI API compatible server, this overrides the baseUrl to be used by OpenAI instance. The `endpoint.completion` determine which endpoint to be used, default is `chat_completions` which uses `v1/chat/completions`, change to `endpoint.completion` to `completions` to use the `v1/completions` endpoint.
370
-
371
- Parameters not supported by OpenAI (e.g., top_k, repetition_penalty, etc.) must be set in the extraBody of endpoints. Be aware that setting them in parameters will cause them to be omitted.
372
-
373
- ```
374
- MODELS=`[
375
- {
376
- "name": "text-generation-webui",
377
- "id": "text-generation-webui",
378
- "parameters": {
379
- "temperature": 0.9,
380
- "top_p": 0.95,
381
- "max_new_tokens": 1024,
382
- "stop": []
383
- },
384
- "endpoints": [{
385
- "type" : "openai",
386
- "baseURL": "http://localhost:8000/v1",
387
- "extraBody": {
388
- "repetition_penalty": 1.2,
389
- "top_k": 50,
390
- "truncate": 1000
391
- }
392
- }]
393
- }
394
- ]`
395
-
396
- ```
397
-
398
- The `openai` type includes official OpenAI models. You can add, for example, GPT4/GPT3.5 as a "openai" model:
399
-
400
- ```
401
- OPENAI_API_KEY=#your openai api key here
402
- MODELS=`[{
403
- "name": "gpt-4",
404
- "displayName": "GPT 4",
405
- "endpoints" : [{
406
- "type": "openai"
407
- }]
408
- },
409
- {
410
- "name": "gpt-3.5-turbo",
411
- "displayName": "GPT 3.5 Turbo",
412
- "endpoints" : [{
413
- "type": "openai"
414
- }]
415
- }]`
416
- ```
417
-
418
- You may also consume any model provider that provides compatible OpenAI API endpoint. For example, you may self-host [Portkey](https://github.com/Portkey-AI/gateway) gateway and experiment with Claude or GPTs offered by Azure OpenAI. Example for Claude from Anthropic:
419
-
420
- ```
421
- MODELS=`[{
422
- "name": "claude-2.1",
423
- "displayName": "Claude 2.1",
424
- "description": "Anthropic has been founded by former OpenAI researchers...",
425
- "parameters": {
426
- "temperature": 0.5,
427
- "max_new_tokens": 4096,
428
- },
429
- "endpoints": [
430
- {
431
- "type": "openai",
432
- "baseURL": "https://gateway.example.com/v1",
433
- "defaultHeaders": {
434
- "x-portkey-config": '{"provider":"anthropic","api_key":"sk-ant-abc...xyz"}'
435
- }
436
- }
437
- ]
438
- }]`
439
- ```
440
-
441
- Example for GPT 4 deployed on Azure OpenAI:
442
-
443
- ```
444
- MODELS=`[{
445
- "id": "gpt-4-1106-preview",
446
- "name": "gpt-4-1106-preview",
447
- "displayName": "gpt-4-1106-preview",
448
- "parameters": {
449
- "temperature": 0.5,
450
- "max_new_tokens": 4096,
451
- },
452
- "endpoints": [
453
- {
454
- "type": "openai",
455
- "baseURL": "https://{resource-name}.openai.azure.com/openai/deployments/{deployment-id}",
456
- "defaultHeaders": {
457
- "api-key": "{api-key}"
458
- },
459
- "defaultQuery": {
460
- "api-version": "2023-05-15"
461
- }
462
- }
463
- ]
464
- }]`
465
- ```
466
-
467
- Or try Mistral from [Deepinfra](https://deepinfra.com/mistralai/Mistral-7B-Instruct-v0.1/api?example=openai-http):
468
-
469
- > Note, apiKey can either be set custom per endpoint, or globally using `OPENAI_API_KEY` variable.
470
-
471
- ```
472
- MODELS=`[{
473
- "name": "mistral-7b",
474
- "displayName": "Mistral 7B",
475
- "description": "A 7B dense Transformer, fast-deployed and easily customisable. Small, yet powerful for a variety of use cases. Supports English and code, and a 8k context window.",
476
- "parameters": {
477
- "temperature": 0.5,
478
- "max_new_tokens": 4096,
479
- },
480
- "endpoints": [
481
- {
482
- "type": "openai",
483
- "baseURL": "https://api.deepinfra.com/v1/openai",
484
- "apiKey": "abc...xyz"
485
- }
486
- ]
487
- }]`
488
- ```
489
-
490
- _Non-streaming endpoints_
491
-
492
- For endpoints that don´t support streaming like o1 on Azure, you can pass `streamingSupported: false` in your endpoint config:
493
-
494
- ```
495
- MODELS=`[{
496
- "id": "o1-preview",
497
- "name": "o1-preview",
498
- "displayName": "o1-preview",
499
- "systemRoleSupported": false,
500
- "endpoints": [
501
- {
502
- "type": "openai",
503
- "baseURL": "https://my-deployment.openai.azure.com/openai/deployments/o1-preview",
504
- "defaultHeaders": {
505
- "api-key": "$SECRET"
506
- },
507
- "streamingSupported": false,
508
- }
509
- ]
510
- }]`
511
- ```
512
-
513
- ##### Llama.cpp API server
514
-
515
- chat-ui also supports the llama.cpp API server directly without the need for an adapter. You can do this using the `llamacpp` endpoint type.
516
-
517
- If you want to run Chat UI with llama.cpp, you can do the following, using [microsoft/Phi-3-mini-4k-instruct-gguf](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-gguf) as an example model:
518
-
519
- ```bash
520
- # install llama.cpp
521
- brew install llama.cpp
522
- # start llama.cpp server
523
- llama-server --hf-repo microsoft/Phi-3-mini-4k-instruct-gguf --hf-file Phi-3-mini-4k-instruct-q4.gguf -c 4096
524
- ```
525
-
526
- ```env
527
- MODELS=`[
528
- {
529
- "name": "Local Zephyr",
530
- "chatPromptTemplate": "<|system|>\n{{preprompt}}</s>\n{{#each messages}}{{#ifUser}}<|user|>\n{{content}}</s>\n<|assistant|>\n{{/ifUser}}{{#ifAssistant}}{{content}}</s>\n{{/ifAssistant}}{{/each}}",
531
- "parameters": {
532
- "temperature": 0.1,
533
- "top_p": 0.95,
534
- "repetition_penalty": 1.2,
535
- "top_k": 50,
536
- "truncate": 1000,
537
- "max_new_tokens": 2048,
538
- "stop": ["</s>"]
539
- },
540
- "endpoints": [
541
- {
542
- "url": "http://127.0.0.1:8080",
543
- "type": "llamacpp"
544
- }
545
- ]
546
- }
547
- ]`
548
- ```
549
-
550
- Start chat-ui with `npm run dev` and you should be able to chat with Zephyr locally.
551
-
552
- #### Ollama
553
-
554
- We also support the Ollama inference server. Spin up a model with
555
-
556
- ```cli
557
- ollama run mistral
558
- ```
559
-
560
- Then specify the endpoints like so:
561
-
562
- ```env
563
- MODELS=`[
564
- {
565
- "name": "Ollama Mistral",
566
- "chatPromptTemplate": "<s>{{#each messages}}{{#ifUser}}[INST] {{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}} {{content}} [/INST]{{/ifUser}}{{#ifAssistant}}{{content}}</s> {{/ifAssistant}}{{/each}}",
567
- "parameters": {
568
- "temperature": 0.1,
569
- "top_p": 0.95,
570
- "repetition_penalty": 1.2,
571
- "top_k": 50,
572
- "truncate": 3072,
573
- "max_new_tokens": 1024,
574
- "stop": ["</s>"]
575
- },
576
- "endpoints": [
577
- {
578
- "type": "ollama",
579
- "url" : "http://127.0.0.1:11434",
580
- "ollamaName" : "mistral"
581
- }
582
- ]
583
- }
584
- ]`
585
- ```
586
-
587
- #### Anthropic
588
-
589
- We also support Anthropic models (including multimodal ones via `multmodal: true`) through the official SDK. You may provide your API key via the `ANTHROPIC_API_KEY` env variable, or alternatively, through the `endpoints.apiKey` as per the following example.
590
-
591
- ```
592
- MODELS=`[
593
- {
594
- "name": "claude-3-haiku-20240307",
595
- "displayName": "Claude 3 Haiku",
596
- "description": "Fastest and most compact model for near-instant responsiveness",
597
- "multimodal": true,
598
- "parameters": {
599
- "max_new_tokens": 4096,
600
- },
601
- "endpoints": [
602
- {
603
- "type": "anthropic",
604
- // optionals
605
- "apiKey": "sk-ant-...",
606
- "baseURL": "https://api.anthropic.com",
607
- "defaultHeaders": {},
608
- "defaultQuery": {}
609
- }
610
- ]
611
- },
612
- {
613
- "name": "claude-3-sonnet-20240229",
614
- "displayName": "Claude 3 Sonnet",
615
- "description": "Ideal balance of intelligence and speed",
616
- "multimodal": true,
617
- "parameters": {
618
- "max_new_tokens": 4096,
619
- },
620
- "endpoints": [
621
- {
622
- "type": "anthropic",
623
- // optionals
624
- "apiKey": "sk-ant-...",
625
- "baseURL": "https://api.anthropic.com",
626
- "defaultHeaders": {},
627
- "defaultQuery": {}
628
- }
629
- ]
630
- },
631
- {
632
- "name": "claude-3-opus-20240229",
633
- "displayName": "Claude 3 Opus",
634
- "description": "Most powerful model for highly complex tasks",
635
- "multimodal": true,
636
- "parameters": {
637
- "max_new_tokens": 4096
638
- },
639
- "endpoints": [
640
- {
641
- "type": "anthropic",
642
- // optionals
643
- "apiKey": "sk-ant-...",
644
- "baseURL": "https://api.anthropic.com",
645
- "defaultHeaders": {},
646
- "defaultQuery": {}
647
- }
648
- ]
649
- }
650
- ]`
651
- ```
652
-
653
- We also support using Anthropic models running on Vertex AI. Authentication is done using Google Application Default Credentials. Project ID can be provided through the `endpoints.projectId` as per the following example:
654
-
655
- ```
656
- MODELS=`[
657
- {
658
- "name": "claude-3-sonnet@20240229",
659
- "displayName": "Claude 3 Sonnet",
660
- "description": "Ideal balance of intelligence and speed",
661
- "multimodal": true,
662
- "parameters": {
663
- "max_new_tokens": 4096,
664
- },
665
- "endpoints": [
666
- {
667
- "type": "anthropic-vertex",
668
- "region": "us-central1",
669
- "projectId": "gcp-project-id",
670
- // optionals
671
- "defaultHeaders": {},
672
- "defaultQuery": {}
673
- }
674
- ]
675
- },
676
- {
677
- "name": "claude-3-haiku@20240307",
678
- "displayName": "Claude 3 Haiku",
679
- "description": "Fastest, most compact model for near-instant responsiveness",
680
- "multimodal": true,
681
- "parameters": {
682
- "max_new_tokens": 4096
683
- },
684
- "endpoints": [
685
- {
686
- "type": "anthropic-vertex",
687
- "region": "us-central1",
688
- "projectId": "gcp-project-id",
689
- // optionals
690
- "defaultHeaders": {},
691
- "defaultQuery": {}
692
- }
693
- ]
694
- }
695
- ]`
696
- ```
697
-
698
- #### Amazon
699
-
700
- You can also specify your Amazon SageMaker instance as an endpoint for chat-ui. The config goes like this:
701
-
702
- ```env
703
- "endpoints": [
704
- {
705
- "type" : "aws",
706
- "service" : "sagemaker"
707
- "url": "",
708
- "accessKey": "",
709
- "secretKey" : "",
710
- "sessionToken": "",
711
- "region": "",
712
-
713
- "weight": 1
714
- }
715
- ]
716
- ```
717
-
718
- You can also set `"service" : "lambda"` to use a lambda instance.
719
-
720
- You can get the `accessKey` and `secretKey` from your AWS user, under programmatic access.
721
-
722
- #### Cloudflare Workers AI
723
-
724
- You can also use Cloudflare Workers AI to run your own models with serverless inference.
725
-
726
- You will need to have a Cloudflare account, then get your [account ID](https://developers.cloudflare.com/fundamentals/setup/find-account-and-zone-ids/) as well as your [API token](https://developers.cloudflare.com/workers-ai/get-started/rest-api/#1-get-api-token-and-account-id) for Workers AI.
727
-
728
- You can either specify them directly in your `.env.local` using the `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` variables, or you can set them directly in the endpoint config.
729
-
730
- You can find the list of models available on Cloudflare [here](https://developers.cloudflare.com/workers-ai/models/#text-generation).
731
-
732
- ```env
733
- {
734
- "name" : "nousresearch/hermes-2-pro-mistral-7b",
735
- "tokenizer": "nousresearch/hermes-2-pro-mistral-7b",
736
- "parameters": {
737
- "stop": ["<|im_end|>"]
738
- },
739
- "endpoints" : [
740
- {
741
- "type" : "cloudflare"
742
- <!-- optionally specify these
743
- "accountId": "your-account-id",
744
- "authToken": "your-api-token"
745
- -->
746
- }
747
- ]
748
- }
749
- ```
750
-
751
- #### Cohere
752
-
753
- You can also use Cohere to run their models directly from chat-ui. You will need to have a Cohere account, then get your [API token](https://dashboard.cohere.com/api-keys). You can either specify it directly in your `.env.local` using the `COHERE_API_TOKEN` variable, or you can set it in the endpoint config.
754
-
755
- Here is an example of a Cohere model config. You can set which model you want to use by setting the `id` field to the model name.
756
-
757
- ```env
758
- {
759
- "name" : "CohereForAI/c4ai-command-r-v01",
760
- "id": "command-r",
761
- "description": "C4AI Command-R is a research release of a 35 billion parameter highly performant generative model",
762
- "endpoints": [
763
- {
764
- "type": "cohere",
765
- <!-- optionally specify these, or use COHERE_API_TOKEN
766
- "apiKey": "your-api-token"
767
- -->
768
- }
769
- ]
770
- }
771
- ```
772
-
773
- ##### Google Vertex models
774
-
775
- Chat UI can connect to the google Vertex API endpoints ([List of supported models](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models)).
776
-
777
- To enable:
778
-
779
- 1. [Select](https://console.cloud.google.com/project) or [create](https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project) a Google Cloud project.
780
- 1. [Enable billing for your project](https://cloud.google.com/billing/docs/how-to/modify-project).
781
- 1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).
782
- 1. [Set up authentication with a service account](https://cloud.google.com/docs/authentication/getting-started)
783
- so you can access the API from your local workstation.
784
-
785
- The service account credentials file can be imported as an environmental variable:
786
-
787
- ```env
788
- GOOGLE_APPLICATION_CREDENTIALS = clientid.json
789
- ```
790
-
791
- Make sure your docker container has access to the file and the variable is correctly set.
792
- Afterwards Google Vertex endpoints can be configured as following:
793
-
794
- ```
795
- MODELS=`[
796
- //...
797
- {
798
- "name": "gemini-1.5-pro",
799
- "displayName": "Vertex Gemini Pro 1.5",
800
- "multimodal": true,
801
- "endpoints" : [{
802
- "type": "vertex",
803
- "project": "abc-xyz",
804
- "location": "europe-west3",
805
- "extraBody": {
806
- "model_version": "gemini-1.5-pro-preview-0409",
807
- },
808
-
809
- // Optional
810
- "safetyThreshold": "BLOCK_MEDIUM_AND_ABOVE",
811
- "apiEndpoint": "", // alternative api endpoint url,
812
- "tools": [{
813
- "googleSearchRetrieval": {
814
- "disableAttribution": true
815
- }
816
- }],
817
- "multimodal": {
818
- "image": {
819
- "supportedMimeTypes": ["image/png", "image/jpeg", "image/webp"],
820
- "preferredMimeType": "image/png",
821
- "maxSizeInMB": 5,
822
- "maxWidth": 2000,
823
- "maxHeight": 1000,
824
- }
825
- }
826
- }]
827
- },
828
- ]`
829
-
830
- ```
831
-
832
- ##### LangServe
833
-
834
- LangChain applications that are deployed using LangServe can be called with the following config:
835
-
836
- ```
837
- MODELS=`[
838
- //...
839
- {
840
- "name": "summarization-chain", //model-name
841
- "endpoints" : [{
842
- "type": "langserve",
843
- "url" : "http://127.0.0.1:8100",
844
- }]
845
- },
846
- ]`
847
-
848
- ```
849
-
850
- ### Model Context Protocol (MCP) Support (Upcoming)
851
-
852
- The project is planning to introduce support for the Model Context Protocol (MCP). MCP is a specification designed to standardize how language models receive and understand context from various sources. This will enable more flexible and powerful integrations, allowing models to seamlessly access and utilize a broader range of information, such as user history, external documents, or real-time data, in a structured way.
853
-
854
- This is an upcoming feature, and we believe it will significantly enhance the capabilities and extensibility of Chat UI.
855
-
856
- We are actively seeking contributions from the community to help design, implement, and integrate MCP support into Chat UI. If you are interested in shaping the future of how Chat UI handles model context and want to contribute to this exciting development, please look for issues tagged with 'MCP' or 'Model Context Protocol' on our issue tracker. Your expertise and input would be invaluable!
857
-
858
- ### Custom endpoint authorization
859
-
860
- #### Basic and Bearer
861
-
862
- Custom endpoints may require authorization, depending on how you configure them. Authentication will usually be set either with `Basic` or `Bearer`.
863
-
864
- For `Basic` we will need to generate a base64 encoding of the username and password.
865
-
866
- `echo -n "USER:PASS" | base64`
867
-
868
- > VVNFUjpQQVNT
869
-
870
- For `Bearer` you can use a token, which can be grabbed from [here](https://huggingface.co/settings/tokens).
871
-
872
- You can then add the generated information and the `authorization` parameter to your `.env.local`.
873
-
874
- ```env
875
- "endpoints": [
876
- {
877
- "url": "https://HOST:PORT",
878
- "authorization": "Basic VVNFUjpQQVNT",
879
- }
880
- ]
881
- ```
882
-
883
- Please note that if `HF_TOKEN` is also set or not empty, it will take precedence.
884
-
885
- #### Models hosted on multiple custom endpoints
886
-
887
- If the model being hosted will be available on multiple servers/instances add the `weight` parameter to your `.env.local`. The `weight` will be used to determine the probability of requesting a particular endpoint.
888
-
889
- ```env
890
- "endpoints": [
891
- {
892
- "url": "https://HOST:PORT",
893
- "weight": 1
894
- },
895
- {
896
- "url": "https://HOST:PORT",
897
- "weight": 2
898
- }
899
- ...
900
- ]
901
- ```
902
-
903
- #### Client Certificate Authentication (mTLS)
904
-
905
- Custom endpoints may require client certificate authentication, depending on how you configure them. To enable mTLS between Chat UI and your custom endpoint, you will need to set the `USE_CLIENT_CERTIFICATE` to `true`, and add the `CERT_PATH` and `KEY_PATH` parameters to your `.env.local`. These parameters should point to the location of the certificate and key files on your local machine. The certificate and key files should be in PEM format. The key file can be encrypted with a passphrase, in which case you will also need to add the `CLIENT_KEY_PASSWORD` parameter to your `.env.local`.
906
-
907
- If you're using a certificate signed by a private CA, you will also need to add the `CA_PATH` parameter to your `.env.local`. This parameter should point to the location of the CA certificate file on your local machine.
908
-
909
- If you're using a self-signed certificate, e.g. for testing or development purposes, you can set the `REJECT_UNAUTHORIZED` parameter to `false` in your `.env.local`. This will disable certificate validation, and allow Chat UI to connect to your custom endpoint.
910
-
911
- #### Specific Embedding Model
912
-
913
- A model can use any of the embedding models defined in `.env.local`, (currently used when web searching),
914
- by default it will use the first embedding model, but it can be changed with the field `embeddingModel`:
915
-
916
- ```env
917
- TEXT_EMBEDDING_MODELS = `[
918
- {
919
- "name": "Xenova/gte-small",
920
- "chunkCharLength": 512,
921
- "endpoints": [
922
- {"type": "transformersjs"}
923
- ]
924
- },
925
- {
926
- "name": "intfloat/e5-base-v2",
927
- "chunkCharLength": 768,
928
- "endpoints": [
929
- {"type": "tei", "url": "http://127.0.0.1:8080/", "authorization": "Basic VVNFUjpQQVNT"},
930
- {"type": "tei", "url": "http://127.0.0.1:8081/"}
931
- ]
932
- }
933
- ]`
934
-
935
- MODELS=`[
936
- {
937
- "name": "Ollama Mistral",
938
- "chatPromptTemplate": "...",
939
- "embeddingModel": "intfloat/e5-base-v2"
940
- "parameters": {
941
- ...
942
- },
943
- "endpoints": [
944
- ...
945
- ]
946
- }
947
- ]`
948
-
949
- ```
950
-
951
- ### Reasoning Models
952
-
953
- ChatUI supports specialized reasoning/Chain-of-Thought (CoT) models through the `reasoning` configuration field. When properly configured, this displays a UI widget that allows users to view or collapse the model’s reasoning steps. We support three types of reasoning parsing:
954
-
955
- #### Token-Based Delimitations
956
-
957
- For models like DeepSeek R1, token-based delimitations can be used to identify reasoning steps. This is done by specifying the `beginToken` and `endToken` fields in the `reasoning` configuration.
958
-
959
- Example configuration for DeepSeek R1 (token-based):
960
-
961
- ```json
962
- {
963
- "name": "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
964
- // ...
965
- "reasoning": {
966
- "type": "tokens",
967
- "beginToken": "<think>",
968
- "endToken": "</think>"
969
- }
970
- }
971
- ```
972
-
973
- #### Summarizing the Chain of Thought
974
-
975
- For models like QwQ, which return a chain of thought but do not explicitly provide a final answer, the `summarize` type can be used. This automatically summarizes the reasoning steps using the `TASK_MODEL` (or the first model in the configuration if `TASK_MODEL` is not specified) and displays the summary as the final answer.
976
-
977
- Example configuration for QwQ (summarize-based):
978
-
979
- ```json
980
- {
981
- "name": "Qwen/QwQ-32B-Preview",
982
- // ...
983
- "reasoning": {
984
- "type": "summarize"
985
- }
986
- }
987
- ```
988
-
989
- #### Regex-Based Delimitations
990
-
991
- In some cases, the final answer can be extracted from the model output using a regular expression. This is achieved by specifying the `regex` field in the `reasoning` configuration. For example, if your model wraps the final answer in a `\boxed{}` tag, you can use the following configuration:
992
-
993
- ```json
994
- {
995
- "name": "model/yourmodel",
996
- // ...
997
- "reasoning": {
998
- "type": "regex",
999
- "regex": "\\\\boxed\\{(.+?)\\}"
1000
- }
1001
- }
1002
- ```
1003
-
1004
- #### Enabling/Disabling Reasoning Summary
1005
-
1006
- You can toggle the summaries that are displayed alongside the CoT by changing the `REASONING_SUMMARY` env variable.
1007
-
1008
- ```env
1009
- REASONING_SUMMARY=false
1010
- ```
1011
-
1012
- ## Common issues
1013
-
1014
- ### 403:You don't have access to this conversation
1015
-
1016
- 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`.
1017
-
1018
- Make sure to set your `PUBLIC_ORIGIN` in your `.env.local` to the correct URL as well.
1019
-
1020
- ## Deploying to a HF Space
1021
-
1022
- 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.
1023
-
1024
- ## Building
1025
-
1026
- To create a production version of your app:
1027
-
1028
- ```bash
1029
- npm run build
1030
- ```
1031
-
1032
- You can preview the production build with `npm run preview`.
1033
-
1034
- > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
1035
-
1036
- ## Config changes for HuggingChat
1037
-
1038
- 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.
1039
-
1040
- > [!TIP]
1041
- > If you want to make changes to the model config used in production for HuggingChat, you should do so against `chart/env/prod.yaml`.
1042
-
1043
- ### Running a copy of HuggingChat locally
1044
-
1045
- If you want to run an exact copy of HuggingChat locally, you will need to do the following first:
1046
-
1047
- 1. Create an [OAuth App on the hub](https://huggingface.co/settings/applications/new) with `openid profile email` permissions. Make sure to set the callback URL to something like `http://localhost:5173/chat/login/callback` which matches the right path for your local instance.
1048
- 2. Create a [HF Token](https://huggingface.co/settings/tokens) with your Hugging Face account. You will need a Pro account to be able to access some of the larger models available through HuggingChat.
1049
- 3. Create a free account with [serper.dev](https://serper.dev/) (you will get 2500 free search queries)
1050
- 4. Run an instance of mongoDB, however you want. (Local or remote)
1051
-
1052
- You can then create a new `.env.SECRET_CONFIG` file with the following content
1053
-
1054
- ```env
1055
- MONGODB_URL=<link to your mongo DB from step 4>
1056
- HF_TOKEN=<your HF token from step 2>
1057
- OPENID_CONFIG=`{
1058
- PROVIDER_URL: "https://huggingface.co",
1059
- CLIENT_ID: "<your client ID from step 1>",
1060
- CLIENT_SECRET: "<your client secret from step 1>",
1061
- }`
1062
- SERPER_API_KEY=<your serper API key from step 3>
1063
- MESSAGES_BEFORE_LOGIN=<can be any numerical value, or set to 0 to require login>
1064
- ```
1065
-
1066
- 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.
1067
-
1068
- ### Populate database
1069
-
1070
- > [!WARNING]
1071
- > 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.
1072
-
1073
- You can populate the database using faker data using the `populate` script:
1074
-
1075
- ```bash
1076
- npm run populate <flags here>
1077
- ```
1078
-
1079
- At least one flag must be specified, the following flags are available:
1080
-
1081
- - `reset` - resets the database
1082
- - `all` - populates all tables
1083
- - `users` - populates the users table
1084
- - `settings` - populates the settings table for existing users
1085
- - `assistants` - populates the assistants table for existing users
1086
- - `conversations` - populates the conversations table for existing users
1087
-
1088
- For example, you could use it like so:
1089
-
1090
- ```bash
1091
- npm run populate reset
1092
- ```
1093
-
1094
- to clear out the database. Then login in the app to create your user and run the following command:
1095
-
1096
- ```bash
1097
- npm run populate users settings assistants conversations
1098
- ```
1099
-
1100
- to populate the database with fake data, including fake conversations and assistants for your user.
1101
-
1102
- ## Building the docker images locally
1103
-
1104
- You can build the docker images locally using the following commands:
1105
-
1106
- ```bash
1107
- docker build -t chat-ui-db:latest --build-arg INCLUDE_DB=true .
1108
- docker build -t chat-ui:latest --build-arg INCLUDE_DB=false .
1109
- 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 .
1110
- ```
1111
-
1112
- If you want to run the images with your local .env.local you have two options
1113
-
1114
- ```bash
1115
- DOTENV_LOCAL=$(<.env.local) docker run --network=host -e DOTENV_LOCAL chat-ui-db
1116
- ```
1117
-
1118
- ```bash
1119
- docker run --network=host --mount type=bind,source="$(pwd)/.env.local",target=/app/.env.local chat-ui-db
1120
- ```
 
1
+ ---
2
+ title: Test
3
+ emoji: 🏢
4
+ colorFrom: indigo
5
+ colorTo: gray
6
+ sdk: docker
7
+ pinned: false
8
+ ---
9
+
10
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README_SETUP.md ADDED
@@ -0,0 +1,1120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Chat UI
2
+
3
+ **Find the docs at [hf.co/docs/chat-ui](https://huggingface.co/docs/chat-ui/index).**
4
+
5
+ ![Chat UI repository thumbnail](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/chatui-websearch.png)
6
+
7
+ 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](https://huggingface.co/chat).
8
+
9
+ 0. [Quickstart](#quickstart)
10
+ 1. [No Setup Deploy](#no-setup-deploy)
11
+ 2. [Setup](#setup)
12
+ 3. [Launch](#launch)
13
+ 4. [Web Search](#web-search)
14
+ 5. [Text Embedding Models](#text-embedding-models)
15
+ 6. [Extra parameters](#extra-parameters)
16
+ 7. [Common issues](#common-issues)
17
+ 8. [Deploying to a HF Space](#deploying-to-a-hf-space)
18
+ 9. [Building](#building)
19
+
20
+ ## Quickstart
21
+
22
+ ### Docker image
23
+
24
+ You can deploy a chat-ui instance in a single command using the docker image. Get your huggingface token from [here](https://huggingface.co/settings/tokens).
25
+
26
+ ```bash
27
+ docker run -p 3000 -e HF_TOKEN=hf_*** -v db:/data ghcr.io/huggingface/chat-ui-db:latest
28
+ ```
29
+
30
+ Take a look at the [`.env` file](https://github.com/huggingface/chat-ui/blob/main/.env) and the readme to see all the environment variables that you can set. We have endpoint support for all OpenAI API compatible local services as well as many other providers like Anthropic, Cloudflare, Google Vertex AI, etc.
31
+
32
+ ### Local setup
33
+
34
+ You can quickly start a locally running chat-ui & LLM text-generation server thanks to chat-ui's [llama.cpp server support](https://huggingface.co/docs/chat-ui/configuration/models/providers/llamacpp).
35
+
36
+ **Step 1 (Start llama.cpp server):**
37
+
38
+ Install llama.cpp w/ brew (for Mac):
39
+
40
+ ```bash
41
+ # install llama.cpp
42
+ brew install llama.cpp
43
+ ```
44
+
45
+ or [build directly from the source](https://github.com/ggerganov/llama.cpp/blob/master/docs/build.md) for your target device:
46
+
47
+ ```
48
+ git clone https://github.com/ggerganov/llama.cpp && cd llama.cpp && make
49
+ ```
50
+
51
+ Next, start the server with the [LLM of your choice](https://huggingface.co/models?library=gguf):
52
+
53
+ ```bash
54
+ # start llama.cpp server (using hf.co/microsoft/Phi-3-mini-4k-instruct-gguf as an example)
55
+ llama-server --hf-repo microsoft/Phi-3-mini-4k-instruct-gguf --hf-file Phi-3-mini-4k-instruct-q4.gguf -c 4096
56
+ ```
57
+
58
+ A local LLaMA.cpp HTTP Server will start on `http://localhost:8080`. Read more [here](https://huggingface.co/docs/chat-ui/configuration/models/providers/llamacpp).
59
+
60
+ **Step 3 (make sure you have MongoDb running locally):**
61
+
62
+ ```bash
63
+ docker run -d -p 27017:27017 --name mongo-chatui mongo:latest
64
+ ```
65
+
66
+ Read more [here](#database).
67
+
68
+ **Step 4 (clone chat-ui):**
69
+
70
+ ```bash
71
+ git clone https://github.com/huggingface/chat-ui
72
+ cd chat-ui
73
+ ```
74
+
75
+ **Step 5 (tell chat-ui to use local llama.cpp server):**
76
+
77
+ Add the following to your `.env.local`:
78
+
79
+ ```ini
80
+ MODELS=`[
81
+ {
82
+ "name": "microsoft/Phi-3-mini-4k-instruct",
83
+ "endpoints": [{
84
+ "type" : "llamacpp",
85
+ "baseURL": "http://localhost:8080"
86
+ }],
87
+ },
88
+ ]`
89
+ ```
90
+
91
+ Read more [here](https://huggingface.co/docs/chat-ui/configuration/models/providers/llamacpp).
92
+
93
+ **Step 6 (start chat-ui):**
94
+
95
+ ```bash
96
+ npm install
97
+ npm run dev -- --open
98
+ ```
99
+
100
+ Read more [here](#launch).
101
+
102
+ <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/chat-ui/llamacpp-dark.png" height="auto"/>
103
+
104
+ ## No Setup Deploy
105
+
106
+ 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.
107
+
108
+ You can deploy your own customized Chat UI instance with any supported [LLM](https://huggingface.co/models?pipeline_tag=text-generation&sort=trending) of your choice on [Hugging Face Spaces](https://huggingface.co/spaces). To do so, use the chat-ui template [available here](https://huggingface.co/new-space?template=huggingchat/chat-ui-template).
109
+
110
+ Set `HF_TOKEN` in [Space secrets](https://huggingface.co/docs/hub/spaces-overview#managing-secrets) to deploy a model with gated access or a model in a private repository. It's also compatible with [Inference for PROs](https://huggingface.co/blog/inference-pro) curated list of powerful models with higher rate limits. Make sure to create your personal token first in your [User Access Tokens settings](https://huggingface.co/settings/tokens).
111
+
112
+ Read the full tutorial [here](https://huggingface.co/docs/hub/spaces-sdks-docker-chatui#chatui-on-spaces).
113
+
114
+ ## Setup
115
+
116
+ 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`.
117
+
118
+ 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:
119
+
120
+ ```env
121
+ MONGODB_URL=<the URL to your MongoDB instance>
122
+ HF_TOKEN=<your access token>
123
+ ```
124
+
125
+ ### Database
126
+
127
+ The chat history is stored in a MongoDB instance, and having a DB instance available is needed for Chat UI to work.
128
+
129
+ You can use a local MongoDB instance. The easiest way is to spin one up using docker:
130
+
131
+ ```bash
132
+ docker run -d -p 27017:27017 --name mongo-chatui mongo:latest
133
+ ```
134
+
135
+ In which case the url of your DB will be `MONGODB_URL=mongodb://localhost:27017`.
136
+
137
+ Alternatively, you can use a [free MongoDB Atlas](https://www.mongodb.com/pricing) 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.
138
+
139
+ ### Hugging Face Access Token
140
+
141
+ If you use a remote inference endpoint, you will need a Hugging Face access token to run Chat UI locally. You can get one from [your Hugging Face profile](https://huggingface.co/settings/tokens).
142
+
143
+ ## Launch
144
+
145
+ After you're done with the `.env.local` file you can run Chat UI locally with:
146
+
147
+ ```bash
148
+ npm install
149
+ npm run dev
150
+ ```
151
+
152
+ ## Web Search
153
+
154
+ Chat UI features a powerful Web Search feature. It works by:
155
+
156
+ 1. Generating an appropriate search query from the user prompt.
157
+ 2. Performing web search and extracting content from webpages.
158
+ 3. Creating embeddings from texts using a text embedding model.
159
+ 4. From these embeddings, find the ones that are closest to the user query using a vector similarity search. Specifically, we use `inner product` distance.
160
+ 5. Get the corresponding texts to those closest embeddings and perform [Retrieval-Augmented Generation](https://huggingface.co/papers/2005.11401) (i.e. expand user prompt by adding those texts so that an LLM can use this information).
161
+
162
+ ## Text Embedding Models
163
+
164
+ By default (for backward compatibility), when `TEXT_EMBEDDING_MODELS` environment variable is not defined, [transformers.js](https://huggingface.co/docs/transformers.js) embedding models will be used for embedding tasks, specifically, [Xenova/gte-small](https://huggingface.co/Xenova/gte-small) model.
165
+
166
+ You can customize the embedding model by setting `TEXT_EMBEDDING_MODELS` in your `.env.local` file. For example:
167
+
168
+ ```env
169
+ TEXT_EMBEDDING_MODELS = `[
170
+ {
171
+ "name": "Xenova/gte-small",
172
+ "displayName": "Xenova/gte-small",
173
+ "description": "locally running embedding",
174
+ "chunkCharLength": 512,
175
+ "endpoints": [
176
+ {"type": "transformersjs"}
177
+ ]
178
+ },
179
+ {
180
+ "name": "intfloat/e5-base-v2",
181
+ "displayName": "intfloat/e5-base-v2",
182
+ "description": "hosted embedding model",
183
+ "chunkCharLength": 768,
184
+ "preQuery": "query: ", # See https://huggingface.co/intfloat/e5-base-v2#faq
185
+ "prePassage": "passage: ", # See https://huggingface.co/intfloat/e5-base-v2#faq
186
+ "endpoints": [
187
+ {
188
+ "type": "tei",
189
+ "url": "http://127.0.0.1:8080/",
190
+ "authorization": "TOKEN_TYPE TOKEN" // optional authorization field. Example: "Basic VVNFUjpQQVNT"
191
+ }
192
+ ]
193
+ }
194
+ ]`
195
+ ```
196
+
197
+ The required fields are `name`, `chunkCharLength` and `endpoints`.
198
+ Supported text embedding backends are: [`transformers.js`](https://huggingface.co/docs/transformers.js), [`TEI`](https://github.com/huggingface/text-embeddings-inference) and [`OpenAI`](https://platform.openai.com/docs/guides/embeddings). `transformers.js` models run locally as part of `chat-ui`, whereas `TEI` models run in a different environment & accessed through an API endpoint. `openai` models are accessed through the [OpenAI API](https://platform.openai.com/docs/guides/embeddings).
199
+
200
+ When more than one embedding models are supplied in `.env.local` file, the first will be used by default, and the others will only be used on LLM's which configured `embeddingModel` to the name of the model.
201
+
202
+ ## Extra parameters
203
+
204
+ ### OpenID connect
205
+
206
+ 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:
207
+
208
+ ```env
209
+ OPENID_CONFIG=`{
210
+ PROVIDER_URL: "<your OIDC issuer>",
211
+ CLIENT_ID: "<your OIDC client ID>",
212
+ CLIENT_SECRET: "<your OIDC client secret>",
213
+ SCOPES: "openid profile",
214
+ TOLERANCE: // optional
215
+ RESOURCE: // optional
216
+ }`
217
+ ```
218
+
219
+ These variables will enable the openID sign-in modal for users.
220
+
221
+ ### Trusted header authentication
222
+
223
+ 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.
224
+
225
+ > [!WARNING]
226
+ > 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.
227
+
228
+ Here is a list of header names for common auth providers:
229
+
230
+ - Tailscale Serve: `Tailscale-User-Login`
231
+ - Cloudflare Access: `Cf-Access-Authenticated-User-Email`
232
+ - oauth2-proxy: `X-Forwarded-Email`
233
+
234
+ ### Theming
235
+
236
+ You can use a few environment variables to customize the look and feel of chat-ui. These are by default:
237
+
238
+ ```env
239
+ PUBLIC_APP_NAME=ChatUI
240
+ PUBLIC_APP_ASSETS=chatui
241
+ PUBLIC_APP_COLOR=blue
242
+ PUBLIC_APP_DESCRIPTION="Making the community's best AI chat models available to everyone."
243
+ PUBLIC_APP_DATA_SHARING=
244
+ PUBLIC_APP_DISCLAIMER=
245
+ ```
246
+
247
+ - `PUBLIC_APP_NAME` The name used as a title throughout the app.
248
+ - `PUBLIC_APP_ASSETS` Is used to find logos & favicons in `static/$PUBLIC_APP_ASSETS`, current options are `chatui` and `huggingchat`.
249
+ - `PUBLIC_APP_COLOR` Can be any of the [tailwind colors](https://tailwindcss.com/docs/customizing-colors#default-color-palette).
250
+ - `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.
251
+ - `PUBLIC_APP_DISCLAIMER` If set to 1, we show a disclaimer about generated outputs on login.
252
+
253
+ ### Web Search config
254
+
255
+ You can enable the web search through an API by adding `YDC_API_KEY` ([docs.you.com](https://docs.you.com)) or `SERPER_API_KEY` ([serper.dev](https://serper.dev/)) or `SERPAPI_KEY` ([serpapi.com](https://serpapi.com/)) or `SERPSTACK_API_KEY` ([serpstack.com](https://serpstack.com/)) or `SEARCHAPI_KEY` ([searchapi.io](https://www.searchapi.io/)) to your `.env.local`.
256
+
257
+ You can also simply enable the local google websearch by setting `USE_LOCAL_WEBSEARCH=true` in your `.env.local` or specify a SearXNG instance by adding the query URL to `SEARXNG_QUERY_URL`.
258
+
259
+ You can enable javascript when parsing webpages to improve compatibility with `WEBSEARCH_JAVASCRIPT=true` at the cost of increased CPU usage. You'll want at least 4 cores when enabling.
260
+
261
+ ### Custom models
262
+
263
+ You can customize the parameters passed to the model or even use a new model by updating the `MODELS` variable in your `.env.local`. The default one can be found in `.env` and looks like this :
264
+
265
+ ```env
266
+ MODELS=`[
267
+ {
268
+ "name": "mistralai/Mistral-7B-Instruct-v0.2",
269
+ "displayName": "mistralai/Mistral-7B-Instruct-v0.2",
270
+ "description": "Mistral 7B is a new Apache 2.0 model, released by Mistral AI that outperforms Llama2 13B in benchmarks.",
271
+ "websiteUrl": "https://mistral.ai/news/announcing-mistral-7b/",
272
+ "preprompt": "",
273
+ "chatPromptTemplate" : "<s>{{#each messages}}{{#ifUser}}[INST] {{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}}{{content}} [/INST]{{/ifUser}}{{#ifAssistant}}{{content}}</s>{{/ifAssistant}}{{/each}}",
274
+ "parameters": {
275
+ "temperature": 0.3,
276
+ "top_p": 0.95,
277
+ "repetition_penalty": 1.2,
278
+ "top_k": 50,
279
+ "truncate": 3072,
280
+ "max_new_tokens": 1024,
281
+ "stop": ["</s>"]
282
+ },
283
+ "promptExamples": [
284
+ {
285
+ "title": "Write an email",
286
+ "prompt": "As a restaurant owner, write a professional email to the supplier to get these products every week: \n\n- Wine (x10)\n- Eggs (x24)\n- Bread (x12)"
287
+ }, {
288
+ "title": "Code a game",
289
+ "prompt": "Code a basic snake game in python, give explanations for each step."
290
+ }, {
291
+ "title": "Recipe help",
292
+ "prompt": "How do I make a delicious lemon cheesecake?"
293
+ }
294
+ ]
295
+ }
296
+ ]`
297
+
298
+ ```
299
+
300
+ You can change things like the parameters, or customize the preprompt to better suit your needs. You can also add more models by adding more objects to the array, with different preprompts for example.
301
+
302
+ #### chatPromptTemplate
303
+
304
+ In 2025 most chat-completion endpoints (local or remotely hosted) support the OpenAI-compatible API and take arrays of messages.
305
+
306
+ If not, when querying the model for a chat response, the `chatPromptTemplate` template is used. `messages` is an array of chat messages, it has the format `[{ content: string }, ...]`. To identify if a message is a user message or an assistant message the `ifUser` and `ifAssistant` block helpers can be used.
307
+
308
+ The following is the default `chatPromptTemplate`, although newlines and indentiation have been added for readability. You can find the prompts used in production for HuggingChat [here](https://github.com/huggingface/chat-ui/blob/main/PROMPTS.md).
309
+
310
+ ```prompt
311
+ {{preprompt}}
312
+ {{#each messages}}
313
+ {{#ifUser}}{{@root.userMessageToken}}{{content}}{{@root.userMessageEndToken}}{{/ifUser}}
314
+ {{#ifAssistant}}{{@root.assistantMessageToken}}{{content}}{{@root.assistantMessageEndToken}}{{/ifAssistant}}
315
+ {{/each}}
316
+ {{assistantMessageToken}}
317
+ ```
318
+
319
+ > [!INFO]
320
+ > We also support Jinja2 templates for the `chatPromptTemplate` in addition to Handlebars templates. On startup we first try to compile with Jinja and if that fails we fall back to interpreting `chatPromptTemplate` as handlebars.
321
+
322
+ #### Multi modal model
323
+
324
+ We currently support [IDEFICS](https://huggingface.co/blog/idefics) (hosted on TGI), OpenAI and Claude 3 as multimodal models. You can enable it by setting `multimodal: true` in your `MODELS` configuration. For IDEFICS, you must have a [PRO HF Api token](https://huggingface.co/settings/tokens). For OpenAI, see the [OpenAI section](#openai-api-compatible-models). For Anthropic, see the [Anthropic section](#anthropic).
325
+
326
+ ```env
327
+ {
328
+ "name": "HuggingFaceM4/idefics-80b-instruct",
329
+ "multimodal" : true,
330
+ "description": "IDEFICS is the new multimodal model by Hugging Face.",
331
+ "preprompt": "",
332
+ "chatPromptTemplate" : "{{#each messages}}{{#ifUser}}User: {{content}}{{/ifUser}}<end_of_utterance>\nAssistant: {{#ifAssistant}}{{content}}\n{{/ifAssistant}}{{/each}}",
333
+ "parameters": {
334
+ "temperature": 0.1,
335
+ "top_p": 0.95,
336
+ "repetition_penalty": 1.2,
337
+ "top_k": 12,
338
+ "truncate": 1000,
339
+ "max_new_tokens": 1024,
340
+ "stop": ["<end_of_utterance>", "User:", "\nUser:"]
341
+ }
342
+ }
343
+ ```
344
+
345
+ #### Running your own models using a custom endpoint
346
+
347
+ If you want to, instead of hitting models on the Hugging Face Inference API, you can run your own models locally.
348
+
349
+ A good option is to hit a [text-generation-inference](https://github.com/huggingface/text-generation-inference), or a llama.cpp endpoint. You will find an example for TGI in the official [Chat UI Spaces Docker template](https://huggingface.co/new-space?template=huggingchat/chat-ui-template) for instance: both this app and a text-generation-inference server run inside the same container.
350
+
351
+ To do this, you can add your own endpoints to the `MODELS` variable in `.env.local`, by adding an `"endpoints"` key for each model in `MODELS`.
352
+
353
+ ```env
354
+ {
355
+ // rest of the model config here
356
+ "endpoints": [{
357
+ "type" : "tgi",
358
+ "url": "https://HOST:PORT",
359
+ }]
360
+ }
361
+ ```
362
+
363
+ If `endpoints` are left unspecified, ChatUI will look for the model on the hosted Hugging Face inference API using the model name.
364
+
365
+ ##### OpenAI API compatible models
366
+
367
+ Chat UI can be used with any API server that supports OpenAI API compatibility, for example [text-generation-webui](https://github.com/oobabooga/text-generation-webui/tree/main/extensions/openai), [LocalAI](https://github.com/go-skynet/LocalAI), [FastChat](https://github.com/lm-sys/FastChat/blob/main/docs/openai_api.md), [llama-cpp-python](https://github.com/abetlen/llama-cpp-python), and [ialacol](https://github.com/chenhunghan/ialacol) and [vllm](https://docs.vllm.ai/en/latest/serving/openai_compatible_server.html).
368
+
369
+ The following example config makes Chat UI works with [text-generation-webui](https://github.com/oobabooga/text-generation-webui/tree/main/extensions/openai), the `endpoint.baseUrl` is the url of the OpenAI API compatible server, this overrides the baseUrl to be used by OpenAI instance. The `endpoint.completion` determine which endpoint to be used, default is `chat_completions` which uses `v1/chat/completions`, change to `endpoint.completion` to `completions` to use the `v1/completions` endpoint.
370
+
371
+ Parameters not supported by OpenAI (e.g., top_k, repetition_penalty, etc.) must be set in the extraBody of endpoints. Be aware that setting them in parameters will cause them to be omitted.
372
+
373
+ ```
374
+ MODELS=`[
375
+ {
376
+ "name": "text-generation-webui",
377
+ "id": "text-generation-webui",
378
+ "parameters": {
379
+ "temperature": 0.9,
380
+ "top_p": 0.95,
381
+ "max_new_tokens": 1024,
382
+ "stop": []
383
+ },
384
+ "endpoints": [{
385
+ "type" : "openai",
386
+ "baseURL": "http://localhost:8000/v1",
387
+ "extraBody": {
388
+ "repetition_penalty": 1.2,
389
+ "top_k": 50,
390
+ "truncate": 1000
391
+ }
392
+ }]
393
+ }
394
+ ]`
395
+
396
+ ```
397
+
398
+ The `openai` type includes official OpenAI models. You can add, for example, GPT4/GPT3.5 as a "openai" model:
399
+
400
+ ```
401
+ OPENAI_API_KEY=#your openai api key here
402
+ MODELS=`[{
403
+ "name": "gpt-4",
404
+ "displayName": "GPT 4",
405
+ "endpoints" : [{
406
+ "type": "openai"
407
+ }]
408
+ },
409
+ {
410
+ "name": "gpt-3.5-turbo",
411
+ "displayName": "GPT 3.5 Turbo",
412
+ "endpoints" : [{
413
+ "type": "openai"
414
+ }]
415
+ }]`
416
+ ```
417
+
418
+ You may also consume any model provider that provides compatible OpenAI API endpoint. For example, you may self-host [Portkey](https://github.com/Portkey-AI/gateway) gateway and experiment with Claude or GPTs offered by Azure OpenAI. Example for Claude from Anthropic:
419
+
420
+ ```
421
+ MODELS=`[{
422
+ "name": "claude-2.1",
423
+ "displayName": "Claude 2.1",
424
+ "description": "Anthropic has been founded by former OpenAI researchers...",
425
+ "parameters": {
426
+ "temperature": 0.5,
427
+ "max_new_tokens": 4096,
428
+ },
429
+ "endpoints": [
430
+ {
431
+ "type": "openai",
432
+ "baseURL": "https://gateway.example.com/v1",
433
+ "defaultHeaders": {
434
+ "x-portkey-config": '{"provider":"anthropic","api_key":"sk-ant-abc...xyz"}'
435
+ }
436
+ }
437
+ ]
438
+ }]`
439
+ ```
440
+
441
+ Example for GPT 4 deployed on Azure OpenAI:
442
+
443
+ ```
444
+ MODELS=`[{
445
+ "id": "gpt-4-1106-preview",
446
+ "name": "gpt-4-1106-preview",
447
+ "displayName": "gpt-4-1106-preview",
448
+ "parameters": {
449
+ "temperature": 0.5,
450
+ "max_new_tokens": 4096,
451
+ },
452
+ "endpoints": [
453
+ {
454
+ "type": "openai",
455
+ "baseURL": "https://{resource-name}.openai.azure.com/openai/deployments/{deployment-id}",
456
+ "defaultHeaders": {
457
+ "api-key": "{api-key}"
458
+ },
459
+ "defaultQuery": {
460
+ "api-version": "2023-05-15"
461
+ }
462
+ }
463
+ ]
464
+ }]`
465
+ ```
466
+
467
+ Or try Mistral from [Deepinfra](https://deepinfra.com/mistralai/Mistral-7B-Instruct-v0.1/api?example=openai-http):
468
+
469
+ > Note, apiKey can either be set custom per endpoint, or globally using `OPENAI_API_KEY` variable.
470
+
471
+ ```
472
+ MODELS=`[{
473
+ "name": "mistral-7b",
474
+ "displayName": "Mistral 7B",
475
+ "description": "A 7B dense Transformer, fast-deployed and easily customisable. Small, yet powerful for a variety of use cases. Supports English and code, and a 8k context window.",
476
+ "parameters": {
477
+ "temperature": 0.5,
478
+ "max_new_tokens": 4096,
479
+ },
480
+ "endpoints": [
481
+ {
482
+ "type": "openai",
483
+ "baseURL": "https://api.deepinfra.com/v1/openai",
484
+ "apiKey": "abc...xyz"
485
+ }
486
+ ]
487
+ }]`
488
+ ```
489
+
490
+ _Non-streaming endpoints_
491
+
492
+ For endpoints that don´t support streaming like o1 on Azure, you can pass `streamingSupported: false` in your endpoint config:
493
+
494
+ ```
495
+ MODELS=`[{
496
+ "id": "o1-preview",
497
+ "name": "o1-preview",
498
+ "displayName": "o1-preview",
499
+ "systemRoleSupported": false,
500
+ "endpoints": [
501
+ {
502
+ "type": "openai",
503
+ "baseURL": "https://my-deployment.openai.azure.com/openai/deployments/o1-preview",
504
+ "defaultHeaders": {
505
+ "api-key": "$SECRET"
506
+ },
507
+ "streamingSupported": false,
508
+ }
509
+ ]
510
+ }]`
511
+ ```
512
+
513
+ ##### Llama.cpp API server
514
+
515
+ chat-ui also supports the llama.cpp API server directly without the need for an adapter. You can do this using the `llamacpp` endpoint type.
516
+
517
+ If you want to run Chat UI with llama.cpp, you can do the following, using [microsoft/Phi-3-mini-4k-instruct-gguf](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-gguf) as an example model:
518
+
519
+ ```bash
520
+ # install llama.cpp
521
+ brew install llama.cpp
522
+ # start llama.cpp server
523
+ llama-server --hf-repo microsoft/Phi-3-mini-4k-instruct-gguf --hf-file Phi-3-mini-4k-instruct-q4.gguf -c 4096
524
+ ```
525
+
526
+ ```env
527
+ MODELS=`[
528
+ {
529
+ "name": "Local Zephyr",
530
+ "chatPromptTemplate": "<|system|>\n{{preprompt}}</s>\n{{#each messages}}{{#ifUser}}<|user|>\n{{content}}</s>\n<|assistant|>\n{{/ifUser}}{{#ifAssistant}}{{content}}</s>\n{{/ifAssistant}}{{/each}}",
531
+ "parameters": {
532
+ "temperature": 0.1,
533
+ "top_p": 0.95,
534
+ "repetition_penalty": 1.2,
535
+ "top_k": 50,
536
+ "truncate": 1000,
537
+ "max_new_tokens": 2048,
538
+ "stop": ["</s>"]
539
+ },
540
+ "endpoints": [
541
+ {
542
+ "url": "http://127.0.0.1:8080",
543
+ "type": "llamacpp"
544
+ }
545
+ ]
546
+ }
547
+ ]`
548
+ ```
549
+
550
+ Start chat-ui with `npm run dev` and you should be able to chat with Zephyr locally.
551
+
552
+ #### Ollama
553
+
554
+ We also support the Ollama inference server. Spin up a model with
555
+
556
+ ```cli
557
+ ollama run mistral
558
+ ```
559
+
560
+ Then specify the endpoints like so:
561
+
562
+ ```env
563
+ MODELS=`[
564
+ {
565
+ "name": "Ollama Mistral",
566
+ "chatPromptTemplate": "<s>{{#each messages}}{{#ifUser}}[INST] {{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}} {{content}} [/INST]{{/ifUser}}{{#ifAssistant}}{{content}}</s> {{/ifAssistant}}{{/each}}",
567
+ "parameters": {
568
+ "temperature": 0.1,
569
+ "top_p": 0.95,
570
+ "repetition_penalty": 1.2,
571
+ "top_k": 50,
572
+ "truncate": 3072,
573
+ "max_new_tokens": 1024,
574
+ "stop": ["</s>"]
575
+ },
576
+ "endpoints": [
577
+ {
578
+ "type": "ollama",
579
+ "url" : "http://127.0.0.1:11434",
580
+ "ollamaName" : "mistral"
581
+ }
582
+ ]
583
+ }
584
+ ]`
585
+ ```
586
+
587
+ #### Anthropic
588
+
589
+ We also support Anthropic models (including multimodal ones via `multmodal: true`) through the official SDK. You may provide your API key via the `ANTHROPIC_API_KEY` env variable, or alternatively, through the `endpoints.apiKey` as per the following example.
590
+
591
+ ```
592
+ MODELS=`[
593
+ {
594
+ "name": "claude-3-haiku-20240307",
595
+ "displayName": "Claude 3 Haiku",
596
+ "description": "Fastest and most compact model for near-instant responsiveness",
597
+ "multimodal": true,
598
+ "parameters": {
599
+ "max_new_tokens": 4096,
600
+ },
601
+ "endpoints": [
602
+ {
603
+ "type": "anthropic",
604
+ // optionals
605
+ "apiKey": "sk-ant-...",
606
+ "baseURL": "https://api.anthropic.com",
607
+ "defaultHeaders": {},
608
+ "defaultQuery": {}
609
+ }
610
+ ]
611
+ },
612
+ {
613
+ "name": "claude-3-sonnet-20240229",
614
+ "displayName": "Claude 3 Sonnet",
615
+ "description": "Ideal balance of intelligence and speed",
616
+ "multimodal": true,
617
+ "parameters": {
618
+ "max_new_tokens": 4096,
619
+ },
620
+ "endpoints": [
621
+ {
622
+ "type": "anthropic",
623
+ // optionals
624
+ "apiKey": "sk-ant-...",
625
+ "baseURL": "https://api.anthropic.com",
626
+ "defaultHeaders": {},
627
+ "defaultQuery": {}
628
+ }
629
+ ]
630
+ },
631
+ {
632
+ "name": "claude-3-opus-20240229",
633
+ "displayName": "Claude 3 Opus",
634
+ "description": "Most powerful model for highly complex tasks",
635
+ "multimodal": true,
636
+ "parameters": {
637
+ "max_new_tokens": 4096
638
+ },
639
+ "endpoints": [
640
+ {
641
+ "type": "anthropic",
642
+ // optionals
643
+ "apiKey": "sk-ant-...",
644
+ "baseURL": "https://api.anthropic.com",
645
+ "defaultHeaders": {},
646
+ "defaultQuery": {}
647
+ }
648
+ ]
649
+ }
650
+ ]`
651
+ ```
652
+
653
+ We also support using Anthropic models running on Vertex AI. Authentication is done using Google Application Default Credentials. Project ID can be provided through the `endpoints.projectId` as per the following example:
654
+
655
+ ```
656
+ MODELS=`[
657
+ {
658
+ "name": "claude-3-sonnet@20240229",
659
+ "displayName": "Claude 3 Sonnet",
660
+ "description": "Ideal balance of intelligence and speed",
661
+ "multimodal": true,
662
+ "parameters": {
663
+ "max_new_tokens": 4096,
664
+ },
665
+ "endpoints": [
666
+ {
667
+ "type": "anthropic-vertex",
668
+ "region": "us-central1",
669
+ "projectId": "gcp-project-id",
670
+ // optionals
671
+ "defaultHeaders": {},
672
+ "defaultQuery": {}
673
+ }
674
+ ]
675
+ },
676
+ {
677
+ "name": "claude-3-haiku@20240307",
678
+ "displayName": "Claude 3 Haiku",
679
+ "description": "Fastest, most compact model for near-instant responsiveness",
680
+ "multimodal": true,
681
+ "parameters": {
682
+ "max_new_tokens": 4096
683
+ },
684
+ "endpoints": [
685
+ {
686
+ "type": "anthropic-vertex",
687
+ "region": "us-central1",
688
+ "projectId": "gcp-project-id",
689
+ // optionals
690
+ "defaultHeaders": {},
691
+ "defaultQuery": {}
692
+ }
693
+ ]
694
+ }
695
+ ]`
696
+ ```
697
+
698
+ #### Amazon
699
+
700
+ You can also specify your Amazon SageMaker instance as an endpoint for chat-ui. The config goes like this:
701
+
702
+ ```env
703
+ "endpoints": [
704
+ {
705
+ "type" : "aws",
706
+ "service" : "sagemaker"
707
+ "url": "",
708
+ "accessKey": "",
709
+ "secretKey" : "",
710
+ "sessionToken": "",
711
+ "region": "",
712
+
713
+ "weight": 1
714
+ }
715
+ ]
716
+ ```
717
+
718
+ You can also set `"service" : "lambda"` to use a lambda instance.
719
+
720
+ You can get the `accessKey` and `secretKey` from your AWS user, under programmatic access.
721
+
722
+ #### Cloudflare Workers AI
723
+
724
+ You can also use Cloudflare Workers AI to run your own models with serverless inference.
725
+
726
+ You will need to have a Cloudflare account, then get your [account ID](https://developers.cloudflare.com/fundamentals/setup/find-account-and-zone-ids/) as well as your [API token](https://developers.cloudflare.com/workers-ai/get-started/rest-api/#1-get-api-token-and-account-id) for Workers AI.
727
+
728
+ You can either specify them directly in your `.env.local` using the `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` variables, or you can set them directly in the endpoint config.
729
+
730
+ You can find the list of models available on Cloudflare [here](https://developers.cloudflare.com/workers-ai/models/#text-generation).
731
+
732
+ ```env
733
+ {
734
+ "name" : "nousresearch/hermes-2-pro-mistral-7b",
735
+ "tokenizer": "nousresearch/hermes-2-pro-mistral-7b",
736
+ "parameters": {
737
+ "stop": ["<|im_end|>"]
738
+ },
739
+ "endpoints" : [
740
+ {
741
+ "type" : "cloudflare"
742
+ <!-- optionally specify these
743
+ "accountId": "your-account-id",
744
+ "authToken": "your-api-token"
745
+ -->
746
+ }
747
+ ]
748
+ }
749
+ ```
750
+
751
+ #### Cohere
752
+
753
+ You can also use Cohere to run their models directly from chat-ui. You will need to have a Cohere account, then get your [API token](https://dashboard.cohere.com/api-keys). You can either specify it directly in your `.env.local` using the `COHERE_API_TOKEN` variable, or you can set it in the endpoint config.
754
+
755
+ Here is an example of a Cohere model config. You can set which model you want to use by setting the `id` field to the model name.
756
+
757
+ ```env
758
+ {
759
+ "name" : "CohereForAI/c4ai-command-r-v01",
760
+ "id": "command-r",
761
+ "description": "C4AI Command-R is a research release of a 35 billion parameter highly performant generative model",
762
+ "endpoints": [
763
+ {
764
+ "type": "cohere",
765
+ <!-- optionally specify these, or use COHERE_API_TOKEN
766
+ "apiKey": "your-api-token"
767
+ -->
768
+ }
769
+ ]
770
+ }
771
+ ```
772
+
773
+ ##### Google Vertex models
774
+
775
+ Chat UI can connect to the google Vertex API endpoints ([List of supported models](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models)).
776
+
777
+ To enable:
778
+
779
+ 1. [Select](https://console.cloud.google.com/project) or [create](https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project) a Google Cloud project.
780
+ 1. [Enable billing for your project](https://cloud.google.com/billing/docs/how-to/modify-project).
781
+ 1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).
782
+ 1. [Set up authentication with a service account](https://cloud.google.com/docs/authentication/getting-started)
783
+ so you can access the API from your local workstation.
784
+
785
+ The service account credentials file can be imported as an environmental variable:
786
+
787
+ ```env
788
+ GOOGLE_APPLICATION_CREDENTIALS = clientid.json
789
+ ```
790
+
791
+ Make sure your docker container has access to the file and the variable is correctly set.
792
+ Afterwards Google Vertex endpoints can be configured as following:
793
+
794
+ ```
795
+ MODELS=`[
796
+ //...
797
+ {
798
+ "name": "gemini-1.5-pro",
799
+ "displayName": "Vertex Gemini Pro 1.5",
800
+ "multimodal": true,
801
+ "endpoints" : [{
802
+ "type": "vertex",
803
+ "project": "abc-xyz",
804
+ "location": "europe-west3",
805
+ "extraBody": {
806
+ "model_version": "gemini-1.5-pro-preview-0409",
807
+ },
808
+
809
+ // Optional
810
+ "safetyThreshold": "BLOCK_MEDIUM_AND_ABOVE",
811
+ "apiEndpoint": "", // alternative api endpoint url,
812
+ "tools": [{
813
+ "googleSearchRetrieval": {
814
+ "disableAttribution": true
815
+ }
816
+ }],
817
+ "multimodal": {
818
+ "image": {
819
+ "supportedMimeTypes": ["image/png", "image/jpeg", "image/webp"],
820
+ "preferredMimeType": "image/png",
821
+ "maxSizeInMB": 5,
822
+ "maxWidth": 2000,
823
+ "maxHeight": 1000,
824
+ }
825
+ }
826
+ }]
827
+ },
828
+ ]`
829
+
830
+ ```
831
+
832
+ ##### LangServe
833
+
834
+ LangChain applications that are deployed using LangServe can be called with the following config:
835
+
836
+ ```
837
+ MODELS=`[
838
+ //...
839
+ {
840
+ "name": "summarization-chain", //model-name
841
+ "endpoints" : [{
842
+ "type": "langserve",
843
+ "url" : "http://127.0.0.1:8100",
844
+ }]
845
+ },
846
+ ]`
847
+
848
+ ```
849
+
850
+ ### Model Context Protocol (MCP) Support (Upcoming)
851
+
852
+ The project is planning to introduce support for the Model Context Protocol (MCP). MCP is a specification designed to standardize how language models receive and understand context from various sources. This will enable more flexible and powerful integrations, allowing models to seamlessly access and utilize a broader range of information, such as user history, external documents, or real-time data, in a structured way.
853
+
854
+ This is an upcoming feature, and we believe it will significantly enhance the capabilities and extensibility of Chat UI.
855
+
856
+ We are actively seeking contributions from the community to help design, implement, and integrate MCP support into Chat UI. If you are interested in shaping the future of how Chat UI handles model context and want to contribute to this exciting development, please look for issues tagged with 'MCP' or 'Model Context Protocol' on our issue tracker. Your expertise and input would be invaluable!
857
+
858
+ ### Custom endpoint authorization
859
+
860
+ #### Basic and Bearer
861
+
862
+ Custom endpoints may require authorization, depending on how you configure them. Authentication will usually be set either with `Basic` or `Bearer`.
863
+
864
+ For `Basic` we will need to generate a base64 encoding of the username and password.
865
+
866
+ `echo -n "USER:PASS" | base64`
867
+
868
+ > VVNFUjpQQVNT
869
+
870
+ For `Bearer` you can use a token, which can be grabbed from [here](https://huggingface.co/settings/tokens).
871
+
872
+ You can then add the generated information and the `authorization` parameter to your `.env.local`.
873
+
874
+ ```env
875
+ "endpoints": [
876
+ {
877
+ "url": "https://HOST:PORT",
878
+ "authorization": "Basic VVNFUjpQQVNT",
879
+ }
880
+ ]
881
+ ```
882
+
883
+ Please note that if `HF_TOKEN` is also set or not empty, it will take precedence.
884
+
885
+ #### Models hosted on multiple custom endpoints
886
+
887
+ If the model being hosted will be available on multiple servers/instances add the `weight` parameter to your `.env.local`. The `weight` will be used to determine the probability of requesting a particular endpoint.
888
+
889
+ ```env
890
+ "endpoints": [
891
+ {
892
+ "url": "https://HOST:PORT",
893
+ "weight": 1
894
+ },
895
+ {
896
+ "url": "https://HOST:PORT",
897
+ "weight": 2
898
+ }
899
+ ...
900
+ ]
901
+ ```
902
+
903
+ #### Client Certificate Authentication (mTLS)
904
+
905
+ Custom endpoints may require client certificate authentication, depending on how you configure them. To enable mTLS between Chat UI and your custom endpoint, you will need to set the `USE_CLIENT_CERTIFICATE` to `true`, and add the `CERT_PATH` and `KEY_PATH` parameters to your `.env.local`. These parameters should point to the location of the certificate and key files on your local machine. The certificate and key files should be in PEM format. The key file can be encrypted with a passphrase, in which case you will also need to add the `CLIENT_KEY_PASSWORD` parameter to your `.env.local`.
906
+
907
+ If you're using a certificate signed by a private CA, you will also need to add the `CA_PATH` parameter to your `.env.local`. This parameter should point to the location of the CA certificate file on your local machine.
908
+
909
+ If you're using a self-signed certificate, e.g. for testing or development purposes, you can set the `REJECT_UNAUTHORIZED` parameter to `false` in your `.env.local`. This will disable certificate validation, and allow Chat UI to connect to your custom endpoint.
910
+
911
+ #### Specific Embedding Model
912
+
913
+ A model can use any of the embedding models defined in `.env.local`, (currently used when web searching),
914
+ by default it will use the first embedding model, but it can be changed with the field `embeddingModel`:
915
+
916
+ ```env
917
+ TEXT_EMBEDDING_MODELS = `[
918
+ {
919
+ "name": "Xenova/gte-small",
920
+ "chunkCharLength": 512,
921
+ "endpoints": [
922
+ {"type": "transformersjs"}
923
+ ]
924
+ },
925
+ {
926
+ "name": "intfloat/e5-base-v2",
927
+ "chunkCharLength": 768,
928
+ "endpoints": [
929
+ {"type": "tei", "url": "http://127.0.0.1:8080/", "authorization": "Basic VVNFUjpQQVNT"},
930
+ {"type": "tei", "url": "http://127.0.0.1:8081/"}
931
+ ]
932
+ }
933
+ ]`
934
+
935
+ MODELS=`[
936
+ {
937
+ "name": "Ollama Mistral",
938
+ "chatPromptTemplate": "...",
939
+ "embeddingModel": "intfloat/e5-base-v2"
940
+ "parameters": {
941
+ ...
942
+ },
943
+ "endpoints": [
944
+ ...
945
+ ]
946
+ }
947
+ ]`
948
+
949
+ ```
950
+
951
+ ### Reasoning Models
952
+
953
+ ChatUI supports specialized reasoning/Chain-of-Thought (CoT) models through the `reasoning` configuration field. When properly configured, this displays a UI widget that allows users to view or collapse the model’s reasoning steps. We support three types of reasoning parsing:
954
+
955
+ #### Token-Based Delimitations
956
+
957
+ For models like DeepSeek R1, token-based delimitations can be used to identify reasoning steps. This is done by specifying the `beginToken` and `endToken` fields in the `reasoning` configuration.
958
+
959
+ Example configuration for DeepSeek R1 (token-based):
960
+
961
+ ```json
962
+ {
963
+ "name": "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
964
+ // ...
965
+ "reasoning": {
966
+ "type": "tokens",
967
+ "beginToken": "<think>",
968
+ "endToken": "</think>"
969
+ }
970
+ }
971
+ ```
972
+
973
+ #### Summarizing the Chain of Thought
974
+
975
+ For models like QwQ, which return a chain of thought but do not explicitly provide a final answer, the `summarize` type can be used. This automatically summarizes the reasoning steps using the `TASK_MODEL` (or the first model in the configuration if `TASK_MODEL` is not specified) and displays the summary as the final answer.
976
+
977
+ Example configuration for QwQ (summarize-based):
978
+
979
+ ```json
980
+ {
981
+ "name": "Qwen/QwQ-32B-Preview",
982
+ // ...
983
+ "reasoning": {
984
+ "type": "summarize"
985
+ }
986
+ }
987
+ ```
988
+
989
+ #### Regex-Based Delimitations
990
+
991
+ In some cases, the final answer can be extracted from the model output using a regular expression. This is achieved by specifying the `regex` field in the `reasoning` configuration. For example, if your model wraps the final answer in a `\boxed{}` tag, you can use the following configuration:
992
+
993
+ ```json
994
+ {
995
+ "name": "model/yourmodel",
996
+ // ...
997
+ "reasoning": {
998
+ "type": "regex",
999
+ "regex": "\\\\boxed\\{(.+?)\\}"
1000
+ }
1001
+ }
1002
+ ```
1003
+
1004
+ #### Enabling/Disabling Reasoning Summary
1005
+
1006
+ You can toggle the summaries that are displayed alongside the CoT by changing the `REASONING_SUMMARY` env variable.
1007
+
1008
+ ```env
1009
+ REASONING_SUMMARY=false
1010
+ ```
1011
+
1012
+ ## Common issues
1013
+
1014
+ ### 403:You don't have access to this conversation
1015
+
1016
+ 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`.
1017
+
1018
+ Make sure to set your `PUBLIC_ORIGIN` in your `.env.local` to the correct URL as well.
1019
+
1020
+ ## Deploying to a HF Space
1021
+
1022
+ 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.
1023
+
1024
+ ## Building
1025
+
1026
+ To create a production version of your app:
1027
+
1028
+ ```bash
1029
+ npm run build
1030
+ ```
1031
+
1032
+ You can preview the production build with `npm run preview`.
1033
+
1034
+ > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
1035
+
1036
+ ## Config changes for HuggingChat
1037
+
1038
+ 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.
1039
+
1040
+ > [!TIP]
1041
+ > If you want to make changes to the model config used in production for HuggingChat, you should do so against `chart/env/prod.yaml`.
1042
+
1043
+ ### Running a copy of HuggingChat locally
1044
+
1045
+ If you want to run an exact copy of HuggingChat locally, you will need to do the following first:
1046
+
1047
+ 1. Create an [OAuth App on the hub](https://huggingface.co/settings/applications/new) with `openid profile email` permissions. Make sure to set the callback URL to something like `http://localhost:5173/chat/login/callback` which matches the right path for your local instance.
1048
+ 2. Create a [HF Token](https://huggingface.co/settings/tokens) with your Hugging Face account. You will need a Pro account to be able to access some of the larger models available through HuggingChat.
1049
+ 3. Create a free account with [serper.dev](https://serper.dev/) (you will get 2500 free search queries)
1050
+ 4. Run an instance of mongoDB, however you want. (Local or remote)
1051
+
1052
+ You can then create a new `.env.SECRET_CONFIG` file with the following content
1053
+
1054
+ ```env
1055
+ MONGODB_URL=<link to your mongo DB from step 4>
1056
+ HF_TOKEN=<your HF token from step 2>
1057
+ OPENID_CONFIG=`{
1058
+ PROVIDER_URL: "https://huggingface.co",
1059
+ CLIENT_ID: "<your client ID from step 1>",
1060
+ CLIENT_SECRET: "<your client secret from step 1>",
1061
+ }`
1062
+ SERPER_API_KEY=<your serper API key from step 3>
1063
+ MESSAGES_BEFORE_LOGIN=<can be any numerical value, or set to 0 to require login>
1064
+ ```
1065
+
1066
+ 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.
1067
+
1068
+ ### Populate database
1069
+
1070
+ > [!WARNING]
1071
+ > 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.
1072
+
1073
+ You can populate the database using faker data using the `populate` script:
1074
+
1075
+ ```bash
1076
+ npm run populate <flags here>
1077
+ ```
1078
+
1079
+ At least one flag must be specified, the following flags are available:
1080
+
1081
+ - `reset` - resets the database
1082
+ - `all` - populates all tables
1083
+ - `users` - populates the users table
1084
+ - `settings` - populates the settings table for existing users
1085
+ - `assistants` - populates the assistants table for existing users
1086
+ - `conversations` - populates the conversations table for existing users
1087
+
1088
+ For example, you could use it like so:
1089
+
1090
+ ```bash
1091
+ npm run populate reset
1092
+ ```
1093
+
1094
+ to clear out the database. Then login in the app to create your user and run the following command:
1095
+
1096
+ ```bash
1097
+ npm run populate users settings assistants conversations
1098
+ ```
1099
+
1100
+ to populate the database with fake data, including fake conversations and assistants for your user.
1101
+
1102
+ ## Building the docker images locally
1103
+
1104
+ You can build the docker images locally using the following commands:
1105
+
1106
+ ```bash
1107
+ docker build -t chat-ui-db:latest --build-arg INCLUDE_DB=true .
1108
+ docker build -t chat-ui:latest --build-arg INCLUDE_DB=false .
1109
+ 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 .
1110
+ ```
1111
+
1112
+ If you want to run the images with your local .env.local you have two options
1113
+
1114
+ ```bash
1115
+ DOTENV_LOCAL=$(<.env.local) docker run --network=host -e DOTENV_LOCAL chat-ui-db
1116
+ ```
1117
+
1118
+ ```bash
1119
+ docker run --network=host --mount type=bind,source="$(pwd)/.env.local",target=/app/.env.local chat-ui-db
1120
+ ```