peterpeter8585 commited on
Commit
9818b69
·
verified ·
1 Parent(s): 693978c

Upload 12 files

Browse files
Files changed (12) hide show
  1. Dockerfile +95 -0
  2. LICENSE +203 -0
  3. PRIVACY.md +42 -0
  4. PROMPTS.md +69 -0
  5. README.md +1066 -10
  6. entrypoint.sh +19 -0
  7. package-lock.json +0 -0
  8. package.json +124 -0
  9. postcss.config.js +6 -0
  10. svelte.config.js +46 -0
  11. tailwind.config.cjs +24 -0
  12. tsconfig.json +19 -0
Dockerfile ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # syntax=docker/dockerfile:1
2
+ ARG INCLUDE_DB=false
3
+
4
+ FROM node:20-slim AS base
5
+ ENV PLAYWRIGHT_SKIP_BROWSER_GC=1
6
+
7
+ # install dotenv-cli
8
+ RUN npm install -g dotenv-cli
9
+
10
+ # switch to a user that works for spaces
11
+ RUN userdel -r node
12
+ RUN useradd -m -u 1000 user
13
+ USER user
14
+
15
+ ENV HOME=/home/user \
16
+ PATH=/home/user/.local/bin:$PATH
17
+
18
+ WORKDIR /app
19
+
20
+ # add a .env.local if the user doesn't bind a volume to it
21
+ RUN touch /app/.env.local
22
+
23
+
24
+ RUN npm i --no-package-lock --no-save [email protected]
25
+ USER root
26
+ RUN apt-get update
27
+ RUN apt-get install gnupg curl -y
28
+ RUN npx playwright install --with-deps chromium
29
+ RUN chown -R 1000:1000 /home/user/.npm
30
+ USER user
31
+
32
+ COPY --chown=1000 .env /app/.env
33
+ COPY --chown=1000 entrypoint.sh /app/entrypoint.sh
34
+ COPY --chown=1000 gcp-*.json /app/
35
+ COPY --chown=1000 package.json /app/package.json
36
+ COPY --chown=1000 package-lock.json /app/package-lock.json
37
+
38
+ RUN chmod +x /app/entrypoint.sh
39
+
40
+
41
+ FROM node:20 AS builder
42
+
43
+ WORKDIR /app
44
+
45
+ COPY --link --chown=1000 package-lock.json package.json ./
46
+
47
+ ARG APP_BASE=
48
+ ARG PUBLIC_APP_COLOR=blue
49
+ ENV BODY_SIZE_LIMIT=15728640
50
+
51
+ RUN --mount=type=cache,target=/app/.npm \
52
+ npm set cache /app/.npm && \
53
+ npm ci
54
+
55
+ COPY --link --chown=1000 . .
56
+
57
+ RUN git config --global --add safe.directory /app && \
58
+ npm run build
59
+
60
+ # mongo image
61
+ FROM mongo:7 AS mongo
62
+
63
+ # image to be used if INCLUDE_DB is false
64
+ FROM base AS local_db_false
65
+
66
+ # image to be used if INCLUDE_DB is true
67
+ FROM base AS local_db_true
68
+
69
+ # copy mongo from the other stage
70
+ COPY --from=mongo /usr/bin/mongo* /usr/bin/
71
+
72
+ ENV MONGODB_URL=mongodb://localhost:27017
73
+ USER root
74
+ RUN mkdir -p /data/db
75
+ RUN chown -R 1000:1000 /data/db
76
+ USER user
77
+ # final image
78
+ FROM local_db_${INCLUDE_DB} AS final
79
+
80
+ # build arg to determine if the database should be included
81
+ ARG INCLUDE_DB=false
82
+ ENV INCLUDE_DB=${INCLUDE_DB}
83
+
84
+ # svelte requires APP_BASE at build time so it must be passed as a build arg
85
+ ARG APP_BASE=
86
+ # tailwind requires the primary theme to be known at build time so it must be passed as a build arg
87
+ ARG PUBLIC_APP_COLOR=blue
88
+ ARG PUBLIC_COMMIT_SHA=
89
+ ENV PUBLIC_COMMIT_SHA=${PUBLIC_COMMIT_SHA}
90
+ ENV BODY_SIZE_LIMIT=15728640
91
+ #import the build & dependencies
92
+ COPY --from=builder --chown=1000 /app/build /app/build
93
+ COPY --from=builder --chown=1000 /app/node_modules /app/node_modules
94
+
95
+ CMD ["/bin/bash", "-c", "/app/entrypoint.sh"]
LICENSE ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright 2018- The Hugging Face team. All rights reserved.
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright [yyyy] [name of copyright owner]
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
PRIVACY.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Privacy
2
+
3
+ > Last updated: April 15, 2024
4
+
5
+ Users of HuggingChat are authenticated through their HF user account.
6
+
7
+ We endorse Privacy by Design. As such, your conversations are private to you and will not be shared with anyone, including model authors, for any purpose, including for research or model training purposes.
8
+
9
+ You conversation data will only be stored to let you access past conversations. You can click on the Delete icon to delete any past conversation at any moment.
10
+
11
+ 🗓 Please also consult huggingface.co's main privacy policy at <https://huggingface.co/privacy>. To exercise any of your legal privacy rights, please send an email to <[email protected]>.
12
+
13
+ ## About available LLMs
14
+
15
+ The goal of this app is to showcase that it is now possible to build an open source alternative to ChatGPT. 💪
16
+
17
+ We aim to always provide a diverse set of state of the art open LLMs, hence we rotate the available models over time.
18
+
19
+ Historically, HuggingChat has been running models such as:
20
+
21
+ - [Llama 2 70B](https://huggingface.co/meta-llama/Llama-2-70b-chat-hf)
22
+ - [CodeLlama 35B](https://about.fb.com/news/2023/08/code-llama-ai-for-coding/)
23
+ - [Falcon 180B](https://www.tii.ae/news/technology-innovation-institute-introduces-worlds-most-powerful-open-llm-falcon-180b)
24
+ - [Mistral 7B](https://mistral.ai/news/announcing-mistral-7b/)
25
+ - [Cohere Command R+](https://huggingface.co/chat/models/CohereForAI/c4ai-command-r-plus)
26
+ - [Google Gemma 7B](https://huggingface.co/chat/models/google/gemma-1.1-7b-it)
27
+
28
+ This is only a partial list. Check the [models](https://huggingface.co/chat/models/) page for up-to-date list of the best available LLMs.
29
+
30
+ ## Technical details
31
+
32
+ This app is running in a [Space](https://huggingface.co/docs/hub/spaces-overview), which entails that the code for this UI is publicly visible [inside the Space repo](https://huggingface.co/spaces/huggingchat/chat-ui/tree/main).
33
+
34
+ **Further development takes place on the [huggingface/chat-ui GitHub repo](https://github.com/huggingface/chat-ui).**
35
+
36
+ The inference backend is running the optimized [text-generation-inference](https://github.com/huggingface/text-generation-inference) on HuggingFace's Inference API infrastructure.
37
+
38
+ It is therefore possible to deploy a copy of this app to a Space and customize it (swap model, add some UI elements, or store user messages according to your own Terms and conditions). You can also 1-click deploy your own instance using the [Chat UI Spaces Docker template](https://huggingface.co/new-space?template=huggingchat/chat-ui-template).
39
+
40
+ We welcome any feedback on this app: please participate to the public discussion at <https://huggingface.co/spaces/huggingchat/chat-ui/discussions>
41
+
42
+ <a target="_blank" href="https://huggingface.co/spaces/huggingchat/chat-ui/discussions"><img src="https://huggingface.co/datasets/huggingface/badges/raw/main/open-a-discussion-xl.svg" title="open a discussion"></a>
PROMPTS.md ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Prompt templates
2
+
3
+ These are the templates used to format the conversation history for different models used in HuggingChat. Set them in your `.env.local` [like so](https://github.com/huggingface/chat-ui#chatprompttemplate).
4
+
5
+ ## Llama 2
6
+
7
+ ```env
8
+ <s>[INST] <<SYS>>\n{{preprompt}}\n<</SYS>>\n\n{{#each messages}}{{#ifUser}}{{content}} [/INST] {{/ifUser}}{{#ifAssistant}}{{content}} </s><s>[INST] {{/ifAssistant}}{{/each}}
9
+ ```
10
+
11
+ ## CodeLlama
12
+
13
+ ```env
14
+ <s>[INST] <<SYS>>\n{{preprompt}}\n<</SYS>>\n\n{{#each messages}}{{#ifUser}}{{content}} [/INST] {{/ifUser}}{{#ifAssistant}}{{content}} </s><s>[INST] {{/ifAssistant}}{{/each}}
15
+ ```
16
+
17
+ ## Falcon
18
+
19
+ ```env
20
+ System: {{preprompt}}\nUser:{{#each messages}}{{#ifUser}}{{content}}\nFalcon:{{/ifUser}}{{#ifAssistant}}{{content}}\nUser:{{/ifAssistant}}{{/each}}
21
+ ```
22
+
23
+ ## Mistral
24
+
25
+ ```env
26
+ <s>{{#each messages}}{{#ifUser}}[INST] {{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}} {{content}} [/INST]{{/ifUser}}{{#ifAssistant}}{{content}}</s> {{/ifAssistant}}{{/each}}
27
+ ```
28
+
29
+ ## Zephyr
30
+
31
+ ```env
32
+ <|system|>\n{{preprompt}}</s>\n{{#each messages}}{{#ifUser}}<|user|>\n{{content}}</s>\n<|assistant|>\n{{/ifUser}}{{#ifAssistant}}{{content}}</s>\n{{/ifAssistant}}{{/each}}
33
+ ```
34
+
35
+ ## IDEFICS
36
+
37
+ ```env
38
+ {{#each messages}}{{#ifUser}}User: {{content}}{{/ifUser}}<end_of_utterance>\nAssistant: {{#ifAssistant}}{{content}}\n{{/ifAssistant}}{{/each}}
39
+ ```
40
+
41
+ ## OpenChat
42
+
43
+ ```env
44
+ <s>{{#each messages}}{{#ifUser}}GPT4 User: {{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}}{{content}}<|end_of_turn|>GPT4 Assistant: {{/ifUser}}{{#ifAssistant}}{{content}}<|end_of_turn|>{{/ifAssistant}}{{/each}}
45
+ ```
46
+
47
+ ## Mixtral
48
+
49
+ ```env
50
+ <s> {{#each messages}}{{#ifUser}}[INST]{{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}} {{content}} [/INST]{{/ifUser}}{{#ifAssistant}} {{content}}</s> {{/ifAssistant}}{{/each}}
51
+ ```
52
+
53
+ ## ChatML
54
+
55
+ ```env
56
+ {{#if @root.preprompt}}<|im_start|>system\n{{@root.preprompt}}<|im_end|>\n{{/if}}{{#each messages}}{{#ifUser}}<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n{{/ifUser}}{{#ifAssistant}}{{content}}<|im_end|>\n{{/ifAssistant}}{{/each}}
57
+ ```
58
+
59
+ ## CodeLlama 70B
60
+
61
+ ```env
62
+ <s>{{#if @root.preprompt}}Source: system\n\n {{@root.preprompt}} <step> {{/if}}{{#each messages}}{{#ifUser}}Source: user\n\n {{content}} <step> {{/ifUser}}{{#ifAssistant}}Source: assistant\n\n {{content}} <step> {{/ifAssistant}}{{/each}}Source: assistant\nDestination: user\n\n ``
63
+ ```
64
+
65
+ ## Gemma
66
+
67
+ ```env
68
+ {{#each messages}}{{#ifUser}}<start_of_turn>user\n{{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}}{{content}}<end_of_turn>\n<start_of_turn>model\n{{/ifUser}}{{#ifAssistant}}{{content}}<end_of_turn>\n{{/ifAssistant}}{{/each}}
69
+ ```
README.md CHANGED
@@ -1,10 +1,1066 @@
1
- ---
2
- title: Chat2
3
- emoji: 😻
4
- colorFrom: green
5
- colorTo: purple
6
- sdk: docker
7
- pinned: false
8
- ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #### Multi modal model
318
+
319
+ 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).
320
+
321
+ ```env
322
+ {
323
+ "name": "HuggingFaceM4/idefics-80b-instruct",
324
+ "multimodal" : true,
325
+ "description": "IDEFICS is the new multimodal model by Hugging Face.",
326
+ "preprompt": "",
327
+ "chatPromptTemplate" : "{{#each messages}}{{#ifUser}}User: {{content}}{{/ifUser}}<end_of_utterance>\nAssistant: {{#ifAssistant}}{{content}}\n{{/ifAssistant}}{{/each}}",
328
+ "parameters": {
329
+ "temperature": 0.1,
330
+ "top_p": 0.95,
331
+ "repetition_penalty": 1.2,
332
+ "top_k": 12,
333
+ "truncate": 1000,
334
+ "max_new_tokens": 1024,
335
+ "stop": ["<end_of_utterance>", "User:", "\nUser:"]
336
+ }
337
+ }
338
+ ```
339
+
340
+ #### Running your own models using a custom endpoint
341
+
342
+ If you want to, instead of hitting models on the Hugging Face Inference API, you can run your own models locally.
343
+
344
+ 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.
345
+
346
+ 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`.
347
+
348
+ ```env
349
+ {
350
+ // rest of the model config here
351
+ "endpoints": [{
352
+ "type" : "tgi",
353
+ "url": "https://HOST:PORT",
354
+ }]
355
+ }
356
+ ```
357
+
358
+ If `endpoints` are left unspecified, ChatUI will look for the model on the hosted Hugging Face inference API using the model name.
359
+
360
+ ##### OpenAI API compatible models
361
+
362
+ 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).
363
+
364
+ 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.
365
+
366
+ 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.
367
+
368
+ ```
369
+ MODELS=`[
370
+ {
371
+ "name": "text-generation-webui",
372
+ "id": "text-generation-webui",
373
+ "parameters": {
374
+ "temperature": 0.9,
375
+ "top_p": 0.95,
376
+ "max_new_tokens": 1024,
377
+ "stop": []
378
+ },
379
+ "endpoints": [{
380
+ "type" : "openai",
381
+ "baseURL": "http://localhost:8000/v1",
382
+ "extraBody": {
383
+ "repetition_penalty": 1.2,
384
+ "top_k": 50,
385
+ "truncate": 1000
386
+ }
387
+ }]
388
+ }
389
+ ]`
390
+
391
+ ```
392
+
393
+ The `openai` type includes official OpenAI models. You can add, for example, GPT4/GPT3.5 as a "openai" model:
394
+
395
+ ```
396
+ OPENAI_API_KEY=#your openai api key here
397
+ MODELS=`[{
398
+ "name": "gpt-4",
399
+ "displayName": "GPT 4",
400
+ "endpoints" : [{
401
+ "type": "openai"
402
+ }]
403
+ },
404
+ {
405
+ "name": "gpt-3.5-turbo",
406
+ "displayName": "GPT 3.5 Turbo",
407
+ "endpoints" : [{
408
+ "type": "openai"
409
+ }]
410
+ }]`
411
+ ```
412
+
413
+ 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:
414
+
415
+ ```
416
+ MODELS=`[{
417
+ "name": "claude-2.1",
418
+ "displayName": "Claude 2.1",
419
+ "description": "Anthropic has been founded by former OpenAI researchers...",
420
+ "parameters": {
421
+ "temperature": 0.5,
422
+ "max_new_tokens": 4096,
423
+ },
424
+ "endpoints": [
425
+ {
426
+ "type": "openai",
427
+ "baseURL": "https://gateway.example.com/v1",
428
+ "defaultHeaders": {
429
+ "x-portkey-config": '{"provider":"anthropic","api_key":"sk-ant-abc...xyz"}'
430
+ }
431
+ }
432
+ ]
433
+ }]`
434
+ ```
435
+
436
+ Example for GPT 4 deployed on Azure OpenAI:
437
+
438
+ ```
439
+ MODELS=`[{
440
+ "id": "gpt-4-1106-preview",
441
+ "name": "gpt-4-1106-preview",
442
+ "displayName": "gpt-4-1106-preview",
443
+ "parameters": {
444
+ "temperature": 0.5,
445
+ "max_new_tokens": 4096,
446
+ },
447
+ "endpoints": [
448
+ {
449
+ "type": "openai",
450
+ "baseURL": "https://{resource-name}.openai.azure.com/openai/deployments/{deployment-id}",
451
+ "defaultHeaders": {
452
+ "api-key": "{api-key}"
453
+ },
454
+ "defaultQuery": {
455
+ "api-version": "2023-05-15"
456
+ }
457
+ }
458
+ ]
459
+ }]`
460
+ ```
461
+
462
+ Or try Mistral from [Deepinfra](https://deepinfra.com/mistralai/Mistral-7B-Instruct-v0.1/api?example=openai-http):
463
+
464
+ > Note, apiKey can either be set custom per endpoint, or globally using `OPENAI_API_KEY` variable.
465
+
466
+ ```
467
+ MODELS=`[{
468
+ "name": "mistral-7b",
469
+ "displayName": "Mistral 7B",
470
+ "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.",
471
+ "parameters": {
472
+ "temperature": 0.5,
473
+ "max_new_tokens": 4096,
474
+ },
475
+ "endpoints": [
476
+ {
477
+ "type": "openai",
478
+ "baseURL": "https://api.deepinfra.com/v1/openai",
479
+ "apiKey": "abc...xyz"
480
+ }
481
+ ]
482
+ }]`
483
+ ```
484
+
485
+ ##### Llama.cpp API server
486
+
487
+ 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.
488
+
489
+ 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:
490
+
491
+ ```bash
492
+ # install llama.cpp
493
+ brew install llama.cpp
494
+ # start llama.cpp server
495
+ llama-server --hf-repo microsoft/Phi-3-mini-4k-instruct-gguf --hf-file Phi-3-mini-4k-instruct-q4.gguf -c 4096
496
+ ```
497
+
498
+ ```env
499
+ MODELS=`[
500
+ {
501
+ "name": "Local Zephyr",
502
+ "chatPromptTemplate": "<|system|>\n{{preprompt}}</s>\n{{#each messages}}{{#ifUser}}<|user|>\n{{content}}</s>\n<|assistant|>\n{{/ifUser}}{{#ifAssistant}}{{content}}</s>\n{{/ifAssistant}}{{/each}}",
503
+ "parameters": {
504
+ "temperature": 0.1,
505
+ "top_p": 0.95,
506
+ "repetition_penalty": 1.2,
507
+ "top_k": 50,
508
+ "truncate": 1000,
509
+ "max_new_tokens": 2048,
510
+ "stop": ["</s>"]
511
+ },
512
+ "endpoints": [
513
+ {
514
+ "url": "http://127.0.0.1:8080",
515
+ "type": "llamacpp"
516
+ }
517
+ ]
518
+ }
519
+ ]`
520
+ ```
521
+
522
+ Start chat-ui with `npm run dev` and you should be able to chat with Zephyr locally.
523
+
524
+ #### Ollama
525
+
526
+ We also support the Ollama inference server. Spin up a model with
527
+
528
+ ```cli
529
+ ollama run mistral
530
+ ```
531
+
532
+ Then specify the endpoints like so:
533
+
534
+ ```env
535
+ MODELS=`[
536
+ {
537
+ "name": "Ollama Mistral",
538
+ "chatPromptTemplate": "<s>{{#each messages}}{{#ifUser}}[INST] {{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}} {{content}} [/INST]{{/ifUser}}{{#ifAssistant}}{{content}}</s> {{/ifAssistant}}{{/each}}",
539
+ "parameters": {
540
+ "temperature": 0.1,
541
+ "top_p": 0.95,
542
+ "repetition_penalty": 1.2,
543
+ "top_k": 50,
544
+ "truncate": 3072,
545
+ "max_new_tokens": 1024,
546
+ "stop": ["</s>"]
547
+ },
548
+ "endpoints": [
549
+ {
550
+ "type": "ollama",
551
+ "url" : "http://127.0.0.1:11434",
552
+ "ollamaName" : "mistral"
553
+ }
554
+ ]
555
+ }
556
+ ]`
557
+ ```
558
+
559
+ #### Anthropic
560
+
561
+ 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.
562
+
563
+ ```
564
+ MODELS=`[
565
+ {
566
+ "name": "claude-3-haiku-20240307",
567
+ "displayName": "Claude 3 Haiku",
568
+ "description": "Fastest and most compact model for near-instant responsiveness",
569
+ "multimodal": true,
570
+ "parameters": {
571
+ "max_new_tokens": 4096,
572
+ },
573
+ "endpoints": [
574
+ {
575
+ "type": "anthropic",
576
+ // optionals
577
+ "apiKey": "sk-ant-...",
578
+ "baseURL": "https://api.anthropic.com",
579
+ "defaultHeaders": {},
580
+ "defaultQuery": {}
581
+ }
582
+ ]
583
+ },
584
+ {
585
+ "name": "claude-3-sonnet-20240229",
586
+ "displayName": "Claude 3 Sonnet",
587
+ "description": "Ideal balance of intelligence and speed",
588
+ "multimodal": true,
589
+ "parameters": {
590
+ "max_new_tokens": 4096,
591
+ },
592
+ "endpoints": [
593
+ {
594
+ "type": "anthropic",
595
+ // optionals
596
+ "apiKey": "sk-ant-...",
597
+ "baseURL": "https://api.anthropic.com",
598
+ "defaultHeaders": {},
599
+ "defaultQuery": {}
600
+ }
601
+ ]
602
+ },
603
+ {
604
+ "name": "claude-3-opus-20240229",
605
+ "displayName": "Claude 3 Opus",
606
+ "description": "Most powerful model for highly complex tasks",
607
+ "multimodal": true,
608
+ "parameters": {
609
+ "max_new_tokens": 4096
610
+ },
611
+ "endpoints": [
612
+ {
613
+ "type": "anthropic",
614
+ // optionals
615
+ "apiKey": "sk-ant-...",
616
+ "baseURL": "https://api.anthropic.com",
617
+ "defaultHeaders": {},
618
+ "defaultQuery": {}
619
+ }
620
+ ]
621
+ }
622
+ ]`
623
+ ```
624
+
625
+ 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:
626
+
627
+ ```
628
+ MODELS=`[
629
+ {
630
+ "name": "claude-3-sonnet@20240229",
631
+ "displayName": "Claude 3 Sonnet",
632
+ "description": "Ideal balance of intelligence and speed",
633
+ "multimodal": true,
634
+ "parameters": {
635
+ "max_new_tokens": 4096,
636
+ },
637
+ "endpoints": [
638
+ {
639
+ "type": "anthropic-vertex",
640
+ "region": "us-central1",
641
+ "projectId": "gcp-project-id",
642
+ // optionals
643
+ "defaultHeaders": {},
644
+ "defaultQuery": {}
645
+ }
646
+ ]
647
+ },
648
+ {
649
+ "name": "claude-3-haiku@20240307",
650
+ "displayName": "Claude 3 Haiku",
651
+ "description": "Fastest, most compact model for near-instant responsiveness",
652
+ "multimodal": true,
653
+ "parameters": {
654
+ "max_new_tokens": 4096
655
+ },
656
+ "endpoints": [
657
+ {
658
+ "type": "anthropic-vertex",
659
+ "region": "us-central1",
660
+ "projectId": "gcp-project-id",
661
+ // optionals
662
+ "defaultHeaders": {},
663
+ "defaultQuery": {}
664
+ }
665
+ ]
666
+ }
667
+ ]`
668
+ ```
669
+
670
+ #### Amazon
671
+
672
+ You can also specify your Amazon SageMaker instance as an endpoint for chat-ui. The config goes like this:
673
+
674
+ ```env
675
+ "endpoints": [
676
+ {
677
+ "type" : "aws",
678
+ "service" : "sagemaker"
679
+ "url": "",
680
+ "accessKey": "",
681
+ "secretKey" : "",
682
+ "sessionToken": "",
683
+ "region": "",
684
+
685
+ "weight": 1
686
+ }
687
+ ]
688
+ ```
689
+
690
+ You can also set `"service" : "lambda"` to use a lambda instance.
691
+
692
+ You can get the `accessKey` and `secretKey` from your AWS user, under programmatic access.
693
+
694
+ #### Cloudflare Workers AI
695
+
696
+ You can also use Cloudflare Workers AI to run your own models with serverless inference.
697
+
698
+ 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.
699
+
700
+ 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.
701
+
702
+ You can find the list of models available on Cloudflare [here](https://developers.cloudflare.com/workers-ai/models/#text-generation).
703
+
704
+ ```env
705
+ {
706
+ "name" : "nousresearch/hermes-2-pro-mistral-7b",
707
+ "tokenizer": "nousresearch/hermes-2-pro-mistral-7b",
708
+ "parameters": {
709
+ "stop": ["<|im_end|>"]
710
+ },
711
+ "endpoints" : [
712
+ {
713
+ "type" : "cloudflare"
714
+ <!-- optionally specify these
715
+ "accountId": "your-account-id",
716
+ "authToken": "your-api-token"
717
+ -->
718
+ }
719
+ ]
720
+ }
721
+ ```
722
+
723
+ #### Cohere
724
+
725
+ 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.
726
+
727
+ 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.
728
+
729
+ ```env
730
+ {
731
+ "name" : "CohereForAI/c4ai-command-r-v01",
732
+ "id": "command-r",
733
+ "description": "C4AI Command-R is a research release of a 35 billion parameter highly performant generative model",
734
+ "endpoints": [
735
+ {
736
+ "type": "cohere",
737
+ <!-- optionally specify these, or use COHERE_API_TOKEN
738
+ "apiKey": "your-api-token"
739
+ -->
740
+ }
741
+ ]
742
+ }
743
+ ```
744
+
745
+ ##### Google Vertex models
746
+
747
+ 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)).
748
+
749
+ To enable:
750
+
751
+ 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.
752
+ 1. [Enable billing for your project](https://cloud.google.com/billing/docs/how-to/modify-project).
753
+ 1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).
754
+ 1. [Set up authentication with a service account](https://cloud.google.com/docs/authentication/getting-started)
755
+ so you can access the API from your local workstation.
756
+
757
+ The service account credentials file can be imported as an environmental variable:
758
+
759
+ ```env
760
+ GOOGLE_APPLICATION_CREDENTIALS = clientid.json
761
+ ```
762
+
763
+ Make sure your docker container has access to the file and the variable is correctly set.
764
+ Afterwards Google Vertex endpoints can be configured as following:
765
+
766
+ ```
767
+ MODELS=`[
768
+ //...
769
+ {
770
+ "name": "gemini-1.5-pro",
771
+ "displayName": "Vertex Gemini Pro 1.5",
772
+ "multimodal": true,
773
+ "endpoints" : [{
774
+ "type": "vertex",
775
+ "project": "abc-xyz",
776
+ "location": "europe-west3",
777
+ "extraBody": {
778
+ "model_version": "gemini-1.5-pro-preview-0409",
779
+ },
780
+
781
+ // Optional
782
+ "safetyThreshold": "BLOCK_MEDIUM_AND_ABOVE",
783
+ "apiEndpoint": "", // alternative api endpoint url,
784
+ "tools": [{
785
+ "googleSearchRetrieval": {
786
+ "disableAttribution": true
787
+ }
788
+ }],
789
+ "multimodal": {
790
+ "image": {
791
+ "supportedMimeTypes": ["image/png", "image/jpeg", "image/webp"],
792
+ "preferredMimeType": "image/png",
793
+ "maxSizeInMB": 5,
794
+ "maxWidth": 2000,
795
+ "maxHeight": 1000,
796
+ }
797
+ }
798
+ }]
799
+ },
800
+ ]`
801
+
802
+ ```
803
+
804
+ ##### LangServe
805
+
806
+ LangChain applications that are deployed using LangServe can be called with the following config:
807
+
808
+ ```
809
+ MODELS=`[
810
+ //...
811
+ {
812
+ "name": "summarization-chain", //model-name
813
+ "endpoints" : [{
814
+ "type": "langserve",
815
+ "url" : "http://127.0.0.1:8100",
816
+ }]
817
+ },
818
+ ]`
819
+
820
+ ```
821
+
822
+ ### Custom endpoint authorization
823
+
824
+ #### Basic and Bearer
825
+
826
+ Custom endpoints may require authorization, depending on how you configure them. Authentication will usually be set either with `Basic` or `Bearer`.
827
+
828
+ For `Basic` we will need to generate a base64 encoding of the username and password.
829
+
830
+ `echo -n "USER:PASS" | base64`
831
+
832
+ > VVNFUjpQQVNT
833
+
834
+ For `Bearer` you can use a token, which can be grabbed from [here](https://huggingface.co/settings/tokens).
835
+
836
+ You can then add the generated information and the `authorization` parameter to your `.env.local`.
837
+
838
+ ```env
839
+ "endpoints": [
840
+ {
841
+ "url": "https://HOST:PORT",
842
+ "authorization": "Basic VVNFUjpQQVNT",
843
+ }
844
+ ]
845
+ ```
846
+
847
+ Please note that if `HF_TOKEN` is also set or not empty, it will take precedence.
848
+
849
+ #### Models hosted on multiple custom endpoints
850
+
851
+ 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.
852
+
853
+ ```env
854
+ "endpoints": [
855
+ {
856
+ "url": "https://HOST:PORT",
857
+ "weight": 1
858
+ },
859
+ {
860
+ "url": "https://HOST:PORT",
861
+ "weight": 2
862
+ }
863
+ ...
864
+ ]
865
+ ```
866
+
867
+ #### Client Certificate Authentication (mTLS)
868
+
869
+ 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`.
870
+
871
+ 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.
872
+
873
+ 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.
874
+
875
+ #### Specific Embedding Model
876
+
877
+ A model can use any of the embedding models defined in `.env.local`, (currently used when web searching),
878
+ by default it will use the first embedding model, but it can be changed with the field `embeddingModel`:
879
+
880
+ ```env
881
+ TEXT_EMBEDDING_MODELS = `[
882
+ {
883
+ "name": "Xenova/gte-small",
884
+ "chunkCharLength": 512,
885
+ "endpoints": [
886
+ {"type": "transformersjs"}
887
+ ]
888
+ },
889
+ {
890
+ "name": "intfloat/e5-base-v2",
891
+ "chunkCharLength": 768,
892
+ "endpoints": [
893
+ {"type": "tei", "url": "http://127.0.0.1:8080/", "authorization": "Basic VVNFUjpQQVNT"},
894
+ {"type": "tei", "url": "http://127.0.0.1:8081/"}
895
+ ]
896
+ }
897
+ ]`
898
+
899
+ MODELS=`[
900
+ {
901
+ "name": "Ollama Mistral",
902
+ "chatPromptTemplate": "...",
903
+ "embeddingModel": "intfloat/e5-base-v2"
904
+ "parameters": {
905
+ ...
906
+ },
907
+ "endpoints": [
908
+ ...
909
+ ]
910
+ }
911
+ ]`
912
+
913
+ ```
914
+
915
+ ### Reasoning Models
916
+
917
+ 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:
918
+
919
+ #### Token-Based Delimitations
920
+
921
+ 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.
922
+
923
+ Example configuration for DeepSeek R1 (token-based):
924
+
925
+ ```json
926
+ {
927
+ "name": "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
928
+ // ...
929
+ "reasoning": {
930
+ "type": "tokens",
931
+ "beginToken": "<think>",
932
+ "endToken": "</think>"
933
+ }
934
+ }
935
+ ```
936
+
937
+ #### Summarizing the Chain of Thought
938
+
939
+ 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.
940
+
941
+ Example configuration for QwQ (summarize-based):
942
+
943
+ ```json
944
+ {
945
+ "name": "Qwen/QwQ-32B-Preview",
946
+ // ...
947
+ "reasoning": {
948
+ "type": "summarize"
949
+ }
950
+ }
951
+ ```
952
+
953
+ #### Regex-Based Delimitations
954
+
955
+ 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:
956
+
957
+ ```json
958
+ {
959
+ "name": "model/yourmodel",
960
+ // ...
961
+ "reasoning": {
962
+ "type": "regex",
963
+ "regex": "\\\\boxed\\{(.+?)\\}"
964
+ }
965
+ }
966
+ ```
967
+
968
+ ## Common issues
969
+
970
+ ### 403:You don't have access to this conversation
971
+
972
+ 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`.
973
+
974
+ Make sure to set your `PUBLIC_ORIGIN` in your `.env.local` to the correct URL as well.
975
+
976
+ ## Deploying to a HF Space
977
+
978
+ 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.
979
+
980
+ ## Building
981
+
982
+ To create a production version of your app:
983
+
984
+ ```bash
985
+ npm run build
986
+ ```
987
+
988
+ You can preview the production build with `npm run preview`.
989
+
990
+ > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
991
+
992
+ ## Config changes for HuggingChat
993
+
994
+ 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.
995
+
996
+ > [!TIP]
997
+ > If you want to make changes to the model config used in production for HuggingChat, you should do so against `chart/env/prod.yaml`.
998
+
999
+ ### Running a copy of HuggingChat locally
1000
+
1001
+ If you want to run an exact copy of HuggingChat locally, you will need to do the following first:
1002
+
1003
+ 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.
1004
+ 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.
1005
+ 3. Create a free account with [serper.dev](https://serper.dev/) (you will get 2500 free search queries)
1006
+ 4. Run an instance of mongoDB, however you want. (Local or remote)
1007
+
1008
+ You can then create a new `.env.SECRET_CONFIG` file with the following content
1009
+
1010
+ ```env
1011
+ MONGODB_URL=<link to your mongo DB from step 4>
1012
+ HF_TOKEN=<your HF token from step 2>
1013
+ OPENID_CONFIG=`{
1014
+ PROVIDER_URL: "https://huggingface.co",
1015
+ CLIENT_ID: "<your client ID from step 1>",
1016
+ CLIENT_SECRET: "<your client secret from step 1>",
1017
+ }`
1018
+ SERPER_API_KEY=<your serper API key from step 3>
1019
+ MESSAGES_BEFORE_LOGIN=<can be any numerical value, or set to 0 to require login>
1020
+ ```
1021
+
1022
+ 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.
1023
+
1024
+ ### Populate database
1025
+
1026
+ > [!WARNING]
1027
+ > 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.
1028
+
1029
+ You can populate the database using faker data using the `populate` script:
1030
+
1031
+ ```bash
1032
+ npm run populate <flags here>
1033
+ ```
1034
+
1035
+ At least one flag must be specified, the following flags are available:
1036
+
1037
+ - `reset` - resets the database
1038
+ - `all` - populates all tables
1039
+ - `users` - populates the users table
1040
+ - `settings` - populates the settings table for existing users
1041
+ - `assistants` - populates the assistants table for existing users
1042
+ - `conversations` - populates the conversations table for existing users
1043
+
1044
+ For example, you could use it like so:
1045
+
1046
+ ```bash
1047
+ npm run populate reset
1048
+ ```
1049
+
1050
+ to clear out the database. Then login in the app to create your user and run the following command:
1051
+
1052
+ ```bash
1053
+ npm run populate users settings assistants conversations
1054
+ ```
1055
+
1056
+ to populate the database with fake data, including fake conversations and assistants for your user.
1057
+
1058
+ ### Building the docker images locally
1059
+
1060
+ You can build the docker images locally using the following commands:
1061
+
1062
+ ```bash
1063
+ docker build -t chat-ui-db:latest --build-arg INCLUDE_DB=true .
1064
+ docker build -t chat-ui:latest --build-arg INCLUDE_DB=false .
1065
+ docker build -t huggingchat:latest --build-arg INCLUDE_DB=false --build-arg APP_BASE=/chat --build-arg PUBLIC_APP_COLOR=yellow .
1066
+ ```
entrypoint.sh ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ENV_LOCAL_PATH=/app/.env.local
2
+
3
+ if test -z "${DOTENV_LOCAL}" ; then
4
+ if ! test -f "${ENV_LOCAL_PATH}" ; then
5
+ echo "DOTENV_LOCAL was not found in the ENV variables and .env.local is not set using a bind volume. Make sure to set environment variables properly. "
6
+ fi;
7
+ else
8
+ echo "DOTENV_LOCAL was found in the ENV variables. Creating .env.local file."
9
+ cat <<< "$DOTENV_LOCAL" > ${ENV_LOCAL_PATH}
10
+ fi;
11
+
12
+ if [ "$INCLUDE_DB" = "true" ] ; then
13
+ echo "Starting local MongoDB instance"
14
+ nohup mongod &
15
+ fi;
16
+
17
+ export PUBLIC_VERSION=$(node -p "require('./package.json').version")
18
+
19
+ dotenv -e /app/.env -c -- node /app/build/index.js -- --host 0.0.0.0 --port 3000
package-lock.json ADDED
The diff for this file is too large to render. See raw diff
 
package.json ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "chat-ui",
3
+ "version": "0.9.4",
4
+ "private": true,
5
+ "packageManager": "[email protected]",
6
+ "scripts": {
7
+ "dev": "vite dev",
8
+ "build": "vite build",
9
+ "preview": "vite preview",
10
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
11
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
12
+ "lint": "prettier --check . && eslint .",
13
+ "format": "prettier --write .",
14
+ "test": "vitest",
15
+ "updateLocalEnv": "node --loader ts-node/esm scripts/updateLocalEnv.ts",
16
+ "populate": "vite-node --options.transformMode.ssr='/.*/' scripts/populate.ts",
17
+ "prepare": "husky"
18
+ },
19
+ "devDependencies": {
20
+ "@faker-js/faker": "^8.4.1",
21
+ "@iconify-json/carbon": "^1.1.16",
22
+ "@iconify-json/eos-icons": "^1.1.6",
23
+ "@sveltejs/adapter-node": "^5.2.0",
24
+ "@sveltejs/kit": "^2.17.1",
25
+ "@sveltejs/vite-plugin-svelte": "^5.0.3",
26
+ "@tailwindcss/typography": "^0.5.9",
27
+ "@types/dompurify": "^3.0.5",
28
+ "@types/express": "^4.17.21",
29
+ "@types/js-yaml": "^4.0.9",
30
+ "@types/jsdom": "^21.1.1",
31
+ "@types/jsonpath": "^0.2.4",
32
+ "@types/katex": "^0.16.7",
33
+ "@types/mime-types": "^2.1.4",
34
+ "@types/minimist": "^1.2.5",
35
+ "@types/node": "^22.1.0",
36
+ "@types/parquetjs": "^0.10.3",
37
+ "@types/sbd": "^1.0.5",
38
+ "@types/uuid": "^9.0.8",
39
+ "@typescript-eslint/eslint-plugin": "^6.x",
40
+ "@typescript-eslint/parser": "^6.x",
41
+ "dompurify": "^3.1.6",
42
+ "eslint": "^8.28.0",
43
+ "eslint-config-prettier": "^8.5.0",
44
+ "eslint-plugin-svelte": "^2.45.1",
45
+ "isomorphic-dompurify": "^2.13.0",
46
+ "js-yaml": "^4.1.0",
47
+ "minimist": "^1.2.8",
48
+ "mongodb-memory-server": "^10.1.2",
49
+ "prettier": "^3.1.0",
50
+ "prettier-plugin-svelte": "^3.2.6",
51
+ "prettier-plugin-tailwindcss": "^0.6.11",
52
+ "prom-client": "^15.1.2",
53
+ "svelte": "^5.0.0",
54
+ "svelte-check": "^4.0.0",
55
+ "ts-node": "^10.9.1",
56
+ "tslib": "^2.4.1",
57
+ "typescript": "^5.5.0",
58
+ "unplugin-icons": "^0.16.1",
59
+ "vite": "^6.1.0",
60
+ "vite-node": "^1.3.1",
61
+ "vitest": "^2.1.9"
62
+ },
63
+ "type": "module",
64
+ "dependencies": {
65
+ "@aws-sdk/credential-providers": "^3.592.0",
66
+ "@cliqz/adblocker-playwright": "^1.27.2",
67
+ "@gradio/client": "^1.8.0",
68
+ "@huggingface/hub": "^0.5.1",
69
+ "@huggingface/inference": "^2.8.1",
70
+ "@huggingface/transformers": "^3.1.1",
71
+ "@iconify-json/bi": "^1.1.21",
72
+ "@playwright/browser-chromium": "^1.43.1",
73
+ "@resvg/resvg-js": "^2.6.2",
74
+ "autoprefixer": "^10.4.14",
75
+ "aws-sigv4-fetch": "^4.0.1",
76
+ "aws4": "^1.13.0",
77
+ "browser-image-resizer": "^2.4.1",
78
+ "date-fns": "^2.29.3",
79
+ "dotenv": "^16.0.3",
80
+ "express": "^4.21.2",
81
+ "file-type": "^19.4.1",
82
+ "google-auth-library": "^9.13.0",
83
+ "handlebars": "^4.7.8",
84
+ "highlight.js": "^11.7.0",
85
+ "husky": "^9.0.11",
86
+ "image-size": "^1.0.2",
87
+ "ip-address": "^9.0.5",
88
+ "jose": "^5.3.0",
89
+ "jsdom": "^22.0.0",
90
+ "json5": "^2.2.3",
91
+ "jsonpath": "^1.1.1",
92
+ "katex": "^0.16.21",
93
+ "lint-staged": "^15.2.7",
94
+ "marked": "^12.0.1",
95
+ "mongodb": "^5.8.0",
96
+ "nanoid": "^5.0.9",
97
+ "openid-client": "^5.4.2",
98
+ "parquetjs": "^0.11.2",
99
+ "pino": "^9.0.0",
100
+ "pino-pretty": "^11.0.0",
101
+ "playwright": "^1.44.1",
102
+ "postcss": "^8.4.31",
103
+ "saslprep": "^1.0.3",
104
+ "satori": "^0.10.11",
105
+ "satori-html": "^0.3.2",
106
+ "sbd": "^1.0.19",
107
+ "serpapi": "^1.1.1",
108
+ "sharp": "^0.33.4",
109
+ "tailwind-scrollbar": "^3.0.0",
110
+ "tailwindcss": "^3.4.0",
111
+ "uuid": "^10.0.0",
112
+ "zod": "^3.22.3"
113
+ },
114
+ "optionalDependencies": {
115
+ "@anthropic-ai/sdk": "^0.32.1",
116
+ "@anthropic-ai/vertex-sdk": "^0.4.1",
117
+ "@aws-sdk/client-bedrock-runtime": "^3.631.0",
118
+ "@google-cloud/vertexai": "^1.1.0",
119
+ "@google/generative-ai": "^0.14.1",
120
+ "aws4fetch": "^1.0.17",
121
+ "cohere-ai": "^7.9.0",
122
+ "openai": "^4.44.0"
123
+ }
124
+ }
postcss.config.js ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ export default {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {},
5
+ },
6
+ };
svelte.config.js ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import adapter from "@sveltejs/adapter-node";
2
+ import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
3
+ import dotenv from "dotenv";
4
+ import { execSync } from "child_process";
5
+
6
+ dotenv.config({ path: "./.env.local" });
7
+ dotenv.config({ path: "./.env" });
8
+
9
+ function getCurrentCommitSHA() {
10
+ try {
11
+ return execSync("git rev-parse HEAD").toString();
12
+ } catch (error) {
13
+ console.error("Error getting current commit SHA:", error);
14
+ return "unknown";
15
+ }
16
+ }
17
+
18
+ process.env.PUBLIC_VERSION ??= process.env.npm_package_version;
19
+ process.env.PUBLIC_COMMIT_SHA ??= getCurrentCommitSHA();
20
+
21
+ /** @type {import('@sveltejs/kit').Config} */
22
+ const config = {
23
+ // Consult https://kit.svelte.dev/docs/integrations#preprocessors
24
+ // for more information about preprocessors
25
+ preprocess: vitePreprocess(),
26
+
27
+ kit: {
28
+ adapter: adapter(),
29
+
30
+ paths: {
31
+ base: process.env.APP_BASE || "",
32
+ relative: false,
33
+ },
34
+ csrf: {
35
+ // handled in hooks.server.ts, because we can have multiple valid origins
36
+ checkOrigin: false,
37
+ },
38
+ csp: {
39
+ directives: {
40
+ ...(process.env.ALLOW_IFRAME === "true" ? {} : { "frame-ancestors": ["'none'"] }),
41
+ },
42
+ },
43
+ },
44
+ };
45
+
46
+ export default config;
tailwind.config.cjs ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const defaultTheme = require("tailwindcss/defaultTheme");
2
+ const colors = require("tailwindcss/colors");
3
+
4
+ /** @type {import('tailwindcss').Config} */
5
+ export default {
6
+ darkMode: "class",
7
+ mode: "jit",
8
+ content: ["./src/**/*.{html,js,svelte,ts}"],
9
+ theme: {
10
+ extend: {
11
+ colors: {
12
+ primary: colors[process.env.PUBLIC_APP_COLOR],
13
+ },
14
+ fontSize: {
15
+ xxs: "0.625rem",
16
+ smd: "0.94rem",
17
+ },
18
+ },
19
+ },
20
+ plugins: [
21
+ require("tailwind-scrollbar")({ nocompatible: true }),
22
+ require("@tailwindcss/typography"),
23
+ ],
24
+ };
tsconfig.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "extends": "./.svelte-kit/tsconfig.json",
3
+ "compilerOptions": {
4
+ "allowJs": true,
5
+ "checkJs": true,
6
+ "esModuleInterop": true,
7
+ "forceConsistentCasingInFileNames": true,
8
+ "resolveJsonModule": true,
9
+ "skipLibCheck": true,
10
+ "sourceMap": true,
11
+ "strict": true,
12
+ "target": "ES2018"
13
+ },
14
+ "exclude": ["vite.config.ts"]
15
+ // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
16
+ //
17
+ // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
18
+ // from the referenced tsconfig.json - TypeScript does not merge them in
19
+ }