Huggingface IT commited on
Commit
1035425
·
1 Parent(s): 7f373de

config space

Browse files
Files changed (3) hide show
  1. .hf.yaml +0 -9
  2. README.md +8 -1102
  3. README_repo.md +1102 -0
.hf.yaml DELETED
@@ -1,9 +0,0 @@
1
- title: Chat UI Energy Score
2
- emoji: ⚡
3
- colorFrom: indigo
4
- colorTo: pink
5
- pinned: false
6
-
7
- image: "docker"
8
- build:
9
- dockerfile: Dockerfile
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -1,1102 +1,8 @@
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 from bullet list",
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 snake game",
289
- "prompt": "Code a basic snake game in python, give explanations for each step."
290
- }, {
291
- "title": "Assist in a task",
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
- 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.
305
-
306
- 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).
307
-
308
- ```prompt
309
- {{preprompt}}
310
- {{#each messages}}
311
- {{#ifUser}}{{@root.userMessageToken}}{{content}}{{@root.userMessageEndToken}}{{/ifUser}}
312
- {{#ifAssistant}}{{@root.assistantMessageToken}}{{content}}{{@root.assistantMessageEndToken}}{{/ifAssistant}}
313
- {{/each}}
314
- {{assistantMessageToken}}
315
- ```
316
-
317
- > [!INFO]
318
- > 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.
319
-
320
- #### Multi modal model
321
-
322
- 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).
323
-
324
- ```env
325
- {
326
- "name": "HuggingFaceM4/idefics-80b-instruct",
327
- "multimodal" : true,
328
- "description": "IDEFICS is the new multimodal model by Hugging Face.",
329
- "preprompt": "",
330
- "chatPromptTemplate" : "{{#each messages}}{{#ifUser}}User: {{content}}{{/ifUser}}<end_of_utterance>\nAssistant: {{#ifAssistant}}{{content}}\n{{/ifAssistant}}{{/each}}",
331
- "parameters": {
332
- "temperature": 0.1,
333
- "top_p": 0.95,
334
- "repetition_penalty": 1.2,
335
- "top_k": 12,
336
- "truncate": 1000,
337
- "max_new_tokens": 1024,
338
- "stop": ["<end_of_utterance>", "User:", "\nUser:"]
339
- }
340
- }
341
- ```
342
-
343
- #### Running your own models using a custom endpoint
344
-
345
- If you want to, instead of hitting models on the Hugging Face Inference API, you can run your own models locally.
346
-
347
- A good option is to hit a [text-generation-inference](https://github.com/huggingface/text-generation-inference) endpoint. This is what is done 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.
348
-
349
- 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`.
350
-
351
- ```env
352
- {
353
- // rest of the model config here
354
- "endpoints": [{
355
- "type" : "tgi",
356
- "url": "https://HOST:PORT",
357
- }]
358
- }
359
- ```
360
-
361
- If `endpoints` are left unspecified, ChatUI will look for the model on the hosted Hugging Face inference API using the model name.
362
-
363
- ##### OpenAI API compatible models
364
-
365
- 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).
366
-
367
- 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.
368
-
369
- 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.
370
-
371
- ```
372
- MODELS=`[
373
- {
374
- "name": "text-generation-webui",
375
- "id": "text-generation-webui",
376
- "parameters": {
377
- "temperature": 0.9,
378
- "top_p": 0.95,
379
- "max_new_tokens": 1024,
380
- "stop": []
381
- },
382
- "endpoints": [{
383
- "type" : "openai",
384
- "baseURL": "http://localhost:8000/v1",
385
- "extraBody": {
386
- "repetition_penalty": 1.2,
387
- "top_k": 50,
388
- "truncate": 1000
389
- }
390
- }]
391
- }
392
- ]`
393
-
394
- ```
395
-
396
- The `openai` type includes official OpenAI models. You can add, for example, GPT4/GPT3.5 as a "openai" model:
397
-
398
- ```
399
- OPENAI_API_KEY=#your openai api key here
400
- MODELS=`[{
401
- "name": "gpt-4",
402
- "displayName": "GPT 4",
403
- "endpoints" : [{
404
- "type": "openai"
405
- }]
406
- },
407
- {
408
- "name": "gpt-3.5-turbo",
409
- "displayName": "GPT 3.5 Turbo",
410
- "endpoints" : [{
411
- "type": "openai"
412
- }]
413
- }]`
414
- ```
415
-
416
- 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:
417
-
418
- ```
419
- MODELS=`[{
420
- "name": "claude-2.1",
421
- "displayName": "Claude 2.1",
422
- "description": "Anthropic has been founded by former OpenAI researchers...",
423
- "parameters": {
424
- "temperature": 0.5,
425
- "max_new_tokens": 4096,
426
- },
427
- "endpoints": [
428
- {
429
- "type": "openai",
430
- "baseURL": "https://gateway.example.com/v1",
431
- "defaultHeaders": {
432
- "x-portkey-config": '{"provider":"anthropic","api_key":"sk-ant-abc...xyz"}'
433
- }
434
- }
435
- ]
436
- }]`
437
- ```
438
-
439
- Example for GPT 4 deployed on Azure OpenAI:
440
-
441
- ```
442
- MODELS=`[{
443
- "id": "gpt-4-1106-preview",
444
- "name": "gpt-4-1106-preview",
445
- "displayName": "gpt-4-1106-preview",
446
- "parameters": {
447
- "temperature": 0.5,
448
- "max_new_tokens": 4096,
449
- },
450
- "endpoints": [
451
- {
452
- "type": "openai",
453
- "baseURL": "https://{resource-name}.openai.azure.com/openai/deployments/{deployment-id}",
454
- "defaultHeaders": {
455
- "api-key": "{api-key}"
456
- },
457
- "defaultQuery": {
458
- "api-version": "2023-05-15"
459
- }
460
- }
461
- ]
462
- }]`
463
- ```
464
-
465
- Or try Mistral from [Deepinfra](https://deepinfra.com/mistralai/Mistral-7B-Instruct-v0.1/api?example=openai-http):
466
-
467
- > Note, apiKey can either be set custom per endpoint, or globally using `OPENAI_API_KEY` variable.
468
-
469
- ```
470
- MODELS=`[{
471
- "name": "mistral-7b",
472
- "displayName": "Mistral 7B",
473
- "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.",
474
- "parameters": {
475
- "temperature": 0.5,
476
- "max_new_tokens": 4096,
477
- },
478
- "endpoints": [
479
- {
480
- "type": "openai",
481
- "baseURL": "https://api.deepinfra.com/v1/openai",
482
- "apiKey": "abc...xyz"
483
- }
484
- ]
485
- }]`
486
- ```
487
-
488
- _Non-streaming endpoints_
489
-
490
- For endpoints that don´t support streaming like o1 on Azure, you can pass `streamingSupported: false` in your endpoint config:
491
-
492
- ```
493
- MODELS=`[{
494
- "id": "o1-preview",
495
- "name": "o1-preview",
496
- "displayName": "o1-preview",
497
- "systemRoleSupported": false,
498
- "endpoints": [
499
- {
500
- "type": "openai",
501
- "baseURL": "https://my-deployment.openai.azure.com/openai/deployments/o1-preview",
502
- "defaultHeaders": {
503
- "api-key": "$SECRET"
504
- },
505
- "streamingSupported": false,
506
- }
507
- ]
508
- }]`
509
- ```
510
-
511
- ##### Llama.cpp API server
512
-
513
- 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.
514
-
515
- 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:
516
-
517
- ```bash
518
- # install llama.cpp
519
- brew install llama.cpp
520
- # start llama.cpp server
521
- llama-server --hf-repo microsoft/Phi-3-mini-4k-instruct-gguf --hf-file Phi-3-mini-4k-instruct-q4.gguf -c 4096
522
- ```
523
-
524
- ```env
525
- MODELS=`[
526
- {
527
- "name": "Local Zephyr",
528
- "chatPromptTemplate": "<|system|>\n{{preprompt}}</s>\n{{#each messages}}{{#ifUser}}<|user|>\n{{content}}</s>\n<|assistant|>\n{{/ifUser}}{{#ifAssistant}}{{content}}</s>\n{{/ifAssistant}}{{/each}}",
529
- "parameters": {
530
- "temperature": 0.1,
531
- "top_p": 0.95,
532
- "repetition_penalty": 1.2,
533
- "top_k": 50,
534
- "truncate": 1000,
535
- "max_new_tokens": 2048,
536
- "stop": ["</s>"]
537
- },
538
- "endpoints": [
539
- {
540
- "url": "http://127.0.0.1:8080",
541
- "type": "llamacpp"
542
- }
543
- ]
544
- }
545
- ]`
546
- ```
547
-
548
- Start chat-ui with `npm run dev` and you should be able to chat with Zephyr locally.
549
-
550
- #### Ollama
551
-
552
- We also support the Ollama inference server. Spin up a model with
553
-
554
- ```cli
555
- ollama run mistral
556
- ```
557
-
558
- Then specify the endpoints like so:
559
-
560
- ```env
561
- MODELS=`[
562
- {
563
- "name": "Ollama Mistral",
564
- "chatPromptTemplate": "<s>{{#each messages}}{{#ifUser}}[INST] {{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}} {{content}} [/INST]{{/ifUser}}{{#ifAssistant}}{{content}}</s> {{/ifAssistant}}{{/each}}",
565
- "parameters": {
566
- "temperature": 0.1,
567
- "top_p": 0.95,
568
- "repetition_penalty": 1.2,
569
- "top_k": 50,
570
- "truncate": 3072,
571
- "max_new_tokens": 1024,
572
- "stop": ["</s>"]
573
- },
574
- "endpoints": [
575
- {
576
- "type": "ollama",
577
- "url" : "http://127.0.0.1:11434",
578
- "ollamaName" : "mistral"
579
- }
580
- ]
581
- }
582
- ]`
583
- ```
584
-
585
- #### Anthropic
586
-
587
- 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.
588
-
589
- ```
590
- MODELS=`[
591
- {
592
- "name": "claude-3-haiku-20240307",
593
- "displayName": "Claude 3 Haiku",
594
- "description": "Fastest and most compact model for near-instant responsiveness",
595
- "multimodal": true,
596
- "parameters": {
597
- "max_new_tokens": 4096,
598
- },
599
- "endpoints": [
600
- {
601
- "type": "anthropic",
602
- // optionals
603
- "apiKey": "sk-ant-...",
604
- "baseURL": "https://api.anthropic.com",
605
- "defaultHeaders": {},
606
- "defaultQuery": {}
607
- }
608
- ]
609
- },
610
- {
611
- "name": "claude-3-sonnet-20240229",
612
- "displayName": "Claude 3 Sonnet",
613
- "description": "Ideal balance of intelligence and speed",
614
- "multimodal": true,
615
- "parameters": {
616
- "max_new_tokens": 4096,
617
- },
618
- "endpoints": [
619
- {
620
- "type": "anthropic",
621
- // optionals
622
- "apiKey": "sk-ant-...",
623
- "baseURL": "https://api.anthropic.com",
624
- "defaultHeaders": {},
625
- "defaultQuery": {}
626
- }
627
- ]
628
- },
629
- {
630
- "name": "claude-3-opus-20240229",
631
- "displayName": "Claude 3 Opus",
632
- "description": "Most powerful model for highly complex tasks",
633
- "multimodal": true,
634
- "parameters": {
635
- "max_new_tokens": 4096
636
- },
637
- "endpoints": [
638
- {
639
- "type": "anthropic",
640
- // optionals
641
- "apiKey": "sk-ant-...",
642
- "baseURL": "https://api.anthropic.com",
643
- "defaultHeaders": {},
644
- "defaultQuery": {}
645
- }
646
- ]
647
- }
648
- ]`
649
- ```
650
-
651
- 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:
652
-
653
- ```
654
- MODELS=`[
655
- {
656
- "name": "claude-3-sonnet@20240229",
657
- "displayName": "Claude 3 Sonnet",
658
- "description": "Ideal balance of intelligence and speed",
659
- "multimodal": true,
660
- "parameters": {
661
- "max_new_tokens": 4096,
662
- },
663
- "endpoints": [
664
- {
665
- "type": "anthropic-vertex",
666
- "region": "us-central1",
667
- "projectId": "gcp-project-id",
668
- // optionals
669
- "defaultHeaders": {},
670
- "defaultQuery": {}
671
- }
672
- ]
673
- },
674
- {
675
- "name": "claude-3-haiku@20240307",
676
- "displayName": "Claude 3 Haiku",
677
- "description": "Fastest, most compact model for near-instant responsiveness",
678
- "multimodal": true,
679
- "parameters": {
680
- "max_new_tokens": 4096
681
- },
682
- "endpoints": [
683
- {
684
- "type": "anthropic-vertex",
685
- "region": "us-central1",
686
- "projectId": "gcp-project-id",
687
- // optionals
688
- "defaultHeaders": {},
689
- "defaultQuery": {}
690
- }
691
- ]
692
- }
693
- ]`
694
- ```
695
-
696
- #### Amazon
697
-
698
- You can also specify your Amazon SageMaker instance as an endpoint for chat-ui. The config goes like this:
699
-
700
- ```env
701
- "endpoints": [
702
- {
703
- "type" : "aws",
704
- "service" : "sagemaker"
705
- "url": "",
706
- "accessKey": "",
707
- "secretKey" : "",
708
- "sessionToken": "",
709
- "region": "",
710
-
711
- "weight": 1
712
- }
713
- ]
714
- ```
715
-
716
- You can also set `"service" : "lambda"` to use a lambda instance.
717
-
718
- You can get the `accessKey` and `secretKey` from your AWS user, under programmatic access.
719
-
720
- #### Cloudflare Workers AI
721
-
722
- You can also use Cloudflare Workers AI to run your own models with serverless inference.
723
-
724
- 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.
725
-
726
- 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.
727
-
728
- You can find the list of models available on Cloudflare [here](https://developers.cloudflare.com/workers-ai/models/#text-generation).
729
-
730
- ```env
731
- {
732
- "name" : "nousresearch/hermes-2-pro-mistral-7b",
733
- "tokenizer": "nousresearch/hermes-2-pro-mistral-7b",
734
- "parameters": {
735
- "stop": ["<|im_end|>"]
736
- },
737
- "endpoints" : [
738
- {
739
- "type" : "cloudflare"
740
- <!-- optionally specify these
741
- "accountId": "your-account-id",
742
- "authToken": "your-api-token"
743
- -->
744
- }
745
- ]
746
- }
747
- ```
748
-
749
- #### Cohere
750
-
751
- 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.
752
-
753
- 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.
754
-
755
- ```env
756
- {
757
- "name" : "CohereForAI/c4ai-command-r-v01",
758
- "id": "command-r",
759
- "description": "C4AI Command-R is a research release of a 35 billion parameter highly performant generative model",
760
- "endpoints": [
761
- {
762
- "type": "cohere",
763
- <!-- optionally specify these, or use COHERE_API_TOKEN
764
- "apiKey": "your-api-token"
765
- -->
766
- }
767
- ]
768
- }
769
- ```
770
-
771
- ##### Google Vertex models
772
-
773
- 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)).
774
-
775
- To enable:
776
-
777
- 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.
778
- 1. [Enable billing for your project](https://cloud.google.com/billing/docs/how-to/modify-project).
779
- 1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).
780
- 1. [Set up authentication with a service account](https://cloud.google.com/docs/authentication/getting-started)
781
- so you can access the API from your local workstation.
782
-
783
- The service account credentials file can be imported as an environmental variable:
784
-
785
- ```env
786
- GOOGLE_APPLICATION_CREDENTIALS = clientid.json
787
- ```
788
-
789
- Make sure your docker container has access to the file and the variable is correctly set.
790
- Afterwards Google Vertex endpoints can be configured as following:
791
-
792
- ```
793
- MODELS=`[
794
- //...
795
- {
796
- "name": "gemini-1.5-pro",
797
- "displayName": "Vertex Gemini Pro 1.5",
798
- "multimodal": true,
799
- "endpoints" : [{
800
- "type": "vertex",
801
- "project": "abc-xyz",
802
- "location": "europe-west3",
803
- "extraBody": {
804
- "model_version": "gemini-1.5-pro-preview-0409",
805
- },
806
-
807
- // Optional
808
- "safetyThreshold": "BLOCK_MEDIUM_AND_ABOVE",
809
- "apiEndpoint": "", // alternative api endpoint url,
810
- "tools": [{
811
- "googleSearchRetrieval": {
812
- "disableAttribution": true
813
- }
814
- }],
815
- "multimodal": {
816
- "image": {
817
- "supportedMimeTypes": ["image/png", "image/jpeg", "image/webp"],
818
- "preferredMimeType": "image/png",
819
- "maxSizeInMB": 5,
820
- "maxWidth": 2000,
821
- "maxHeight": 1000,
822
- }
823
- }
824
- }]
825
- },
826
- ]`
827
-
828
- ```
829
-
830
- ##### LangServe
831
-
832
- LangChain applications that are deployed using LangServe can be called with the following config:
833
-
834
- ```
835
- MODELS=`[
836
- //...
837
- {
838
- "name": "summarization-chain", //model-name
839
- "endpoints" : [{
840
- "type": "langserve",
841
- "url" : "http://127.0.0.1:8100",
842
- }]
843
- },
844
- ]`
845
-
846
- ```
847
-
848
- ### Custom endpoint authorization
849
-
850
- #### Basic and Bearer
851
-
852
- Custom endpoints may require authorization, depending on how you configure them. Authentication will usually be set either with `Basic` or `Bearer`.
853
-
854
- For `Basic` we will need to generate a base64 encoding of the username and password.
855
-
856
- `echo -n "USER:PASS" | base64`
857
-
858
- > VVNFUjpQQVNT
859
-
860
- For `Bearer` you can use a token, which can be grabbed from [here](https://huggingface.co/settings/tokens).
861
-
862
- You can then add the generated information and the `authorization` parameter to your `.env.local`.
863
-
864
- ```env
865
- "endpoints": [
866
- {
867
- "url": "https://HOST:PORT",
868
- "authorization": "Basic VVNFUjpQQVNT",
869
- }
870
- ]
871
- ```
872
-
873
- Please note that if `HF_TOKEN` is also set or not empty, it will take precedence.
874
-
875
- #### Models hosted on multiple custom endpoints
876
-
877
- 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.
878
-
879
- ```env
880
- "endpoints": [
881
- {
882
- "url": "https://HOST:PORT",
883
- "weight": 1
884
- },
885
- {
886
- "url": "https://HOST:PORT",
887
- "weight": 2
888
- }
889
- ...
890
- ]
891
- ```
892
-
893
- #### Client Certificate Authentication (mTLS)
894
-
895
- 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`.
896
-
897
- 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.
898
-
899
- 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.
900
-
901
- #### Specific Embedding Model
902
-
903
- A model can use any of the embedding models defined in `.env.local`, (currently used when web searching),
904
- by default it will use the first embedding model, but it can be changed with the field `embeddingModel`:
905
-
906
- ```env
907
- TEXT_EMBEDDING_MODELS = `[
908
- {
909
- "name": "Xenova/gte-small",
910
- "chunkCharLength": 512,
911
- "endpoints": [
912
- {"type": "transformersjs"}
913
- ]
914
- },
915
- {
916
- "name": "intfloat/e5-base-v2",
917
- "chunkCharLength": 768,
918
- "endpoints": [
919
- {"type": "tei", "url": "http://127.0.0.1:8080/", "authorization": "Basic VVNFUjpQQVNT"},
920
- {"type": "tei", "url": "http://127.0.0.1:8081/"}
921
- ]
922
- }
923
- ]`
924
-
925
- MODELS=`[
926
- {
927
- "name": "Ollama Mistral",
928
- "chatPromptTemplate": "...",
929
- "embeddingModel": "intfloat/e5-base-v2"
930
- "parameters": {
931
- ...
932
- },
933
- "endpoints": [
934
- ...
935
- ]
936
- }
937
- ]`
938
-
939
- ```
940
-
941
- ### Reasoning Models
942
-
943
- 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:
944
-
945
- #### Token-Based Delimitations
946
-
947
- 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.
948
-
949
- Example configuration for DeepSeek R1 (token-based):
950
-
951
- ```json
952
- {
953
- "name": "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
954
- // ...
955
- "reasoning": {
956
- "type": "tokens",
957
- "beginToken": "<think>",
958
- "endToken": "</think>"
959
- }
960
- }
961
- ```
962
-
963
- #### Summarizing the Chain of Thought
964
-
965
- 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.
966
-
967
- Example configuration for QwQ (summarize-based):
968
-
969
- ```json
970
- {
971
- "name": "Qwen/QwQ-32B-Preview",
972
- // ...
973
- "reasoning": {
974
- "type": "summarize"
975
- }
976
- }
977
- ```
978
-
979
- #### Regex-Based Delimitations
980
-
981
- 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:
982
-
983
- ```json
984
- {
985
- "name": "model/yourmodel",
986
- // ...
987
- "reasoning": {
988
- "type": "regex",
989
- "regex": "\\\\boxed\\{(.+?)\\}"
990
- }
991
- }
992
- ```
993
-
994
- ## Common issues
995
-
996
- ### 403:You don't have access to this conversation
997
-
998
- 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`.
999
-
1000
- Make sure to set your `PUBLIC_ORIGIN` in your `.env.local` to the correct URL as well.
1001
-
1002
- ## Deploying to a HF Space
1003
-
1004
- 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.
1005
-
1006
- ## Building
1007
-
1008
- To create a production version of your app:
1009
-
1010
- ```bash
1011
- npm run build
1012
- ```
1013
-
1014
- You can preview the production build with `npm run preview`.
1015
-
1016
- > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
1017
-
1018
- ## Config changes for HuggingChat
1019
-
1020
- 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.
1021
-
1022
- > [!TIP]
1023
- > If you want to make changes to the model config used in production for HuggingChat, you should do so against `chart/env/prod.yaml`.
1024
-
1025
- ### Running a copy of HuggingChat locally
1026
-
1027
- If you want to run an exact copy of HuggingChat locally, you will need to do the following first:
1028
-
1029
- 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.
1030
- 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.
1031
- 3. Create a free account with [serper.dev](https://serper.dev/) (you will get 2500 free search queries)
1032
- 4. Run an instance of mongoDB, however you want. (Local or remote)
1033
-
1034
- You can then create a new `.env.SECRET_CONFIG` file with the following content
1035
-
1036
- ```env
1037
- MONGODB_URL=<link to your mongo DB from step 4>
1038
- HF_TOKEN=<your HF token from step 2>
1039
- OPENID_CONFIG=`{
1040
- PROVIDER_URL: "https://huggingface.co",
1041
- CLIENT_ID: "<your client ID from step 1>",
1042
- CLIENT_SECRET: "<your client secret from step 1>",
1043
- }`
1044
- SERPER_API_KEY=<your serper API key from step 3>
1045
- MESSAGES_BEFORE_LOGIN=<can be any numerical value, or set to 0 to require login>
1046
- ```
1047
-
1048
- 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.
1049
-
1050
- ### Populate database
1051
-
1052
- > [!WARNING]
1053
- > 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.
1054
-
1055
- You can populate the database using faker data using the `populate` script:
1056
-
1057
- ```bash
1058
- npm run populate <flags here>
1059
- ```
1060
-
1061
- At least one flag must be specified, the following flags are available:
1062
-
1063
- - `reset` - resets the database
1064
- - `all` - populates all tables
1065
- - `users` - populates the users table
1066
- - `settings` - populates the settings table for existing users
1067
- - `assistants` - populates the assistants table for existing users
1068
- - `conversations` - populates the conversations table for existing users
1069
-
1070
- For example, you could use it like so:
1071
-
1072
- ```bash
1073
- npm run populate reset
1074
- ```
1075
-
1076
- to clear out the database. Then login in the app to create your user and run the following command:
1077
-
1078
- ```bash
1079
- npm run populate users settings assistants conversations
1080
- ```
1081
-
1082
- to populate the database with fake data, including fake conversations and assistants for your user.
1083
-
1084
- ## Building the docker images locally
1085
-
1086
- You can build the docker images locally using the following commands:
1087
-
1088
- ```bash
1089
- docker build -t chat-ui-db:latest --build-arg INCLUDE_DB=true .
1090
- docker build -t chat-ui:latest --build-arg INCLUDE_DB=false .
1091
- docker build -t huggingchat:latest --build-arg INCLUDE_DB=false --build-arg APP_BASE=/chat --build-arg PUBLIC_APP_COLOR=yellow .
1092
- ```
1093
-
1094
- If you want to run the images with your local .env.local you have two options
1095
-
1096
- ```bash
1097
- DOTENV_LOCAL=$(<.env.local) docker run --rm --network=host -e DOTENV_LOCAL -p 3000:3000 chat-ui
1098
- ```
1099
-
1100
- ```bash
1101
- docker run --rm --network=host --mount type=bind,source="$(pwd)/.env.local",target=/app/.env.local -p 3000:3000 chat-ui
1102
- ```
 
1
+ ---
2
+ title: Chat UI Energy Score
3
+ emoji:
4
+ colorFrom: indigo
5
+ colorTo: pink
6
+ sdk: docker
7
+ app_port: 5173
8
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README_repo.md ADDED
@@ -0,0 +1,1102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 from bullet list",
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 snake game",
289
+ "prompt": "Code a basic snake game in python, give explanations for each step."
290
+ }, {
291
+ "title": "Assist in a task",
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
+ 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.
305
+
306
+ 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).
307
+
308
+ ```prompt
309
+ {{preprompt}}
310
+ {{#each messages}}
311
+ {{#ifUser}}{{@root.userMessageToken}}{{content}}{{@root.userMessageEndToken}}{{/ifUser}}
312
+ {{#ifAssistant}}{{@root.assistantMessageToken}}{{content}}{{@root.assistantMessageEndToken}}{{/ifAssistant}}
313
+ {{/each}}
314
+ {{assistantMessageToken}}
315
+ ```
316
+
317
+ > [!INFO]
318
+ > 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.
319
+
320
+ #### Multi modal model
321
+
322
+ 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).
323
+
324
+ ```env
325
+ {
326
+ "name": "HuggingFaceM4/idefics-80b-instruct",
327
+ "multimodal" : true,
328
+ "description": "IDEFICS is the new multimodal model by Hugging Face.",
329
+ "preprompt": "",
330
+ "chatPromptTemplate" : "{{#each messages}}{{#ifUser}}User: {{content}}{{/ifUser}}<end_of_utterance>\nAssistant: {{#ifAssistant}}{{content}}\n{{/ifAssistant}}{{/each}}",
331
+ "parameters": {
332
+ "temperature": 0.1,
333
+ "top_p": 0.95,
334
+ "repetition_penalty": 1.2,
335
+ "top_k": 12,
336
+ "truncate": 1000,
337
+ "max_new_tokens": 1024,
338
+ "stop": ["<end_of_utterance>", "User:", "\nUser:"]
339
+ }
340
+ }
341
+ ```
342
+
343
+ #### Running your own models using a custom endpoint
344
+
345
+ If you want to, instead of hitting models on the Hugging Face Inference API, you can run your own models locally.
346
+
347
+ A good option is to hit a [text-generation-inference](https://github.com/huggingface/text-generation-inference) endpoint. This is what is done 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.
348
+
349
+ 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`.
350
+
351
+ ```env
352
+ {
353
+ // rest of the model config here
354
+ "endpoints": [{
355
+ "type" : "tgi",
356
+ "url": "https://HOST:PORT",
357
+ }]
358
+ }
359
+ ```
360
+
361
+ If `endpoints` are left unspecified, ChatUI will look for the model on the hosted Hugging Face inference API using the model name.
362
+
363
+ ##### OpenAI API compatible models
364
+
365
+ 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).
366
+
367
+ 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.
368
+
369
+ 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.
370
+
371
+ ```
372
+ MODELS=`[
373
+ {
374
+ "name": "text-generation-webui",
375
+ "id": "text-generation-webui",
376
+ "parameters": {
377
+ "temperature": 0.9,
378
+ "top_p": 0.95,
379
+ "max_new_tokens": 1024,
380
+ "stop": []
381
+ },
382
+ "endpoints": [{
383
+ "type" : "openai",
384
+ "baseURL": "http://localhost:8000/v1",
385
+ "extraBody": {
386
+ "repetition_penalty": 1.2,
387
+ "top_k": 50,
388
+ "truncate": 1000
389
+ }
390
+ }]
391
+ }
392
+ ]`
393
+
394
+ ```
395
+
396
+ The `openai` type includes official OpenAI models. You can add, for example, GPT4/GPT3.5 as a "openai" model:
397
+
398
+ ```
399
+ OPENAI_API_KEY=#your openai api key here
400
+ MODELS=`[{
401
+ "name": "gpt-4",
402
+ "displayName": "GPT 4",
403
+ "endpoints" : [{
404
+ "type": "openai"
405
+ }]
406
+ },
407
+ {
408
+ "name": "gpt-3.5-turbo",
409
+ "displayName": "GPT 3.5 Turbo",
410
+ "endpoints" : [{
411
+ "type": "openai"
412
+ }]
413
+ }]`
414
+ ```
415
+
416
+ 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:
417
+
418
+ ```
419
+ MODELS=`[{
420
+ "name": "claude-2.1",
421
+ "displayName": "Claude 2.1",
422
+ "description": "Anthropic has been founded by former OpenAI researchers...",
423
+ "parameters": {
424
+ "temperature": 0.5,
425
+ "max_new_tokens": 4096,
426
+ },
427
+ "endpoints": [
428
+ {
429
+ "type": "openai",
430
+ "baseURL": "https://gateway.example.com/v1",
431
+ "defaultHeaders": {
432
+ "x-portkey-config": '{"provider":"anthropic","api_key":"sk-ant-abc...xyz"}'
433
+ }
434
+ }
435
+ ]
436
+ }]`
437
+ ```
438
+
439
+ Example for GPT 4 deployed on Azure OpenAI:
440
+
441
+ ```
442
+ MODELS=`[{
443
+ "id": "gpt-4-1106-preview",
444
+ "name": "gpt-4-1106-preview",
445
+ "displayName": "gpt-4-1106-preview",
446
+ "parameters": {
447
+ "temperature": 0.5,
448
+ "max_new_tokens": 4096,
449
+ },
450
+ "endpoints": [
451
+ {
452
+ "type": "openai",
453
+ "baseURL": "https://{resource-name}.openai.azure.com/openai/deployments/{deployment-id}",
454
+ "defaultHeaders": {
455
+ "api-key": "{api-key}"
456
+ },
457
+ "defaultQuery": {
458
+ "api-version": "2023-05-15"
459
+ }
460
+ }
461
+ ]
462
+ }]`
463
+ ```
464
+
465
+ Or try Mistral from [Deepinfra](https://deepinfra.com/mistralai/Mistral-7B-Instruct-v0.1/api?example=openai-http):
466
+
467
+ > Note, apiKey can either be set custom per endpoint, or globally using `OPENAI_API_KEY` variable.
468
+
469
+ ```
470
+ MODELS=`[{
471
+ "name": "mistral-7b",
472
+ "displayName": "Mistral 7B",
473
+ "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.",
474
+ "parameters": {
475
+ "temperature": 0.5,
476
+ "max_new_tokens": 4096,
477
+ },
478
+ "endpoints": [
479
+ {
480
+ "type": "openai",
481
+ "baseURL": "https://api.deepinfra.com/v1/openai",
482
+ "apiKey": "abc...xyz"
483
+ }
484
+ ]
485
+ }]`
486
+ ```
487
+
488
+ _Non-streaming endpoints_
489
+
490
+ For endpoints that don´t support streaming like o1 on Azure, you can pass `streamingSupported: false` in your endpoint config:
491
+
492
+ ```
493
+ MODELS=`[{
494
+ "id": "o1-preview",
495
+ "name": "o1-preview",
496
+ "displayName": "o1-preview",
497
+ "systemRoleSupported": false,
498
+ "endpoints": [
499
+ {
500
+ "type": "openai",
501
+ "baseURL": "https://my-deployment.openai.azure.com/openai/deployments/o1-preview",
502
+ "defaultHeaders": {
503
+ "api-key": "$SECRET"
504
+ },
505
+ "streamingSupported": false,
506
+ }
507
+ ]
508
+ }]`
509
+ ```
510
+
511
+ ##### Llama.cpp API server
512
+
513
+ 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.
514
+
515
+ 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:
516
+
517
+ ```bash
518
+ # install llama.cpp
519
+ brew install llama.cpp
520
+ # start llama.cpp server
521
+ llama-server --hf-repo microsoft/Phi-3-mini-4k-instruct-gguf --hf-file Phi-3-mini-4k-instruct-q4.gguf -c 4096
522
+ ```
523
+
524
+ ```env
525
+ MODELS=`[
526
+ {
527
+ "name": "Local Zephyr",
528
+ "chatPromptTemplate": "<|system|>\n{{preprompt}}</s>\n{{#each messages}}{{#ifUser}}<|user|>\n{{content}}</s>\n<|assistant|>\n{{/ifUser}}{{#ifAssistant}}{{content}}</s>\n{{/ifAssistant}}{{/each}}",
529
+ "parameters": {
530
+ "temperature": 0.1,
531
+ "top_p": 0.95,
532
+ "repetition_penalty": 1.2,
533
+ "top_k": 50,
534
+ "truncate": 1000,
535
+ "max_new_tokens": 2048,
536
+ "stop": ["</s>"]
537
+ },
538
+ "endpoints": [
539
+ {
540
+ "url": "http://127.0.0.1:8080",
541
+ "type": "llamacpp"
542
+ }
543
+ ]
544
+ }
545
+ ]`
546
+ ```
547
+
548
+ Start chat-ui with `npm run dev` and you should be able to chat with Zephyr locally.
549
+
550
+ #### Ollama
551
+
552
+ We also support the Ollama inference server. Spin up a model with
553
+
554
+ ```cli
555
+ ollama run mistral
556
+ ```
557
+
558
+ Then specify the endpoints like so:
559
+
560
+ ```env
561
+ MODELS=`[
562
+ {
563
+ "name": "Ollama Mistral",
564
+ "chatPromptTemplate": "<s>{{#each messages}}{{#ifUser}}[INST] {{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}} {{content}} [/INST]{{/ifUser}}{{#ifAssistant}}{{content}}</s> {{/ifAssistant}}{{/each}}",
565
+ "parameters": {
566
+ "temperature": 0.1,
567
+ "top_p": 0.95,
568
+ "repetition_penalty": 1.2,
569
+ "top_k": 50,
570
+ "truncate": 3072,
571
+ "max_new_tokens": 1024,
572
+ "stop": ["</s>"]
573
+ },
574
+ "endpoints": [
575
+ {
576
+ "type": "ollama",
577
+ "url" : "http://127.0.0.1:11434",
578
+ "ollamaName" : "mistral"
579
+ }
580
+ ]
581
+ }
582
+ ]`
583
+ ```
584
+
585
+ #### Anthropic
586
+
587
+ 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.
588
+
589
+ ```
590
+ MODELS=`[
591
+ {
592
+ "name": "claude-3-haiku-20240307",
593
+ "displayName": "Claude 3 Haiku",
594
+ "description": "Fastest and most compact model for near-instant responsiveness",
595
+ "multimodal": true,
596
+ "parameters": {
597
+ "max_new_tokens": 4096,
598
+ },
599
+ "endpoints": [
600
+ {
601
+ "type": "anthropic",
602
+ // optionals
603
+ "apiKey": "sk-ant-...",
604
+ "baseURL": "https://api.anthropic.com",
605
+ "defaultHeaders": {},
606
+ "defaultQuery": {}
607
+ }
608
+ ]
609
+ },
610
+ {
611
+ "name": "claude-3-sonnet-20240229",
612
+ "displayName": "Claude 3 Sonnet",
613
+ "description": "Ideal balance of intelligence and speed",
614
+ "multimodal": true,
615
+ "parameters": {
616
+ "max_new_tokens": 4096,
617
+ },
618
+ "endpoints": [
619
+ {
620
+ "type": "anthropic",
621
+ // optionals
622
+ "apiKey": "sk-ant-...",
623
+ "baseURL": "https://api.anthropic.com",
624
+ "defaultHeaders": {},
625
+ "defaultQuery": {}
626
+ }
627
+ ]
628
+ },
629
+ {
630
+ "name": "claude-3-opus-20240229",
631
+ "displayName": "Claude 3 Opus",
632
+ "description": "Most powerful model for highly complex tasks",
633
+ "multimodal": true,
634
+ "parameters": {
635
+ "max_new_tokens": 4096
636
+ },
637
+ "endpoints": [
638
+ {
639
+ "type": "anthropic",
640
+ // optionals
641
+ "apiKey": "sk-ant-...",
642
+ "baseURL": "https://api.anthropic.com",
643
+ "defaultHeaders": {},
644
+ "defaultQuery": {}
645
+ }
646
+ ]
647
+ }
648
+ ]`
649
+ ```
650
+
651
+ 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:
652
+
653
+ ```
654
+ MODELS=`[
655
+ {
656
+ "name": "claude-3-sonnet@20240229",
657
+ "displayName": "Claude 3 Sonnet",
658
+ "description": "Ideal balance of intelligence and speed",
659
+ "multimodal": true,
660
+ "parameters": {
661
+ "max_new_tokens": 4096,
662
+ },
663
+ "endpoints": [
664
+ {
665
+ "type": "anthropic-vertex",
666
+ "region": "us-central1",
667
+ "projectId": "gcp-project-id",
668
+ // optionals
669
+ "defaultHeaders": {},
670
+ "defaultQuery": {}
671
+ }
672
+ ]
673
+ },
674
+ {
675
+ "name": "claude-3-haiku@20240307",
676
+ "displayName": "Claude 3 Haiku",
677
+ "description": "Fastest, most compact model for near-instant responsiveness",
678
+ "multimodal": true,
679
+ "parameters": {
680
+ "max_new_tokens": 4096
681
+ },
682
+ "endpoints": [
683
+ {
684
+ "type": "anthropic-vertex",
685
+ "region": "us-central1",
686
+ "projectId": "gcp-project-id",
687
+ // optionals
688
+ "defaultHeaders": {},
689
+ "defaultQuery": {}
690
+ }
691
+ ]
692
+ }
693
+ ]`
694
+ ```
695
+
696
+ #### Amazon
697
+
698
+ You can also specify your Amazon SageMaker instance as an endpoint for chat-ui. The config goes like this:
699
+
700
+ ```env
701
+ "endpoints": [
702
+ {
703
+ "type" : "aws",
704
+ "service" : "sagemaker"
705
+ "url": "",
706
+ "accessKey": "",
707
+ "secretKey" : "",
708
+ "sessionToken": "",
709
+ "region": "",
710
+
711
+ "weight": 1
712
+ }
713
+ ]
714
+ ```
715
+
716
+ You can also set `"service" : "lambda"` to use a lambda instance.
717
+
718
+ You can get the `accessKey` and `secretKey` from your AWS user, under programmatic access.
719
+
720
+ #### Cloudflare Workers AI
721
+
722
+ You can also use Cloudflare Workers AI to run your own models with serverless inference.
723
+
724
+ 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.
725
+
726
+ 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.
727
+
728
+ You can find the list of models available on Cloudflare [here](https://developers.cloudflare.com/workers-ai/models/#text-generation).
729
+
730
+ ```env
731
+ {
732
+ "name" : "nousresearch/hermes-2-pro-mistral-7b",
733
+ "tokenizer": "nousresearch/hermes-2-pro-mistral-7b",
734
+ "parameters": {
735
+ "stop": ["<|im_end|>"]
736
+ },
737
+ "endpoints" : [
738
+ {
739
+ "type" : "cloudflare"
740
+ <!-- optionally specify these
741
+ "accountId": "your-account-id",
742
+ "authToken": "your-api-token"
743
+ -->
744
+ }
745
+ ]
746
+ }
747
+ ```
748
+
749
+ #### Cohere
750
+
751
+ 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.
752
+
753
+ 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.
754
+
755
+ ```env
756
+ {
757
+ "name" : "CohereForAI/c4ai-command-r-v01",
758
+ "id": "command-r",
759
+ "description": "C4AI Command-R is a research release of a 35 billion parameter highly performant generative model",
760
+ "endpoints": [
761
+ {
762
+ "type": "cohere",
763
+ <!-- optionally specify these, or use COHERE_API_TOKEN
764
+ "apiKey": "your-api-token"
765
+ -->
766
+ }
767
+ ]
768
+ }
769
+ ```
770
+
771
+ ##### Google Vertex models
772
+
773
+ 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)).
774
+
775
+ To enable:
776
+
777
+ 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.
778
+ 1. [Enable billing for your project](https://cloud.google.com/billing/docs/how-to/modify-project).
779
+ 1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).
780
+ 1. [Set up authentication with a service account](https://cloud.google.com/docs/authentication/getting-started)
781
+ so you can access the API from your local workstation.
782
+
783
+ The service account credentials file can be imported as an environmental variable:
784
+
785
+ ```env
786
+ GOOGLE_APPLICATION_CREDENTIALS = clientid.json
787
+ ```
788
+
789
+ Make sure your docker container has access to the file and the variable is correctly set.
790
+ Afterwards Google Vertex endpoints can be configured as following:
791
+
792
+ ```
793
+ MODELS=`[
794
+ //...
795
+ {
796
+ "name": "gemini-1.5-pro",
797
+ "displayName": "Vertex Gemini Pro 1.5",
798
+ "multimodal": true,
799
+ "endpoints" : [{
800
+ "type": "vertex",
801
+ "project": "abc-xyz",
802
+ "location": "europe-west3",
803
+ "extraBody": {
804
+ "model_version": "gemini-1.5-pro-preview-0409",
805
+ },
806
+
807
+ // Optional
808
+ "safetyThreshold": "BLOCK_MEDIUM_AND_ABOVE",
809
+ "apiEndpoint": "", // alternative api endpoint url,
810
+ "tools": [{
811
+ "googleSearchRetrieval": {
812
+ "disableAttribution": true
813
+ }
814
+ }],
815
+ "multimodal": {
816
+ "image": {
817
+ "supportedMimeTypes": ["image/png", "image/jpeg", "image/webp"],
818
+ "preferredMimeType": "image/png",
819
+ "maxSizeInMB": 5,
820
+ "maxWidth": 2000,
821
+ "maxHeight": 1000,
822
+ }
823
+ }
824
+ }]
825
+ },
826
+ ]`
827
+
828
+ ```
829
+
830
+ ##### LangServe
831
+
832
+ LangChain applications that are deployed using LangServe can be called with the following config:
833
+
834
+ ```
835
+ MODELS=`[
836
+ //...
837
+ {
838
+ "name": "summarization-chain", //model-name
839
+ "endpoints" : [{
840
+ "type": "langserve",
841
+ "url" : "http://127.0.0.1:8100",
842
+ }]
843
+ },
844
+ ]`
845
+
846
+ ```
847
+
848
+ ### Custom endpoint authorization
849
+
850
+ #### Basic and Bearer
851
+
852
+ Custom endpoints may require authorization, depending on how you configure them. Authentication will usually be set either with `Basic` or `Bearer`.
853
+
854
+ For `Basic` we will need to generate a base64 encoding of the username and password.
855
+
856
+ `echo -n "USER:PASS" | base64`
857
+
858
+ > VVNFUjpQQVNT
859
+
860
+ For `Bearer` you can use a token, which can be grabbed from [here](https://huggingface.co/settings/tokens).
861
+
862
+ You can then add the generated information and the `authorization` parameter to your `.env.local`.
863
+
864
+ ```env
865
+ "endpoints": [
866
+ {
867
+ "url": "https://HOST:PORT",
868
+ "authorization": "Basic VVNFUjpQQVNT",
869
+ }
870
+ ]
871
+ ```
872
+
873
+ Please note that if `HF_TOKEN` is also set or not empty, it will take precedence.
874
+
875
+ #### Models hosted on multiple custom endpoints
876
+
877
+ 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.
878
+
879
+ ```env
880
+ "endpoints": [
881
+ {
882
+ "url": "https://HOST:PORT",
883
+ "weight": 1
884
+ },
885
+ {
886
+ "url": "https://HOST:PORT",
887
+ "weight": 2
888
+ }
889
+ ...
890
+ ]
891
+ ```
892
+
893
+ #### Client Certificate Authentication (mTLS)
894
+
895
+ 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`.
896
+
897
+ 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.
898
+
899
+ 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.
900
+
901
+ #### Specific Embedding Model
902
+
903
+ A model can use any of the embedding models defined in `.env.local`, (currently used when web searching),
904
+ by default it will use the first embedding model, but it can be changed with the field `embeddingModel`:
905
+
906
+ ```env
907
+ TEXT_EMBEDDING_MODELS = `[
908
+ {
909
+ "name": "Xenova/gte-small",
910
+ "chunkCharLength": 512,
911
+ "endpoints": [
912
+ {"type": "transformersjs"}
913
+ ]
914
+ },
915
+ {
916
+ "name": "intfloat/e5-base-v2",
917
+ "chunkCharLength": 768,
918
+ "endpoints": [
919
+ {"type": "tei", "url": "http://127.0.0.1:8080/", "authorization": "Basic VVNFUjpQQVNT"},
920
+ {"type": "tei", "url": "http://127.0.0.1:8081/"}
921
+ ]
922
+ }
923
+ ]`
924
+
925
+ MODELS=`[
926
+ {
927
+ "name": "Ollama Mistral",
928
+ "chatPromptTemplate": "...",
929
+ "embeddingModel": "intfloat/e5-base-v2"
930
+ "parameters": {
931
+ ...
932
+ },
933
+ "endpoints": [
934
+ ...
935
+ ]
936
+ }
937
+ ]`
938
+
939
+ ```
940
+
941
+ ### Reasoning Models
942
+
943
+ 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:
944
+
945
+ #### Token-Based Delimitations
946
+
947
+ 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.
948
+
949
+ Example configuration for DeepSeek R1 (token-based):
950
+
951
+ ```json
952
+ {
953
+ "name": "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
954
+ // ...
955
+ "reasoning": {
956
+ "type": "tokens",
957
+ "beginToken": "<think>",
958
+ "endToken": "</think>"
959
+ }
960
+ }
961
+ ```
962
+
963
+ #### Summarizing the Chain of Thought
964
+
965
+ 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.
966
+
967
+ Example configuration for QwQ (summarize-based):
968
+
969
+ ```json
970
+ {
971
+ "name": "Qwen/QwQ-32B-Preview",
972
+ // ...
973
+ "reasoning": {
974
+ "type": "summarize"
975
+ }
976
+ }
977
+ ```
978
+
979
+ #### Regex-Based Delimitations
980
+
981
+ 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:
982
+
983
+ ```json
984
+ {
985
+ "name": "model/yourmodel",
986
+ // ...
987
+ "reasoning": {
988
+ "type": "regex",
989
+ "regex": "\\\\boxed\\{(.+?)\\}"
990
+ }
991
+ }
992
+ ```
993
+
994
+ ## Common issues
995
+
996
+ ### 403:You don't have access to this conversation
997
+
998
+ 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`.
999
+
1000
+ Make sure to set your `PUBLIC_ORIGIN` in your `.env.local` to the correct URL as well.
1001
+
1002
+ ## Deploying to a HF Space
1003
+
1004
+ 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.
1005
+
1006
+ ## Building
1007
+
1008
+ To create a production version of your app:
1009
+
1010
+ ```bash
1011
+ npm run build
1012
+ ```
1013
+
1014
+ You can preview the production build with `npm run preview`.
1015
+
1016
+ > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
1017
+
1018
+ ## Config changes for HuggingChat
1019
+
1020
+ 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.
1021
+
1022
+ > [!TIP]
1023
+ > If you want to make changes to the model config used in production for HuggingChat, you should do so against `chart/env/prod.yaml`.
1024
+
1025
+ ### Running a copy of HuggingChat locally
1026
+
1027
+ If you want to run an exact copy of HuggingChat locally, you will need to do the following first:
1028
+
1029
+ 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.
1030
+ 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.
1031
+ 3. Create a free account with [serper.dev](https://serper.dev/) (you will get 2500 free search queries)
1032
+ 4. Run an instance of mongoDB, however you want. (Local or remote)
1033
+
1034
+ You can then create a new `.env.SECRET_CONFIG` file with the following content
1035
+
1036
+ ```env
1037
+ MONGODB_URL=<link to your mongo DB from step 4>
1038
+ HF_TOKEN=<your HF token from step 2>
1039
+ OPENID_CONFIG=`{
1040
+ PROVIDER_URL: "https://huggingface.co",
1041
+ CLIENT_ID: "<your client ID from step 1>",
1042
+ CLIENT_SECRET: "<your client secret from step 1>",
1043
+ }`
1044
+ SERPER_API_KEY=<your serper API key from step 3>
1045
+ MESSAGES_BEFORE_LOGIN=<can be any numerical value, or set to 0 to require login>
1046
+ ```
1047
+
1048
+ 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.
1049
+
1050
+ ### Populate database
1051
+
1052
+ > [!WARNING]
1053
+ > 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.
1054
+
1055
+ You can populate the database using faker data using the `populate` script:
1056
+
1057
+ ```bash
1058
+ npm run populate <flags here>
1059
+ ```
1060
+
1061
+ At least one flag must be specified, the following flags are available:
1062
+
1063
+ - `reset` - resets the database
1064
+ - `all` - populates all tables
1065
+ - `users` - populates the users table
1066
+ - `settings` - populates the settings table for existing users
1067
+ - `assistants` - populates the assistants table for existing users
1068
+ - `conversations` - populates the conversations table for existing users
1069
+
1070
+ For example, you could use it like so:
1071
+
1072
+ ```bash
1073
+ npm run populate reset
1074
+ ```
1075
+
1076
+ to clear out the database. Then login in the app to create your user and run the following command:
1077
+
1078
+ ```bash
1079
+ npm run populate users settings assistants conversations
1080
+ ```
1081
+
1082
+ to populate the database with fake data, including fake conversations and assistants for your user.
1083
+
1084
+ ## Building the docker images locally
1085
+
1086
+ You can build the docker images locally using the following commands:
1087
+
1088
+ ```bash
1089
+ docker build -t chat-ui-db:latest --build-arg INCLUDE_DB=true .
1090
+ docker build -t chat-ui:latest --build-arg INCLUDE_DB=false .
1091
+ docker build -t huggingchat:latest --build-arg INCLUDE_DB=false --build-arg APP_BASE=/chat --build-arg PUBLIC_APP_COLOR=yellow .
1092
+ ```
1093
+
1094
+ If you want to run the images with your local .env.local you have two options
1095
+
1096
+ ```bash
1097
+ DOTENV_LOCAL=$(<.env.local) docker run --rm --network=host -e DOTENV_LOCAL -p 3000:3000 chat-ui
1098
+ ```
1099
+
1100
+ ```bash
1101
+ docker run --rm --network=host --mount type=bind,source="$(pwd)/.env.local",target=/app/.env.local -p 3000:3000 chat-ui
1102
+ ```