kokofixcomputers coyotte508 HF staff commited on
Commit
8b7ec8f
0 Parent(s):

Duplicate from huggingchat/chat-ui

Browse files

Co-authored-by: Eliott Coyac <coyotte508@users.noreply.huggingface.co>

This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .env +63 -0
  2. .eslintignore +13 -0
  3. .eslintrc.cjs +43 -0
  4. .github/workflows/lint-and-test.yml +49 -0
  5. .gitignore +10 -0
  6. .npmrc +1 -0
  7. .prettierignore +13 -0
  8. .prettierrc +8 -0
  9. .vscode/settings.json +8 -0
  10. Dockerfile +16 -0
  11. LICENSE +203 -0
  12. PRIVACY.md +38 -0
  13. README.md +88 -0
  14. package-lock.json +0 -0
  15. package.json +57 -0
  16. postcss.config.js +6 -0
  17. src/app.d.ts +20 -0
  18. src/app.html +74 -0
  19. src/hooks.server.ts +103 -0
  20. src/lib/actions/snapScrollToBottom.ts +54 -0
  21. src/lib/buildPrompt.ts +36 -0
  22. src/lib/components/AnnouncementBanner.svelte +15 -0
  23. src/lib/components/CodeBlock.svelte +28 -0
  24. src/lib/components/CopyToClipBoardBtn.svelte +50 -0
  25. src/lib/components/LoginModal.svelte +65 -0
  26. src/lib/components/MobileNav.svelte +62 -0
  27. src/lib/components/Modal.svelte +62 -0
  28. src/lib/components/ModelCardMetadata.svelte +48 -0
  29. src/lib/components/ModelsModal.svelte +80 -0
  30. src/lib/components/NavConversationItem.svelte +87 -0
  31. src/lib/components/NavMenu.svelte +90 -0
  32. src/lib/components/Portal.svelte +19 -0
  33. src/lib/components/ScrollToBottomBtn.svelte +46 -0
  34. src/lib/components/SettingsModal.svelte +107 -0
  35. src/lib/components/StopGeneratingBtn.svelte +17 -0
  36. src/lib/components/Switch.svelte +11 -0
  37. src/lib/components/Toast.svelte +19 -0
  38. src/lib/components/Tooltip.svelte +22 -0
  39. src/lib/components/chat/ChatInput.svelte +64 -0
  40. src/lib/components/chat/ChatIntroduction.svelte +95 -0
  41. src/lib/components/chat/ChatMessage.svelte +193 -0
  42. src/lib/components/chat/ChatMessages.svelte +65 -0
  43. src/lib/components/chat/ChatWindow.svelte +108 -0
  44. src/lib/components/icons/IconChevron.svelte +20 -0
  45. src/lib/components/icons/IconCopy.svelte +26 -0
  46. src/lib/components/icons/IconDazzled.svelte +36 -0
  47. src/lib/components/icons/IconLoading.svelte +31 -0
  48. src/lib/components/icons/Logo.svelte +25 -0
  49. src/lib/components/icons/LogoHuggingFaceBorderless.svelte +50 -0
  50. src/lib/constants/publicSepToken.ts +1 -0
.env ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use .env.local to change these variables
2
+ # DO NOT EDIT THIS FILE WITH SENSITIVE DATA
3
+
4
+ MONGODB_URL=#your mongodb URL here
5
+ MONGODB_DB_NAME=chat-ui
6
+ COOKIE_NAME=hf-chat
7
+ HF_ACCESS_TOKEN=#hf_<token> from from https://huggingface.co/settings/token
8
+
9
+ # Parameters to enable "Sign in with HF"
10
+ OPENID_CLIENT_ID=
11
+ OPENID_CLIENT_SECRET=
12
+ OPENID_PROVIDER_URL=https://huggingface.co
13
+
14
+ # 'name', 'userMessageToken', 'assistantMessageToken' are required
15
+ MODELS=`[
16
+ {
17
+ "name": "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5",
18
+ "datasetName": "OpenAssistant/oasst1",
19
+ "description": "A good alternative to ChatGPT",
20
+ "websiteUrl": "https://open-assistant.io",
21
+ "userMessageToken": "<|prompter|>",
22
+ "assistantMessageToken": "<|assistant|>",
23
+ "messageEndToken": "</s>",
24
+ "preprompt": "Below are a series of dialogues between various people and an AI assistant. The AI tries to be helpful, polite, honest, sophisticated, emotionally aware, and humble-but-knowledgeable. The assistant is happy to help with almost anything, and will do its best to understand exactly what is needed. It also tries to avoid giving false or misleading information, and it caveats when it isn't entirely sure about the right answer. That said, the assistant is practical and really does its best, and doesn't let caution get too much in the way of being useful.\n-----\n",
25
+ "promptExamples": [
26
+ {
27
+ "title": "Write an email from bullet list",
28
+ "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)"
29
+ }, {
30
+ "title": "Code a snake game",
31
+ "prompt": "Code a basic snake game in python, give explanations for each step."
32
+ }, {
33
+ "title": "Assist in a task",
34
+ "prompt": "How do I make a delicious lemon cheesecake?"
35
+ }
36
+ ],
37
+ "parameters": {
38
+ "temperature": 0.9,
39
+ "top_p": 0.95,
40
+ "repetition_penalty": 1.2,
41
+ "top_k": 50,
42
+ "truncate": 1000,
43
+ "max_new_tokens": 1024
44
+ }
45
+ }
46
+ ]`
47
+ OLD_MODELS=`[]`# any removed models, `{ name: string, displayName?: string, id?: string }`
48
+
49
+ PUBLIC_ORIGIN=#https://huggingface.co
50
+ PUBLIC_SHARE_PREFIX=#https://hf.co/chat
51
+ PUBLIC_GOOGLE_ANALYTICS_ID=#G-XXXXXXXX / Leave empty to disable
52
+ PUBLIC_DEPRECATED_GOOGLE_ANALYTICS_ID=#UA-XXXXXXXX-X / Leave empty to disable
53
+ PUBLIC_ANNOUNCEMENT_BANNERS=`[
54
+ {
55
+ "title": "Chat UI is now open sourced on GitHub",
56
+ "linkTitle": "GitHub repo",
57
+ "linkHref": "https://github.com/huggingface/chat-ui"
58
+ }
59
+ ]`
60
+
61
+ PARQUET_EXPORT_DATASET=
62
+ PARQUET_EXPORT_HF_TOKEN=
63
+ PARQUET_EXPORT_SECRET=
.eslintignore ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .DS_Store
2
+ node_modules
3
+ /build
4
+ /.svelte-kit
5
+ /package
6
+ .env
7
+ .env.*
8
+ !.env.example
9
+
10
+ # Ignore files for PNPM, NPM and YARN
11
+ pnpm-lock.yaml
12
+ package-lock.json
13
+ yarn.lock
.eslintrc.cjs ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module.exports = {
2
+ root: true,
3
+ parser: "@typescript-eslint/parser",
4
+ extends: [
5
+ "eslint:recommended",
6
+ "plugin:@typescript-eslint/recommended",
7
+ "plugin:svelte/recommended",
8
+ "prettier",
9
+ ],
10
+ plugins: ["@typescript-eslint"],
11
+ ignorePatterns: ["*.cjs"],
12
+ overrides: [
13
+ {
14
+ files: ["*.svelte"],
15
+ parser: "svelte-eslint-parser",
16
+ parserOptions: {
17
+ parser: "@typescript-eslint/parser",
18
+ },
19
+ },
20
+ ],
21
+ parserOptions: {
22
+ sourceType: "module",
23
+ ecmaVersion: 2020,
24
+ extraFileExtensions: [".svelte"],
25
+ },
26
+ rules: {
27
+ "no-shadow": ["error"],
28
+ "@typescript-eslint/no-explicit-any": "error",
29
+ "@typescript-eslint/no-non-null-assertion": "error",
30
+ "@typescript-eslint/no-unused-vars": [
31
+ // prevent variables with a _ prefix from being marked as unused
32
+ "error",
33
+ {
34
+ argsIgnorePattern: "^_",
35
+ },
36
+ ],
37
+ },
38
+ env: {
39
+ browser: true,
40
+ es2017: true,
41
+ node: true,
42
+ },
43
+ };
.github/workflows/lint-and-test.yml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Lint and test
2
+ on:
3
+ pull_request:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ lint:
10
+ runs-on: ubuntu-latest
11
+ timeout-minutes: 10
12
+
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+
16
+ - uses: actions/setup-node@v3
17
+ with:
18
+ node-version: "18"
19
+ cache: "npm"
20
+ - run: |
21
+ npm install ci
22
+ - name: "Checking lint/format errors"
23
+ run: |
24
+ npm run lint
25
+ - name: "Checking type errors"
26
+ run: |
27
+ npm run check
28
+ test:
29
+ runs-on: ubuntu-latest
30
+ timeout-minutes: 10
31
+
32
+ services:
33
+ mongodb:
34
+ image: mongo:6.0.5
35
+ ports:
36
+ - 27017:27017
37
+
38
+ steps:
39
+ - uses: actions/checkout@v3
40
+
41
+ - uses: actions/setup-node@v3
42
+ with:
43
+ node-version: "18"
44
+ cache: "npm"
45
+ - run: |
46
+ npm ci
47
+ - name: "Tests"
48
+ run: |
49
+ npm run test
.gitignore ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ .DS_Store
2
+ node_modules
3
+ /build
4
+ /.svelte-kit
5
+ /package
6
+ .env
7
+ .env.*
8
+ !.env.example
9
+ vite.config.js.timestamp-*
10
+ vite.config.ts.timestamp-*
.npmrc ADDED
@@ -0,0 +1 @@
 
 
1
+ engine-strict=true
.prettierignore ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .DS_Store
2
+ node_modules
3
+ /build
4
+ /.svelte-kit
5
+ /package
6
+ .env
7
+ .env.*
8
+ !.env.example
9
+
10
+ # Ignore files for PNPM, NPM and YARN
11
+ pnpm-lock.yaml
12
+ package-lock.json
13
+ yarn.lock
.prettierrc ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "useTabs": true,
3
+ "trailingComma": "es5",
4
+ "printWidth": 100,
5
+ "plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
6
+ "pluginSearchDirs": ["."],
7
+ "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
8
+ }
.vscode/settings.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "editor.formatOnSave": true,
3
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
4
+ "editor.codeActionsOnSave": {
5
+ "source.fixAll": true
6
+ },
7
+ "eslint.validate": ["javascript", "svelte"]
8
+ }
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM node:19
5
+
6
+ RUN npm install -g pm2
7
+
8
+ WORKDIR /app
9
+
10
+ COPY --link --chown=1000 . .
11
+
12
+ RUN npm i
13
+
14
+ RUN --mount=type=secret,id=DOTENV_LOCAL,dst=.env.local npm run build
15
+
16
+ CMD pm2 start build/index.js -i $CPU_CORES --no-daemon
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,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Privacy
2
+
3
+ > Last updated: May 15, 2023
4
+
5
+ Starting with `v0.2` of HuggingChat, users are authenticated through their HF user account.
6
+
7
+ By default, your conversations are shared with the model's authors (for the `v0.2` model, to <a target="_blank" href="https://open-assistant.io/dashboard">Open Assistant</a>) to improve their training data and model over time. Model authors are the custodians of the data collected by their model, even if it's hosted on our platform.
8
+
9
+ If you disable data sharing in your settings, your conversations will not be used for any downstream usage (including for research or model training purposes), and they 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 privacy@huggingface.co.
12
+
13
+ ## About available LLMs
14
+
15
+ The goal of this app is to showcase that it is now (May 2023) possible to build an open source alternative to ChatGPT. 💪
16
+
17
+ For now, it's running OpenAssistant's [latest LLaMA based model](https://huggingface.co/OpenAssistant/oasst-sft-6-llama-30b-xor) (which is one of the current best open source chat models), but the plan in the longer-term is to expose all good-quality chat models from the Hub.
18
+
19
+ We are not affiliated with Open Assistant, but if you want to contribute to the training data for the next generation of open models, please consider contributing to https://open-assistant.io/ ❤️
20
+
21
+ ## Technical details
22
+
23
+ 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).
24
+
25
+ **Further development takes place on the [huggingface/chat-ui GitHub repo](https://github.com/huggingface/chat-ui).**
26
+
27
+ The inference backend is running the optimized [text-generation-inference](https://github.com/huggingface/text-generation-inference) on HuggingFace's Inference API infrastructure.
28
+
29
+ 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)
30
+
31
+ We welcome any feedback on this app: please participate to the public discussion at https://huggingface.co/spaces/huggingchat/chat-ui/discussions
32
+
33
+ <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>
34
+
35
+ ## Coming soon
36
+
37
+ - User setting to share conversations with model authors (done ✅)
38
+ - LLM watermarking
README.md ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: chat-ui
3
+ emoji: 🔥
4
+ colorFrom: purple
5
+ colorTo: purple
6
+ sdk: docker
7
+ pinned: false
8
+ license: apache-2.0
9
+ base_path: /chat
10
+ app_port: 3000
11
+ duplicated_from: huggingchat/chat-ui
12
+ ---
13
+
14
+ # Chat UI
15
+
16
+ ![Chat UI repository thumbnail](https://huggingface.co/datasets/huggingface/documentation-images/raw/f038917dd40d711a72d654ab1abfc03ae9f177e6/chat-ui-repo-thumbnail.svg)
17
+
18
+ A chat interface using open source models, eg OpenAssistant. It is a SvelteKit app and it powers the [HuggingChat app on hf.co/chat](https://huggingface.co/chat).
19
+
20
+ ## Launch
21
+
22
+ ```bash
23
+ npm install
24
+ npm run dev
25
+ ```
26
+
27
+ ## Environment
28
+
29
+ Default configuration is in `.env`. Put custom config and secrets in `.env.local`, it will override the values in `.env`.
30
+
31
+ Check out [.env](./.env) to see what needs to be set.
32
+
33
+ Basically you need to create a `.env.local` with the following contents:
34
+
35
+ ```
36
+ MONGODB_URL=<url to mongo, for example a free MongoDB Atlas sandbox instance>
37
+ HF_ACCESS_TOKEN=<your HF access token from https://huggingface.co/settings/tokens>
38
+ ```
39
+
40
+ ## Duplicating to a Space
41
+
42
+ Create a `DOTENV_LOCAL` secret to your space with the following contents:
43
+
44
+ ```
45
+ MONGODB_URL=<url to mongo, for example a free MongoDB Atlas sandbox instance>
46
+ HF_ACCESS_TOKEN=<your HF access token from https://huggingface.co/settings/tokens>
47
+ ```
48
+
49
+ Where the contents in `<...>` are replaced by the MongoDB URL and your [HF Access Token](https://huggingface.co/settings/tokens).
50
+
51
+ ## Running Local Inference
52
+
53
+ Both the example above use the HF Inference API or HF Endpoints API.
54
+
55
+ If you want to run the model locally, you need to run this inference server locally: https://github.com/huggingface/text-generation-inference
56
+
57
+ And add this to your `.env.local`, feel free to adjust/remove the parameters and the preprompt:
58
+
59
+ ```
60
+ MODELS=`[{
61
+ "name": "...",
62
+ "endpoints": [{"url": "http://127.0.0.1:8080/generate_stream"}],
63
+ "userMessageToken": "<|prompter|>",
64
+ "assistantMessageToken": "<|assistant|>",
65
+ "messageEndToken": "</s>",
66
+ "preprompt": "Below are a series of dialogues between various people and an AI assistant. The AI tries to be helpful, polite, honest, sophisticated, emotionally aware, and humble-but-knowledgeable. The assistant is happy to help with almost anything, and will do its best to understand exactly what is needed. It also tries to avoid giving false or misleading information, and it caveats when it isn't entirely sure about the right answer. That said, the assistant is practical and really does its best, and doesn't let caution get too much in the way of being useful.\n-----\n",
67
+ "parameters": {
68
+ "temperature": 0.9,
69
+ "top_p": 0.95,
70
+ "repetition_penalty": 1.2,
71
+ "top_k": 50,
72
+ "truncate": 1000,
73
+ "max_new_tokens": 1000
74
+ }
75
+ }]`
76
+ ```
77
+
78
+ ## Building
79
+
80
+ To create a production version of your app:
81
+
82
+ ```bash
83
+ npm run build
84
+ ```
85
+
86
+ You can preview the production build with `npm run preview`.
87
+
88
+ > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
package-lock.json ADDED
The diff for this file is too large to render. See raw diff
 
package.json ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "chat-ui",
3
+ "version": "0.2.0",
4
+ "private": true,
5
+ "packageManager": "npm@9.5.0",
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 --plugin-search-dir . --check . && eslint .",
13
+ "format": "prettier --plugin-search-dir . --write .",
14
+ "test": "MONGODB_URL=mongodb://127.0.0.1:27017/ vitest"
15
+ },
16
+ "devDependencies": {
17
+ "@iconify-json/carbon": "^1.1.16",
18
+ "@sveltejs/adapter-node": "^1.2.4",
19
+ "@sveltejs/kit": "^1.15.10",
20
+ "@tailwindcss/typography": "^0.5.9",
21
+ "@types/marked": "^4.0.8",
22
+ "@types/parquetjs": "^0.10.3",
23
+ "@typescript-eslint/eslint-plugin": "^5.45.0",
24
+ "@typescript-eslint/parser": "^5.45.0",
25
+ "eslint": "^8.28.0",
26
+ "eslint-config-prettier": "^8.5.0",
27
+ "eslint-plugin-svelte": "^2.27.3",
28
+ "prettier": "^2.8.0",
29
+ "prettier-plugin-svelte": "^2.8.1",
30
+ "prettier-plugin-tailwindcss": "^0.2.7",
31
+ "svelte": "^3.58.0",
32
+ "svelte-check": "^3.2.0",
33
+ "tslib": "^2.4.1",
34
+ "typescript": "^4.9.3",
35
+ "unplugin-icons": "^0.16.1",
36
+ "vite": "^4.0.0",
37
+ "vitest": "^0.31.0"
38
+ },
39
+ "type": "module",
40
+ "dependencies": {
41
+ "@huggingface/hub": "^0.5.1",
42
+ "@huggingface/inference": "^2.2.0",
43
+ "autoprefixer": "^10.4.14",
44
+ "date-fns": "^2.29.3",
45
+ "dotenv": "^16.0.3",
46
+ "highlight.js": "^11.7.0",
47
+ "marked": "^4.3.0",
48
+ "mongodb": "^5.3.0",
49
+ "nanoid": "^4.0.2",
50
+ "openid-client": "^5.4.2",
51
+ "parquetjs": "^0.11.2",
52
+ "postcss": "^8.4.21",
53
+ "tailwind-scrollbar": "^3.0.0",
54
+ "tailwindcss": "^3.3.1",
55
+ "zod": "^3.21.4"
56
+ }
57
+ }
postcss.config.js ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ export default {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {},
5
+ },
6
+ };
src/app.d.ts ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// <reference types="@sveltejs/kit" />
2
+ /// <reference types="unplugin-icons/types/svelte" />
3
+
4
+ import type { User } from "$lib/types/User";
5
+
6
+ // See https://kit.svelte.dev/docs/types#app
7
+ // for information about these interfaces
8
+ declare global {
9
+ namespace App {
10
+ // interface Error {}
11
+ interface Locals {
12
+ sessionId: string;
13
+ user?: User;
14
+ }
15
+ // interface PageData {}
16
+ // interface Platform {}
17
+ }
18
+ }
19
+
20
+ export {};
src/app.html ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en" class="h-full">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <link rel="icon" href="%sveltekit.assets%/favicon.svg" type="image/svg+xml" />
6
+ <link rel="icon" href="%sveltekit.assets%/favicon.png" type="image/png" />
7
+ <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
8
+ <title>HuggingChat</title>
9
+ <script>
10
+ if (
11
+ localStorage.theme === "dark" ||
12
+ (!("theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches)
13
+ ) {
14
+ document.documentElement.classList.add("dark");
15
+ }
16
+
17
+ // For some reason, Sveltekit doesn't let us load env variables from .env here, so we load it from hooks.server.ts
18
+ window.gaId = "%gaId%";
19
+ window.gaIdDeprecated = "%gaIdDeprecated%";
20
+ </script>
21
+ %sveltekit.head%
22
+ </head>
23
+ <body data-sveltekit-preload-data="hover" class="h-full dark:bg-gray-900">
24
+ <div id="app" class="contents h-full">%sveltekit.body%</div>
25
+
26
+ <!-- Google Tag Manager -->
27
+ <script>
28
+ if (window.gaId) {
29
+ const script = document.createElement("script");
30
+ script.src = "https://www.googletagmanager.com/gtag/js?id=" + window.gaId;
31
+ script.async = true;
32
+ document.head.appendChild(script);
33
+
34
+ window.dataLayer = window.dataLayer || [];
35
+ function gtag() {
36
+ dataLayer.push(arguments);
37
+ }
38
+ gtag("js", new Date());
39
+ /// ^ See https://developers.google.com/tag-platform/gtagjs/install
40
+ gtag("config", window.gaId);
41
+ gtag("consent", "default", { ad_storage: "denied", analytics_storage: "denied" });
42
+ /// ^ See https://developers.google.com/tag-platform/gtagjs/reference#consent
43
+ /// TODO: ask the user for their consent and update this with gtag('consent', 'update')
44
+ }
45
+ </script>
46
+
47
+ <!-- Google Analytics v3 (deprecated on 1 July 2023) -->
48
+ <script>
49
+ if (window.gaIdDeprecated) {
50
+ (function (i, s, o, g, r, a, m) {
51
+ i["GoogleAnalyticsObject"] = r;
52
+ (i[r] =
53
+ i[r] ||
54
+ function () {
55
+ (i[r].q = i[r].q || []).push(arguments);
56
+ }),
57
+ (i[r].l = 1 * new Date());
58
+ (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
59
+ a.async = 1;
60
+ a.src = g;
61
+ m.parentNode.insertBefore(a, m);
62
+ })(
63
+ window,
64
+ document,
65
+ "script",
66
+ "https://www.google-analytics.com/analytics.js",
67
+ "ganalytics"
68
+ );
69
+ ganalytics("create", window.gaIdDeprecated, "auto");
70
+ ganalytics("send", "pageview");
71
+ }
72
+ </script>
73
+ </body>
74
+ </html>
src/hooks.server.ts ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { COOKIE_NAME } from "$env/static/private";
2
+ import type { Handle } from "@sveltejs/kit";
3
+ import {
4
+ PUBLIC_GOOGLE_ANALYTICS_ID,
5
+ PUBLIC_DEPRECATED_GOOGLE_ANALYTICS_ID,
6
+ PUBLIC_ORIGIN,
7
+ } from "$env/static/public";
8
+ import { collections } from "$lib/server/database";
9
+ import { base } from "$app/paths";
10
+ import { refreshSessionCookie, requiresUser } from "$lib/server/auth";
11
+ import { ERROR_MESSAGES } from "$lib/stores/errors";
12
+
13
+ export const handle: Handle = async ({ event, resolve }) => {
14
+ const token = event.cookies.get(COOKIE_NAME);
15
+
16
+ event.locals.sessionId = token || crypto.randomUUID();
17
+
18
+ const user = await collections.users.findOne({ sessionId: event.locals.sessionId });
19
+
20
+ if (user) {
21
+ event.locals.user = user;
22
+ }
23
+
24
+ function errorResponse(status: number, message: string) {
25
+ const sendJson =
26
+ event.request.headers.get("accept")?.includes("application/json") ||
27
+ event.request.headers.get("content-type")?.includes("application/json");
28
+ return new Response(sendJson ? JSON.stringify({ error: message }) : message, {
29
+ status,
30
+ headers: {
31
+ "content-type": sendJson ? "application/json" : "text/plain",
32
+ },
33
+ });
34
+ }
35
+
36
+ // CSRF protection
37
+ const requestContentType = event.request.headers.get("content-type")?.split(";")[0] ?? "";
38
+ /** https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-enctype */
39
+ const nativeFormContentTypes = [
40
+ "multipart/form-data",
41
+ "application/x-www-form-urlencoded",
42
+ "text/plain",
43
+ ];
44
+ if (event.request.method === "POST" && nativeFormContentTypes.includes(requestContentType)) {
45
+ const referer = event.request.headers.get("referer");
46
+
47
+ if (!referer) {
48
+ return errorResponse(403, "Non-JSON form requests need to have a referer");
49
+ }
50
+
51
+ const validOrigins = [
52
+ new URL(event.request.url).origin,
53
+ ...(PUBLIC_ORIGIN ? [new URL(PUBLIC_ORIGIN).origin] : []),
54
+ ];
55
+
56
+ if (!validOrigins.includes(new URL(referer).origin)) {
57
+ return errorResponse(403, "Invalid referer for POST request");
58
+ }
59
+ }
60
+
61
+ if (
62
+ !event.url.pathname.startsWith(`${base}/login`) &&
63
+ !event.url.pathname.startsWith(`${base}/admin`) &&
64
+ !["GET", "OPTIONS", "HEAD"].includes(event.request.method)
65
+ ) {
66
+ if (!user && requiresUser) {
67
+ return errorResponse(401, ERROR_MESSAGES.authOnly);
68
+ }
69
+
70
+ // if login is not required and the call is not from /settings, we check if the user has accepted the ethics modal first.
71
+ // If login is required, `ethicsModalAcceptedAt` is already true at this point, so do not pass this condition. This saves a DB call.
72
+ if (!requiresUser && !event.url.pathname.startsWith(`${base}/settings`)) {
73
+ const hasAcceptedEthicsModal = await collections.settings.countDocuments({
74
+ sessionId: event.locals.sessionId,
75
+ ethicsModalAcceptedAt: { $exists: true },
76
+ });
77
+
78
+ if (!hasAcceptedEthicsModal) {
79
+ return errorResponse(405, "You need to accept the welcome modal first");
80
+ }
81
+ }
82
+ }
83
+
84
+ refreshSessionCookie(event.cookies, event.locals.sessionId);
85
+
86
+ let replaced = false;
87
+
88
+ const response = await resolve(event, {
89
+ transformPageChunk: (chunk) => {
90
+ // For some reason, Sveltekit doesn't let us load env variables from .env in the app.html template
91
+ if (replaced || !chunk.html.includes("%gaId%") || !chunk.html.includes("%gaIdDeprecated%")) {
92
+ return chunk.html;
93
+ }
94
+ replaced = true;
95
+
96
+ return chunk.html
97
+ .replace("%gaId%", PUBLIC_GOOGLE_ANALYTICS_ID)
98
+ .replace("%gaIdDeprecated%", PUBLIC_DEPRECATED_GOOGLE_ANALYTICS_ID);
99
+ },
100
+ });
101
+
102
+ return response;
103
+ };
src/lib/actions/snapScrollToBottom.ts ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { navigating } from "$app/stores";
2
+ import { tick } from "svelte";
3
+ import { get } from "svelte/store";
4
+
5
+ const detachedOffset = 10;
6
+
7
+ /**
8
+ * @param node element to snap scroll to bottom
9
+ * @param dependency pass in a dependency to update scroll on changes.
10
+ */
11
+ export const snapScrollToBottom = (node: HTMLElement, dependency: unknown) => {
12
+ let prevScrollValue = node.scrollTop;
13
+ let isDetached = false;
14
+
15
+ const handleScroll = () => {
16
+ // if user scrolled up, we detach
17
+ if (node.scrollTop < prevScrollValue) {
18
+ isDetached = true;
19
+ }
20
+
21
+ // if user scrolled back to within 10px of bottom, we reattach
22
+ if (node.scrollTop - (node.scrollHeight - node.clientHeight) >= -detachedOffset) {
23
+ isDetached = false;
24
+ }
25
+
26
+ prevScrollValue = node.scrollTop;
27
+ };
28
+
29
+ const updateScroll = async (_options: { force?: boolean } = {}) => {
30
+ const defaultOptions = { force: false };
31
+ const options = { ...defaultOptions, ..._options };
32
+ const { force } = options;
33
+
34
+ if (!force && isDetached && !get(navigating)) return;
35
+
36
+ // wait for next tick to ensure that the DOM is updated
37
+ await tick();
38
+
39
+ node.scrollTo({ top: node.scrollHeight });
40
+ };
41
+
42
+ node.addEventListener("scroll", handleScroll);
43
+
44
+ if (dependency) {
45
+ updateScroll({ force: true });
46
+ }
47
+
48
+ return {
49
+ update: updateScroll,
50
+ destroy: () => {
51
+ node.removeEventListener("scroll", handleScroll);
52
+ },
53
+ };
54
+ };
src/lib/buildPrompt.ts ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { BackendModel } from "./server/models";
2
+ import type { Message } from "./types/Message";
3
+
4
+ /**
5
+ * Convert [{user: "assistant", content: "hi"}, {user: "user", content: "hello"}] to:
6
+ *
7
+ * <|assistant|>hi<|endoftext|><|prompter|>hello<|endoftext|><|assistant|>
8
+ */
9
+ export function buildPrompt(
10
+ messages: Pick<Message, "from" | "content">[],
11
+ model: BackendModel
12
+ ): string {
13
+ const prompt =
14
+ messages
15
+ .map(
16
+ (m) =>
17
+ (m.from === "user"
18
+ ? model.userMessageToken + m.content
19
+ : model.assistantMessageToken + m.content) +
20
+ (model.messageEndToken
21
+ ? m.content.endsWith(model.messageEndToken)
22
+ ? ""
23
+ : model.messageEndToken
24
+ : "")
25
+ )
26
+ .join("") + model.assistantMessageToken;
27
+
28
+ // Not super precise, but it's truncated in the model's backend anyway
29
+ return (
30
+ model.preprompt +
31
+ prompt
32
+ .split(" ")
33
+ .slice(-(model.parameters?.truncate ?? 0))
34
+ .join(" ")
35
+ );
36
+ }
src/lib/components/AnnouncementBanner.svelte ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let title = "";
3
+ export let classNames = "";
4
+ </script>
5
+
6
+ <div class="flex items-center rounded-xl bg-gray-100 p-1 text-sm dark:bg-gray-800 {classNames}">
7
+ <span
8
+ class="mr-2 inline-flex items-center rounded-lg bg-gradient-to-br from-yellow-300 px-2 py-1 text-xxs font-medium uppercase leading-3 text-yellow-700 dark:from-[#373010] dark:text-yellow-400"
9
+ >New</span
10
+ >
11
+ {title}
12
+ <div class="ml-auto shrink-0">
13
+ <slot />
14
+ </div>
15
+ </div>
src/lib/components/CodeBlock.svelte ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { afterUpdate } from "svelte";
3
+ import CopyToClipBoardBtn from "./CopyToClipBoardBtn.svelte";
4
+
5
+ export let code = "";
6
+ export let lang = "";
7
+
8
+ $: highlightedCode = "";
9
+
10
+ afterUpdate(async () => {
11
+ const { default: hljs } = await import("highlight.js");
12
+ const language = hljs.getLanguage(lang);
13
+
14
+ highlightedCode = hljs.highlightAuto(code, language?.aliases).value;
15
+ });
16
+ </script>
17
+
18
+ <div class="group relative my-4 rounded-lg">
19
+ <!-- eslint-disable svelte/no-at-html-tags -->
20
+ <pre
21
+ class="scrollbar-custom overflow-auto px-5 scrollbar-thumb-gray-500 hover:scrollbar-thumb-gray-400 dark:scrollbar-thumb-white/10 dark:hover:scrollbar-thumb-white/20"><code
22
+ class="language-{lang}">{@html highlightedCode || code.replaceAll("<", "&lt;")}</code
23
+ ></pre>
24
+ <CopyToClipBoardBtn
25
+ classNames="absolute top-2 right-2 invisible opacity-0 group-hover:visible group-hover:opacity-100"
26
+ value={code}
27
+ />
28
+ </div>
src/lib/components/CopyToClipBoardBtn.svelte ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { onDestroy } from "svelte";
3
+
4
+ import IconCopy from "./icons/IconCopy.svelte";
5
+ import Tooltip from "./Tooltip.svelte";
6
+
7
+ export let classNames = "";
8
+ export let value: string;
9
+
10
+ let isSuccess = false;
11
+ let timeout: ReturnType<typeof setTimeout>;
12
+
13
+ const handleClick = async () => {
14
+ // writeText() can be unavailable or fail in some cases (iframe, etc) so we try/catch
15
+ try {
16
+ await navigator.clipboard.writeText(value);
17
+
18
+ isSuccess = true;
19
+ if (timeout) {
20
+ clearTimeout(timeout);
21
+ }
22
+ timeout = setTimeout(() => {
23
+ isSuccess = false;
24
+ }, 1000);
25
+ } catch (err) {
26
+ console.error(err);
27
+ }
28
+ };
29
+
30
+ onDestroy(() => {
31
+ if (timeout) {
32
+ clearTimeout(timeout);
33
+ }
34
+ });
35
+ </script>
36
+
37
+ <button
38
+ class="btn rounded-lg border border-gray-200 px-2 py-2 text-sm shadow-sm transition-all hover:border-gray-300 active:shadow-inner dark:border-gray-600 dark:hover:border-gray-400 {classNames}
39
+ {!isSuccess && 'text-gray-200 dark:text-gray-200'}
40
+ {isSuccess && 'text-green-500'}
41
+ "
42
+ title={"Copy to clipboard"}
43
+ type="button"
44
+ on:click={handleClick}
45
+ >
46
+ <span class="relative">
47
+ <IconCopy />
48
+ <Tooltip classNames={isSuccess ? "opacity-100" : "opacity-0"} />
49
+ </span>
50
+ </button>
src/lib/components/LoginModal.svelte ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { browser } from "$app/environment";
3
+ import { base } from "$app/paths";
4
+ import { page } from "$app/stores";
5
+ import { PUBLIC_VERSION } from "$env/static/public";
6
+ import Logo from "$lib/components/icons/Logo.svelte";
7
+ import LogoHuggingFaceBorderless from "$lib/components/icons/LogoHuggingFaceBorderless.svelte";
8
+ import Modal from "$lib/components/Modal.svelte";
9
+ import type { LayoutData } from "../../routes/$types";
10
+
11
+ export let settings: LayoutData["settings"];
12
+
13
+ const isIframe = browser && window.self !== window.parent;
14
+ </script>
15
+
16
+ <Modal>
17
+ <div
18
+ class="flex w-full flex-col items-center gap-6 bg-gradient-to-t from-yellow-500/40 via-yellow-500/10 to-yellow-500/0 px-4 pb-10 pt-9 text-center"
19
+ >
20
+ <h2 class="flex items-center text-2xl font-semibold text-gray-800">
21
+ <Logo classNames="text-3xl mr-1.5" />HuggingChat
22
+ <div
23
+ class="ml-3 flex h-6 items-center rounded-lg border border-gray-100 bg-gray-50 px-2 text-base text-gray-400"
24
+ >
25
+ v{PUBLIC_VERSION}
26
+ </div>
27
+ </h2>
28
+ <p class="px-4 text-lg font-semibold leading-snug text-gray-800 sm:px-12">
29
+ This application is for demonstration purposes only.
30
+ </p>
31
+ <p class="text-base text-gray-800">
32
+ AI is an area of active research with known problems such as biased generation and
33
+ misinformation. Do not use this application for high-stakes decisions or advice.
34
+ </p>
35
+ <p class="px-2 text-sm text-gray-500">
36
+ Your conversations will be shared with model authors unless you disable it from your settings.
37
+ </p>
38
+ <form
39
+ action="{base}/{$page.data.requiresLogin ? 'login' : 'settings'}"
40
+ target={isIframe ? "_blank" : ""}
41
+ method="POST"
42
+ >
43
+ {#if $page.data.requiresLogin}
44
+ <button
45
+ type="submit"
46
+ class="mt-2 flex items-center whitespace-nowrap rounded-full bg-black px-5 py-2 text-lg font-semibold text-gray-100 transition-colors hover:bg-yellow-500"
47
+ >
48
+ Sign in with <LogoHuggingFaceBorderless classNames="text-xl mr-1 ml-1.5" /> Hugging Face
49
+ </button>
50
+ <p class="mt-2 px-2 text-sm text-gray-500">to start chatting right away</p>
51
+ {:else}
52
+ <input type="hidden" name="ethicsModalAccepted" value={true} />
53
+ {#each Object.entries(settings) as [key, val]}
54
+ <input type="hidden" name={key} value={val} />
55
+ {/each}
56
+ <button
57
+ type="submit"
58
+ class="mt-2 rounded-full bg-black px-5 py-2 text-lg font-semibold text-gray-100 transition-colors hover:bg-yellow-500"
59
+ >
60
+ Start chatting
61
+ </button>
62
+ {/if}
63
+ </form>
64
+ </div>
65
+ </Modal>
src/lib/components/MobileNav.svelte ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { navigating } from "$app/stores";
3
+ import { createEventDispatcher } from "svelte";
4
+ import { browser } from "$app/environment";
5
+ import { base } from "$app/paths";
6
+
7
+ import CarbonClose from "~icons/carbon/close";
8
+ import CarbonAdd from "~icons/carbon/add";
9
+ import CarbonTextAlignJustify from "~icons/carbon/text-align-justify";
10
+
11
+ export let isOpen = false;
12
+ export let title: string | undefined;
13
+
14
+ $: title = title || "New Chat";
15
+
16
+ let closeEl: HTMLButtonElement;
17
+ let openEl: HTMLButtonElement;
18
+
19
+ const dispatch = createEventDispatcher();
20
+
21
+ $: if ($navigating) {
22
+ dispatch("toggle", false);
23
+ }
24
+
25
+ $: if (isOpen && closeEl) {
26
+ closeEl.focus();
27
+ } else if (!isOpen && browser && document.activeElement === closeEl) {
28
+ openEl.focus();
29
+ }
30
+ </script>
31
+
32
+ <nav
33
+ class="flex h-12 items-center justify-between border-b bg-gray-50 px-4 dark:border-gray-800 dark:bg-gray-800/70 md:hidden"
34
+ >
35
+ <button
36
+ type="button"
37
+ class="-ml-3 flex h-9 w-9 shrink-0 items-center justify-center"
38
+ on:click={() => dispatch("toggle", true)}
39
+ aria-label="Open menu"
40
+ bind:this={openEl}><CarbonTextAlignJustify /></button
41
+ >
42
+ <span class="truncate px-4">{title}</span>
43
+ <a href={`${base}/`} class="-mr-3 flex h-9 w-9 shrink-0 items-center justify-center"
44
+ ><CarbonAdd /></a
45
+ >
46
+ </nav>
47
+ <nav
48
+ class="fixed inset-0 z-30 grid max-h-screen grid-cols-1 grid-rows-[auto,auto,1fr,auto] bg-white bg-gradient-to-l from-gray-50 dark:bg-gray-900 dark:from-gray-800/30 {isOpen
49
+ ? 'block'
50
+ : 'hidden'}"
51
+ >
52
+ <div class="flex h-12 items-center px-4">
53
+ <button
54
+ type="button"
55
+ class="-mr-3 ml-auto flex h-9 w-9 items-center justify-center"
56
+ on:click={() => dispatch("toggle", false)}
57
+ aria-label="Close menu"
58
+ bind:this={closeEl}><CarbonClose /></button
59
+ >
60
+ </div>
61
+ <slot />
62
+ </nav>
src/lib/components/Modal.svelte ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { createEventDispatcher, onDestroy, onMount } from "svelte";
3
+ import { cubicOut } from "svelte/easing";
4
+ import { fade } from "svelte/transition";
5
+ import Portal from "./Portal.svelte";
6
+ import { browser } from "$app/environment";
7
+
8
+ export let width = "max-w-sm";
9
+
10
+ let backdropEl: HTMLDivElement;
11
+ let modalEl: HTMLDivElement;
12
+
13
+ const dispatch = createEventDispatcher<{ close: void }>();
14
+
15
+ function handleKeydown(event: KeyboardEvent) {
16
+ // close on ESC
17
+ if (event.key === "Escape") {
18
+ event.preventDefault();
19
+ dispatch("close");
20
+ }
21
+ }
22
+
23
+ function handleBackdropClick(event: MouseEvent) {
24
+ if (event.target === backdropEl) {
25
+ dispatch("close");
26
+ }
27
+ }
28
+
29
+ onMount(() => {
30
+ document.getElementById("app")?.setAttribute("inert", "true");
31
+ modalEl.focus();
32
+ });
33
+
34
+ onDestroy(() => {
35
+ if (!browser) return;
36
+ // remove inert attribute if this is the last modal
37
+ if (document.querySelectorAll('[role="dialog"]:not(#app *)').length === 1) {
38
+ document.getElementById("app")?.removeAttribute("inert");
39
+ }
40
+ });
41
+ </script>
42
+
43
+ <Portal>
44
+ <div
45
+ role="presentation"
46
+ tabindex="-1"
47
+ bind:this={backdropEl}
48
+ on:click={handleBackdropClick}
49
+ transition:fade={{ easing: cubicOut, duration: 300 }}
50
+ class="fixed inset-0 z-40 flex items-center justify-center bg-black/80 p-8 backdrop-blur-sm dark:bg-black/50"
51
+ >
52
+ <div
53
+ role="dialog"
54
+ tabindex="-1"
55
+ bind:this={modalEl}
56
+ on:keydown={handleKeydown}
57
+ class="-mt-10 overflow-hidden rounded-2xl bg-white shadow-2xl outline-none md:-mt-20 {width}"
58
+ >
59
+ <slot />
60
+ </div>
61
+ </div>
62
+ </Portal>
src/lib/components/ModelCardMetadata.svelte ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import CarbonEarth from "~icons/carbon/earth";
3
+ import CarbonArrowUpRight from "~icons/carbon/arrow-up-right";
4
+ import type { Model } from "$lib/types/Model";
5
+
6
+ export let model: Pick<Model, "name" | "datasetName" | "websiteUrl">;
7
+
8
+ export let variant: "light" | "dark" = "light";
9
+ </script>
10
+
11
+ <div
12
+ class="flex items-center gap-5 rounded-xl bg-gray-100 px-3 py-2 text-sm
13
+ {variant === 'dark'
14
+ ? 'text-gray-600 dark:bg-gray-800 dark:text-gray-300'
15
+ : 'text-gray-800 dark:bg-gray-100 dark:text-gray-600'}"
16
+ >
17
+ <a
18
+ href="https://huggingface.co/{model.name}"
19
+ target="_blank"
20
+ rel="noreferrer"
21
+ class="flex items-center hover:underline"
22
+ ><CarbonArrowUpRight class="mr-1.5 shrink-0 text-xs text-gray-400" />
23
+ Model
24
+ <div class="max-sm:hidden">&nbsp;page</div></a
25
+ >
26
+ {#if model.datasetName}
27
+ <a
28
+ href="https://huggingface.co/datasets/{model.datasetName}"
29
+ target="_blank"
30
+ rel="noreferrer"
31
+ class="flex items-center hover:underline"
32
+ ><CarbonArrowUpRight class="mr-1.5 shrink-0 text-xs text-gray-400" />
33
+ Dataset
34
+ <div class="max-sm:hidden">&nbsp;page</div></a
35
+ >
36
+ {/if}
37
+ {#if model.websiteUrl}
38
+ <a
39
+ href={model.websiteUrl}
40
+ target="_blank"
41
+ class="ml-auto flex items-center hover:underline"
42
+ rel="noreferrer"
43
+ >
44
+ <CarbonEarth class="mr-1.5 shrink-0 text-xs text-gray-400" />
45
+ Website
46
+ </a>
47
+ {/if}
48
+ </div>
src/lib/components/ModelsModal.svelte ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { createEventDispatcher } from "svelte";
3
+
4
+ import Modal from "$lib/components/Modal.svelte";
5
+ import CarbonClose from "~icons/carbon/close";
6
+ import CarbonCheckmark from "~icons/carbon/checkmark-filled";
7
+ import ModelCardMetadata from "./ModelCardMetadata.svelte";
8
+ import type { Model } from "$lib/types/Model";
9
+ import type { LayoutData } from "../../routes/$types";
10
+ import { enhance } from "$app/forms";
11
+ import { base } from "$app/paths";
12
+
13
+ export let settings: LayoutData["settings"];
14
+ export let models: Array<Model>;
15
+
16
+ let selectedModelId = settings.activeModel;
17
+
18
+ const dispatch = createEventDispatcher<{ close: void }>();
19
+ </script>
20
+
21
+ <Modal width="max-w-lg" on:close>
22
+ <form
23
+ action="{base}/settings"
24
+ method="post"
25
+ use:enhance={() => {
26
+ dispatch("close");
27
+ }}
28
+ class="flex w-full flex-col gap-5 p-6"
29
+ >
30
+ {#each Object.entries(settings).filter(([k]) => k !== "activeModel") as [key, val]}
31
+ <input type="hidden" name={key} value={val} />
32
+ {/each}
33
+ <div class="flex items-start justify-between text-xl font-semibold text-gray-800">
34
+ <h2>Models</h2>
35
+ <button type="button" class="group" on:click={() => dispatch("close")}>
36
+ <CarbonClose class="text-gray-900 group-hover:text-gray-500" />
37
+ </button>
38
+ </div>
39
+
40
+ <div class="space-y-4">
41
+ {#each models as model}
42
+ <div
43
+ class="rounded-xl border border-gray-100 {model.id === selectedModelId
44
+ ? 'bg-gradient-to-r from-yellow-200/40 via-yellow-500/10'
45
+ : ''}"
46
+ >
47
+ <label class="group flex cursor-pointer p-3" on:change aria-label={model.displayName}>
48
+ <input
49
+ type="radio"
50
+ class="sr-only"
51
+ name="activeModel"
52
+ value={model.id}
53
+ bind:group={selectedModelId}
54
+ />
55
+ <span>
56
+ <span class="text-md block font-semibold leading-tight text-gray-800"
57
+ >{model.displayName}</span
58
+ >
59
+ {#if model.description}
60
+ <span class="text-xs text-[#9FA8B5]">{model.description}</span>
61
+ {/if}
62
+ </span>
63
+ <CarbonCheckmark
64
+ class="-mr-1 -mt-1 ml-auto shrink-0 text-xl {model.id === selectedModelId
65
+ ? 'text-yellow-400'
66
+ : 'text-transparent group-hover:text-gray-200'}"
67
+ />
68
+ </label>
69
+ <ModelCardMetadata {model} />
70
+ </div>
71
+ {/each}
72
+ </div>
73
+ <button
74
+ type="submit"
75
+ class="mt-2 rounded-full bg-black px-5 py-2 text-lg font-semibold text-gray-100 ring-gray-400 ring-offset-1 transition-colors hover:ring"
76
+ >
77
+ Apply
78
+ </button>
79
+ </form>
80
+ </Modal>
src/lib/components/NavConversationItem.svelte ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { base } from "$app/paths";
3
+ import { page } from "$app/stores";
4
+ import { createEventDispatcher } from "svelte";
5
+
6
+ import CarbonCheckmark from "~icons/carbon/checkmark";
7
+ import CarbonTrashCan from "~icons/carbon/trash-can";
8
+ import CarbonClose from "~icons/carbon/close";
9
+ import CarbonEdit from "~icons/carbon/edit";
10
+
11
+ export let conv: { id: string; title: string };
12
+
13
+ let confirmDelete = false;
14
+
15
+ const dispatch = createEventDispatcher<{
16
+ deleteConversation: string;
17
+ editConversationTitle: { id: string; title: string };
18
+ }>();
19
+ </script>
20
+
21
+ <a
22
+ data-sveltekit-noscroll
23
+ on:mouseleave={() => {
24
+ confirmDelete = false;
25
+ }}
26
+ href="{base}/conversation/{conv.id}"
27
+ class="group flex h-11 flex-none items-center gap-1.5 rounded-lg pl-3 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700 {conv.id ===
28
+ $page.params.id
29
+ ? 'bg-gray-100 dark:bg-gray-700'
30
+ : ''}"
31
+ >
32
+ <div class="flex-1 truncate">
33
+ {#if confirmDelete}
34
+ <span class="font-semibold"> Delete </span>
35
+ {/if}
36
+ {conv.title}
37
+ </div>
38
+
39
+ {#if confirmDelete}
40
+ <button
41
+ type="button"
42
+ class="flex h-5 w-5 items-center justify-center rounded md:hidden md:group-hover:flex"
43
+ title="Confirm delete action"
44
+ on:click|preventDefault={() => dispatch("deleteConversation", conv.id)}
45
+ >
46
+ <CarbonCheckmark class="text-xs text-gray-400 hover:text-gray-500 dark:hover:text-gray-300" />
47
+ </button>
48
+ <button
49
+ type="button"
50
+ class="flex h-5 w-5 items-center justify-center rounded md:hidden md:group-hover:flex"
51
+ title="Cancel delete action"
52
+ on:click|preventDefault={() => {
53
+ confirmDelete = false;
54
+ }}
55
+ >
56
+ <CarbonClose class="text-xs text-gray-400 hover:text-gray-500 dark:hover:text-gray-300" />
57
+ </button>
58
+ {:else}
59
+ <button
60
+ type="button"
61
+ class="flex h-5 w-5 items-center justify-center rounded md:hidden md:group-hover:flex"
62
+ title="Edit conversation title"
63
+ on:click|preventDefault={() => {
64
+ const newTitle = prompt("Edit this conversation title:", conv.title);
65
+ if (!newTitle) return;
66
+ dispatch("editConversationTitle", { id: conv.id, title: newTitle });
67
+ }}
68
+ >
69
+ <CarbonEdit class="text-xs text-gray-400 hover:text-gray-500 dark:hover:text-gray-300" />
70
+ </button>
71
+
72
+ <button
73
+ type="button"
74
+ class="flex h-5 w-5 items-center justify-center rounded md:hidden md:group-hover:flex"
75
+ title="Delete conversation"
76
+ on:click|preventDefault={(event) => {
77
+ if (event.shiftKey) {
78
+ dispatch("deleteConversation", conv.id);
79
+ } else {
80
+ confirmDelete = true;
81
+ }
82
+ }}
83
+ >
84
+ <CarbonTrashCan class="text-xs text-gray-400 hover:text-gray-500 dark:hover:text-gray-300" />
85
+ </button>
86
+ {/if}
87
+ </a>
src/lib/components/NavMenu.svelte ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { base } from "$app/paths";
3
+ import { createEventDispatcher } from "svelte";
4
+
5
+ import Logo from "$lib/components/icons/Logo.svelte";
6
+ import { switchTheme } from "$lib/switchTheme";
7
+ import { PUBLIC_ORIGIN } from "$env/static/public";
8
+ import NavConversationItem from "./NavConversationItem.svelte";
9
+
10
+ const dispatch = createEventDispatcher<{
11
+ shareConversation: { id: string; title: string };
12
+ clickSettings: void;
13
+ clickLogout: void;
14
+ }>();
15
+
16
+ export let conversations: Array<{
17
+ id: string;
18
+ title: string;
19
+ }> = [];
20
+ export let user: { username: string } | undefined;
21
+ </script>
22
+
23
+ <div class="sticky top-0 flex flex-none items-center justify-between px-3 py-3.5 max-sm:pt-0">
24
+ <a class="flex items-center rounded-xl text-lg font-semibold" href="{PUBLIC_ORIGIN}{base}/">
25
+ <Logo classNames="mr-1 text-3xl" />
26
+ HuggingChat
27
+ </a>
28
+ <a
29
+ href={`${base}/`}
30
+ class="flex rounded-lg border bg-white px-2 py-0.5 text-center shadow-sm hover:shadow-none dark:border-gray-600 dark:bg-gray-700"
31
+ >
32
+ New Chat
33
+ </a>
34
+ </div>
35
+ <div
36
+ class="scrollbar-custom flex flex-col gap-1 overflow-y-auto rounded-r-xl bg-gradient-to-l from-gray-50 px-3 pb-3 pt-2 dark:from-gray-800/30"
37
+ >
38
+ {#each conversations as conv (conv.id)}
39
+ <NavConversationItem on:editConversationTitle on:deleteConversation {conv} />
40
+ {/each}
41
+ </div>
42
+ <div
43
+ class="mt-0.5 flex flex-col gap-1 rounded-r-xl bg-gradient-to-l from-gray-50 p-3 text-sm dark:from-gray-800/30"
44
+ >
45
+ {#if user?.username}
46
+ <form
47
+ action="{base}/logout"
48
+ method="post"
49
+ class="group flex items-center gap-1.5 rounded-lg pl-3 pr-2 hover:bg-gray-100 dark:hover:bg-gray-700"
50
+ >
51
+ <span class="flex h-9 flex-none items-center gap-1.5 pr-2 text-gray-500 dark:text-gray-400"
52
+ >{user?.username}</span
53
+ >
54
+ <button
55
+ type="submit"
56
+ class="ml-auto h-6 flex-none items-center gap-1.5 rounded-md border bg-white px-2 text-gray-700 shadow-sm group-hover:flex hover:shadow-none dark:border-gray-600 dark:bg-gray-600 dark:text-gray-400 dark:hover:text-gray-300 md:hidden"
57
+ >
58
+ Sign Out
59
+ </button>
60
+ </form>
61
+ {/if}
62
+ <button
63
+ on:click={switchTheme}
64
+ type="button"
65
+ class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-3 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
66
+ >
67
+ Theme
68
+ </button>
69
+ <button
70
+ on:click={() => dispatch("clickSettings")}
71
+ type="button"
72
+ class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-3 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
73
+ >
74
+ Settings
75
+ </button>
76
+ <a
77
+ href="https://huggingface.co/spaces/huggingchat/chat-ui/discussions"
78
+ target="_blank"
79
+ rel="noreferrer"
80
+ class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-3 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
81
+ >
82
+ Feedback
83
+ </a>
84
+ <a
85
+ href="{base}/privacy"
86
+ class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-3 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
87
+ >
88
+ About & Privacy
89
+ </a>
90
+ </div>
src/lib/components/Portal.svelte ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { onMount, onDestroy } from "svelte";
3
+
4
+ let el: HTMLElement;
5
+
6
+ onMount(() => {
7
+ el.ownerDocument.body.appendChild(el);
8
+ });
9
+
10
+ onDestroy(() => {
11
+ if (el?.parentNode) {
12
+ el.parentNode.removeChild(el);
13
+ }
14
+ });
15
+ </script>
16
+
17
+ <div bind:this={el} class="contents" hidden>
18
+ <slot />
19
+ </div>
src/lib/components/ScrollToBottomBtn.svelte ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { fade } from "svelte/transition";
3
+ import { onDestroy } from "svelte";
4
+ import IconChevron from "./icons/IconChevron.svelte";
5
+
6
+ export let scrollNode: HTMLElement;
7
+ export { className as class };
8
+
9
+ let visible = false;
10
+ let className = "";
11
+ let observer: ResizeObserver | null = null;
12
+
13
+ $: if (scrollNode) {
14
+ destroy();
15
+
16
+ if (window.ResizeObserver) {
17
+ observer = new ResizeObserver(() => {
18
+ updateVisibility();
19
+ });
20
+ observer.observe(scrollNode);
21
+ }
22
+ scrollNode.addEventListener("scroll", updateVisibility);
23
+ }
24
+
25
+ function updateVisibility() {
26
+ if (!scrollNode) return;
27
+ visible =
28
+ Math.ceil(scrollNode.scrollTop) + 200 < scrollNode.scrollHeight - scrollNode.clientHeight;
29
+ }
30
+
31
+ function destroy() {
32
+ observer?.disconnect();
33
+ scrollNode?.removeEventListener("scroll", updateVisibility);
34
+ }
35
+
36
+ onDestroy(destroy);
37
+ </script>
38
+
39
+ {#if visible}
40
+ <button
41
+ transition:fade|local={{ duration: 150 }}
42
+ on:click={() => scrollNode.scrollTo({ top: scrollNode.scrollHeight, behavior: "smooth" })}
43
+ class="btn absolute flex h-[41px] w-[41px] rounded-full border bg-white shadow-md transition-all hover:bg-gray-100 dark:border-gray-600 dark:bg-gray-700 dark:shadow-gray-950 dark:hover:bg-gray-600 {className}"
44
+ ><IconChevron classNames="mt-[2px]" /></button
45
+ >
46
+ {/if}
src/lib/components/SettingsModal.svelte ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { createEventDispatcher } from "svelte";
3
+
4
+ import Modal from "$lib/components/Modal.svelte";
5
+ import CarbonClose from "~icons/carbon/close";
6
+ import Switch from "$lib/components/Switch.svelte";
7
+ import type { Settings } from "$lib/types/Settings";
8
+ import { enhance } from "$app/forms";
9
+ import { base } from "$app/paths";
10
+
11
+ export let settings: Pick<Settings, "shareConversationsWithModelAuthors">;
12
+
13
+ let shareConversationsWithModelAuthors = settings.shareConversationsWithModelAuthors;
14
+ let isConfirmingDeletion = false;
15
+
16
+ const dispatch = createEventDispatcher<{ close: void }>();
17
+ </script>
18
+
19
+ <Modal on:close>
20
+ <div class="flex w-full flex-col gap-5 p-6">
21
+ <div class="flex items-start justify-between text-xl font-semibold text-gray-800">
22
+ <h2>Settings</h2>
23
+ <button type="button" class="group" on:click={() => dispatch("close")}>
24
+ <CarbonClose class="text-gray-900 group-hover:text-gray-500" />
25
+ </button>
26
+ </div>
27
+ <form
28
+ class="flex flex-col gap-5"
29
+ use:enhance={() => {
30
+ dispatch("close");
31
+ }}
32
+ method="post"
33
+ action="{base}/settings"
34
+ >
35
+ <label class="flex cursor-pointer select-none items-center gap-2 text-gray-500">
36
+ {#each Object.entries(settings).filter(([k]) => k !== "shareConversationsWithModelAuthors") as [key, val]}
37
+ <input type="hidden" name={key} value={val} />
38
+ {/each}
39
+ <Switch
40
+ name="shareConversationsWithModelAuthors"
41
+ bind:checked={shareConversationsWithModelAuthors}
42
+ />
43
+ Share conversations with model authors
44
+ </label>
45
+
46
+ <p class="text-gray-800">
47
+ Sharing your data will help improve the training data and make open models better over time.
48
+ </p>
49
+ <p class="text-gray-800">
50
+ You can change this setting at any time, it applies to all your conversations.
51
+ </p>
52
+ <p class="text-gray-800">
53
+ Read more about this model's authors,
54
+ <a
55
+ href="https://open-assistant.io/"
56
+ target="_blank"
57
+ rel="noreferrer"
58
+ class="underline decoration-gray-300 hover:decoration-gray-700">Open Assistant</a
59
+ >.
60
+ </p>
61
+ <form
62
+ method="post"
63
+ action="{base}/conversations?/delete"
64
+ on:submit|preventDefault={() => (isConfirmingDeletion = true)}
65
+ >
66
+ <button type="submit" class="underline decoration-gray-300 hover:decoration-gray-700">
67
+ Delete all conversations
68
+ </button>
69
+ </form>
70
+ <button
71
+ type="submit"
72
+ class="mt-2 rounded-full bg-black px-5 py-2 text-lg font-semibold text-gray-100 ring-gray-400 ring-offset-1 transition-all focus-visible:outline-none focus-visible:ring hover:ring"
73
+ >
74
+ Apply
75
+ </button>
76
+ </form>
77
+
78
+ {#if isConfirmingDeletion}
79
+ <Modal on:close={() => (isConfirmingDeletion = false)}>
80
+ <form
81
+ use:enhance={() => {
82
+ dispatch("close");
83
+ }}
84
+ method="post"
85
+ action="{base}/conversations?/delete"
86
+ class="flex w-full flex-col gap-5 p-6"
87
+ >
88
+ <div class="flex items-start justify-between text-xl font-semibold text-gray-800">
89
+ <h2>Are you sure?</h2>
90
+ <button type="button" class="group" on:click={() => (isConfirmingDeletion = false)}>
91
+ <CarbonClose class="text-gray-900 group-hover:text-gray-500" />
92
+ </button>
93
+ </div>
94
+ <p class="text-gray-800">
95
+ This action will delete all your conversations. This cannot be undone.
96
+ </p>
97
+ <button
98
+ type="submit"
99
+ class="mt-2 rounded-full bg-red-700 px-5 py-2 text-lg font-semibold text-gray-100 ring-gray-400 ring-offset-1 transition-all focus-visible:outline-none focus-visible:ring hover:ring"
100
+ >
101
+ Confirm deletion
102
+ </button>
103
+ </form>
104
+ </Modal>
105
+ {/if}
106
+ </div>
107
+ </Modal>
src/lib/components/StopGeneratingBtn.svelte ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import CarbonPause from "~icons/carbon/pause-filled";
3
+
4
+ export let visible = false;
5
+ export let className = "";
6
+ </script>
7
+
8
+ <button
9
+ type="button"
10
+ on:click
11
+ class="btn absolute flex rounded-lg border bg-white px-3 py-1 shadow-sm transition-all hover:bg-gray-100 dark:border-gray-600 dark:bg-gray-700 dark:hover:bg-gray-600
12
+ {className}
13
+ {visible ? 'visible opacity-100' : 'invisible opacity-0'}
14
+ "
15
+ >
16
+ <CarbonPause class="-ml-1 mr-1 h-[1.25rem] w-[1.1875rem] text-gray-400" /> Stop generating
17
+ </button>
src/lib/components/Switch.svelte ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let checked: boolean;
3
+ export let name: string;
4
+ </script>
5
+
6
+ <input bind:checked type="checkbox" {name} class="peer pointer-events-none absolute opacity-0" />
7
+ <div
8
+ class="relative inline-flex h-5 w-9 shrink-0 items-center rounded-full bg-gray-300 p-1 shadow-inner ring-gray-400 transition-all peer-checked:bg-black peer-focus-visible:ring peer-focus-visible:ring-offset-1 hover:bg-gray-400 peer-checked:[&>div]:translate-x-3.5"
9
+ >
10
+ <div class="h-3.5 w-3.5 rounded-full bg-white shadow-sm transition-all" />
11
+ </div>
src/lib/components/Toast.svelte ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { fade } from "svelte/transition";
3
+
4
+ import IconDazzled from "$lib/components/icons/IconDazzled.svelte";
5
+
6
+ export let message = "";
7
+ </script>
8
+
9
+ <div
10
+ transition:fade={{ duration: 300 }}
11
+ class="pointer-events-none fixed right-0 top-12 z-20 bg-gradient-to-bl from-red-500/20 via-red-500/0 to-red-500/0 pb-36 pl-36 pr-2 pt-2 md:top-0 md:pr-8 md:pt-5"
12
+ >
13
+ <div
14
+ class="pointer-events-auto flex items-center rounded-full bg-white/90 px-3 py-1 shadow-sm dark:bg-gray-900/80"
15
+ >
16
+ <IconDazzled classNames="text-2xl mr-2" />
17
+ <h2 class="font-semibold">{message}</h2>
18
+ </div>
19
+ </div>
src/lib/components/Tooltip.svelte ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let classNames = "";
3
+ export let label = "Copied";
4
+ export let position = "left-1/2 top-full transform -translate-x-1/2 translate-y-2";
5
+ </script>
6
+
7
+ <div
8
+ class="
9
+ pointer-events-none absolute rounded bg-black px-2 py-1 font-normal leading-tight text-white shadow transition-opacity
10
+ {position}
11
+ {classNames}
12
+ "
13
+ >
14
+ <div
15
+ class="absolute bottom-full left-1/2 h-0 w-0 -translate-x-1/2 transform border-4 border-t-0 border-black"
16
+ style="
17
+ border-left-color: transparent;
18
+ border-right-color: transparent;
19
+ "
20
+ />
21
+ {label}
22
+ </div>
src/lib/components/chat/ChatInput.svelte ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { createEventDispatcher, onMount } from "svelte";
3
+
4
+ export let value = "";
5
+ export let minRows = 1;
6
+ export let maxRows: null | number = null;
7
+ export let placeholder = "";
8
+ export let disabled = false;
9
+
10
+ // Approximate width from which we disable autofocus
11
+ const TABLET_VIEWPORT_WIDTH = 768;
12
+
13
+ let innerWidth = 0;
14
+ let textareaElement: HTMLTextAreaElement;
15
+
16
+ const dispatch = createEventDispatcher<{ submit: void }>();
17
+
18
+ $: minHeight = `${1 + minRows * 1.5}em`;
19
+ $: maxHeight = maxRows ? `${1 + maxRows * 1.5}em` : `auto`;
20
+
21
+ function handleKeydown(event: KeyboardEvent) {
22
+ // submit on enter
23
+ if (event.key === "Enter" && !event.shiftKey) {
24
+ event.preventDefault();
25
+ dispatch("submit"); // use a custom event instead of `event.target.form.requestSubmit()` as it does not work on Safari 14
26
+ }
27
+ }
28
+
29
+ onMount(() => {
30
+ if (innerWidth > TABLET_VIEWPORT_WIDTH) {
31
+ textareaElement.focus();
32
+ }
33
+ });
34
+ </script>
35
+
36
+ <svelte:window bind:innerWidth />
37
+
38
+ <div class="relative min-w-0 flex-1">
39
+ <pre
40
+ class="scrollbar-custom invisible overflow-x-hidden overflow-y-scroll whitespace-pre-wrap break-words p-3"
41
+ aria-hidden="true"
42
+ style="min-height: {minHeight}; max-height: {maxHeight}">{(value || " ") + "\n"}</pre>
43
+
44
+ <textarea
45
+ enterkeyhint="send"
46
+ tabindex="0"
47
+ rows="1"
48
+ class="scrollbar-custom absolute top-0 m-0 h-full w-full resize-none scroll-p-3 overflow-x-hidden overflow-y-scroll border-0 bg-transparent p-3 outline-none focus:ring-0 focus-visible:ring-0"
49
+ bind:value
50
+ bind:this={textareaElement}
51
+ {disabled}
52
+ on:keydown={handleKeydown}
53
+ {placeholder}
54
+ />
55
+ </div>
56
+
57
+ <style>
58
+ pre,
59
+ textarea {
60
+ font-family: inherit;
61
+ box-sizing: border-box;
62
+ line-height: 1.5;
63
+ }
64
+ </style>
src/lib/components/chat/ChatIntroduction.svelte ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { PUBLIC_VERSION } from "$env/static/public";
3
+ import { PUBLIC_ANNOUNCEMENT_BANNERS } from "$env/static/public";
4
+ import Logo from "$lib/components/icons/Logo.svelte";
5
+ import { createEventDispatcher } from "svelte";
6
+ import IconChevron from "$lib/components/icons/IconChevron.svelte";
7
+ import CarbonArrowUpRight from "~icons/carbon/arrow-up-right";
8
+ import AnnouncementBanner from "../AnnouncementBanner.svelte";
9
+ import ModelsModal from "../ModelsModal.svelte";
10
+ import type { Model } from "$lib/types/Model";
11
+ import ModelCardMetadata from "../ModelCardMetadata.svelte";
12
+ import type { LayoutData } from "../../../routes/$types";
13
+ import { findCurrentModel } from "$lib/utils/models";
14
+
15
+ export let currentModel: Model;
16
+ export let settings: LayoutData["settings"];
17
+ export let models: Model[];
18
+
19
+ let isModelsModalOpen = false;
20
+
21
+ $: currentModelMetadata = findCurrentModel(models, settings.activeModel);
22
+
23
+ const announcementBanners = PUBLIC_ANNOUNCEMENT_BANNERS
24
+ ? JSON.parse(PUBLIC_ANNOUNCEMENT_BANNERS)
25
+ : [];
26
+
27
+ const dispatch = createEventDispatcher<{ message: string }>();
28
+ </script>
29
+
30
+ <div class="my-auto grid gap-8 lg:grid-cols-3">
31
+ <div class="lg:col-span-1">
32
+ <div>
33
+ <div class="mb-3 flex items-center text-2xl font-semibold">
34
+ <Logo classNames="mr-1 text-yellow-400 text-4xl flex-none" />
35
+ HuggingChat
36
+ <div
37
+ class="ml-3 flex h-6 items-center rounded-lg border border-gray-100 bg-gray-50 px-2 text-base text-gray-400 dark:border-gray-700/60 dark:bg-gray-800"
38
+ >
39
+ v{PUBLIC_VERSION}
40
+ </div>
41
+ </div>
42
+ <p class="text-base text-gray-600 dark:text-gray-400">
43
+ Making the community's best AI chat models available to everyone.
44
+ </p>
45
+ </div>
46
+ </div>
47
+ <div class="lg:col-span-2 lg:pl-24">
48
+ {#each announcementBanners as banner}
49
+ <AnnouncementBanner classNames="mb-4" title={banner.title}>
50
+ <a
51
+ target="_blank"
52
+ href={banner.linkHref}
53
+ class="mr-2 flex items-center underline hover:no-underline"
54
+ ><CarbonArrowUpRight class="mr-1.5 text-xs" /> {banner.linkTitle}</a
55
+ >
56
+ </AnnouncementBanner>
57
+ {/each}
58
+
59
+ {#if isModelsModalOpen}
60
+ <ModelsModal {settings} {models} on:close={() => (isModelsModalOpen = false)} />
61
+ {/if}
62
+ <div class="overflow-hidden rounded-xl border dark:border-gray-800">
63
+ <div class="flex p-3">
64
+ <div>
65
+ <div class="text-sm text-gray-600 dark:text-gray-400">Current Model</div>
66
+ <div class="font-semibold">{currentModel.displayName}</div>
67
+ </div>
68
+ {#if models.length > 1}
69
+ <button
70
+ type="button"
71
+ on:click={() => (isModelsModalOpen = true)}
72
+ class="btn ml-auto flex h-7 w-7 self-start rounded-full bg-gray-100 p-1 text-xs hover:bg-gray-100 dark:border-gray-600 dark:bg-gray-800 dark:hover:bg-gray-600"
73
+ ><IconChevron /></button
74
+ >
75
+ {/if}
76
+ </div>
77
+ <ModelCardMetadata variant="dark" model={currentModel} />
78
+ </div>
79
+ </div>
80
+ {#if currentModelMetadata.promptExamples}
81
+ <div class="lg:col-span-3 lg:mt-12">
82
+ <p class="mb-3 text-gray-600 dark:text-gray-300">Examples</p>
83
+ <div class="grid gap-3 lg:grid-cols-3 lg:gap-5">
84
+ {#each currentModelMetadata.promptExamples as example}
85
+ <button
86
+ type="button"
87
+ class="rounded-xl border bg-gray-50 p-2.5 text-gray-600 hover:bg-gray-100 dark:border-gray-800 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700 sm:p-4"
88
+ on:click={() => dispatch("message", example.prompt)}
89
+ >
90
+ {example.title}
91
+ </button>
92
+ {/each}
93
+ </div>
94
+ </div>{/if}
95
+ </div>
src/lib/components/chat/ChatMessage.svelte ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { marked } from "marked";
3
+ import type { Message } from "$lib/types/Message";
4
+ import { afterUpdate, createEventDispatcher } from "svelte";
5
+ import { deepestChild } from "$lib/utils/deepestChild";
6
+ import { page } from "$app/stores";
7
+
8
+ import CodeBlock from "../CodeBlock.svelte";
9
+ import IconLoading from "../icons/IconLoading.svelte";
10
+ import CarbonRotate360 from "~icons/carbon/rotate-360";
11
+ import CarbonDownload from "~icons/carbon/download";
12
+ import CarbonThumbsUp from "~icons/carbon/thumbs-up";
13
+ import CarbonThumbsDown from "~icons/carbon/thumbs-down";
14
+ import { PUBLIC_SEP_TOKEN } from "$lib/constants/publicSepToken";
15
+ import type { Model } from "$lib/types/Model";
16
+
17
+ function sanitizeMd(md: string) {
18
+ let ret = md
19
+ .replace(/<\|[a-z]*$/, "")
20
+ .replace(/<\|[a-z]+\|$/, "")
21
+ .replace(/<$/, "")
22
+ .replaceAll(PUBLIC_SEP_TOKEN, " ")
23
+ .replaceAll(/<\|[a-z]+\|>/g, " ")
24
+ .replaceAll(/<br\s?\/?>/gi, "\n")
25
+ .replaceAll("<", "&lt;")
26
+ .trim();
27
+
28
+ for (const stop of [...(model.parameters?.stop ?? []), "<|endoftext|>"]) {
29
+ if (ret.endsWith(stop)) {
30
+ ret = ret.slice(0, -stop.length).trim();
31
+ }
32
+ }
33
+
34
+ return ret;
35
+ }
36
+ function unsanitizeMd(md: string) {
37
+ return md.replaceAll("&lt;", "<");
38
+ }
39
+
40
+ export let model: Model;
41
+ export let message: Message;
42
+ export let loading = false;
43
+ export let isAuthor = true;
44
+ export let readOnly = false;
45
+ export let isTapped = false;
46
+
47
+ const dispatch = createEventDispatcher<{
48
+ retry: { content: string; id: Message["id"] };
49
+ vote: { score: Message["score"]; id: Message["id"] };
50
+ }>();
51
+
52
+ let contentEl: HTMLElement;
53
+ let loadingEl: IconLoading;
54
+ let pendingTimeout: ReturnType<typeof setTimeout>;
55
+
56
+ const renderer = new marked.Renderer();
57
+
58
+ // For code blocks with simple backticks
59
+ renderer.codespan = (code) => {
60
+ // Unsanitize double-sanitized code
61
+ return `<code>${code.replaceAll("&amp;", "&")}</code>`;
62
+ };
63
+
64
+ const options: marked.MarkedOptions = {
65
+ ...marked.getDefaults(),
66
+ gfm: true,
67
+ breaks: true,
68
+ renderer,
69
+ };
70
+
71
+ $: tokens = marked.lexer(sanitizeMd(message.content));
72
+
73
+ afterUpdate(() => {
74
+ loadingEl?.$destroy();
75
+ clearTimeout(pendingTimeout);
76
+
77
+ // Add loading animation to the last message if update takes more than 600ms
78
+ if (loading) {
79
+ pendingTimeout = setTimeout(() => {
80
+ if (contentEl) {
81
+ loadingEl = new IconLoading({
82
+ target: deepestChild(contentEl),
83
+ props: { classNames: "loading inline ml-2" },
84
+ });
85
+ }
86
+ }, 600);
87
+ }
88
+ });
89
+
90
+ $: downloadLink =
91
+ message.from === "user" ? `${$page.url.pathname}/message/${message.id}/prompt` : undefined;
92
+ </script>
93
+
94
+ {#if message.from === "assistant"}
95
+ <div
96
+ class="group relative -mb-8 flex items-start justify-start gap-4 pb-8 leading-relaxed"
97
+ on:click={() => (isTapped = !isTapped)}
98
+ on:keypress={() => (isTapped = !isTapped)}
99
+ >
100
+ <img
101
+ alt=""
102
+ src="https://huggingface.co/avatars/2edb18bd0206c16b433841a47f53fa8e.svg"
103
+ class="mt-5 h-3 w-3 flex-none select-none rounded-full shadow-lg"
104
+ />
105
+ <div
106
+ class="relative min-h-[calc(2rem+theme(spacing[3.5])*2)] min-w-[100px] break-words rounded-2xl border border-gray-100 bg-gradient-to-br from-gray-50 px-5 py-3.5 text-gray-600 prose-pre:my-2 dark:border-gray-800 dark:from-gray-800/40 dark:text-gray-300"
107
+ >
108
+ {#if !message.content}
109
+ <IconLoading classNames="absolute inset-0 m-auto" />
110
+ {/if}
111
+ <div
112
+ class="prose max-w-none dark:prose-invert max-sm:prose-sm prose-headings:font-semibold prose-h1:text-lg prose-h2:text-base prose-h3:text-base prose-pre:bg-gray-800 dark:prose-pre:bg-gray-900"
113
+ bind:this={contentEl}
114
+ >
115
+ {#each tokens as token}
116
+ {#if token.type === "code"}
117
+ <CodeBlock lang={token.lang} code={unsanitizeMd(token.text)} />
118
+ {:else}
119
+ <!-- eslint-disable-next-line svelte/no-at-html-tags -->
120
+ {@html marked(token.raw, options)}
121
+ {/if}
122
+ {/each}
123
+ </div>
124
+ </div>
125
+ {#if isAuthor && !loading && message.content}
126
+ <div
127
+ class="absolute bottom-1 right-0 flex max-md:transition-all md:bottom-0 md:group-hover:visible md:group-hover:opacity-100
128
+ {message.score ? 'visible opacity-100' : 'invisible max-md:-translate-y-4 max-md:opacity-0'}
129
+ {isTapped ? 'max-md:visible max-md:translate-y-0 max-md:opacity-100' : ''}
130
+ "
131
+ >
132
+ <button
133
+ class="btn rounded-sm p-1 text-sm text-gray-400 focus:ring-0 hover:text-gray-500 dark:text-gray-400 dark:hover:text-gray-300
134
+ {message.score && message.score > 0
135
+ ? 'text-green-500 hover:text-green-500 dark:text-green-400 hover:dark:text-green-400'
136
+ : ''}"
137
+ title={message.score === 1 ? "Remove +1" : "+1"}
138
+ type="button"
139
+ on:click={() => dispatch("vote", { score: message.score === 1 ? 0 : 1, id: message.id })}
140
+ >
141
+ <CarbonThumbsUp class="h-[1.14em] w-[1.14em]" />
142
+ </button>
143
+ <button
144
+ class="btn rounded-sm p-1 text-sm text-gray-400 focus:ring-0 hover:text-gray-500 dark:text-gray-400 dark:hover:text-gray-300
145
+ {message.score && message.score < 0
146
+ ? 'text-red-500 hover:text-red-500 dark:text-red-400 hover:dark:text-red-400'
147
+ : ''}"
148
+ title={message.score === -1 ? "Remove -1" : "-1"}
149
+ type="button"
150
+ on:click={() =>
151
+ dispatch("vote", { score: message.score === -1 ? 0 : -1, id: message.id })}
152
+ >
153
+ <CarbonThumbsDown class="h-[1.14em] w-[1.14em]" />
154
+ </button>
155
+ </div>
156
+ {/if}
157
+ </div>
158
+ {/if}
159
+ {#if message.from === "user"}
160
+ <div class="group relative flex items-start justify-start gap-4 max-sm:text-sm">
161
+ <div class="mt-5 h-3 w-3 flex-none rounded-full" />
162
+ <div
163
+ class="max-w-full whitespace-break-spaces break-words rounded-2xl px-5 py-3.5 text-gray-500 dark:text-gray-400"
164
+ >
165
+ {message.content.trim()}
166
+ </div>
167
+ {#if !loading}
168
+ <div class="absolute right-0 top-3.5 flex gap-2 lg:-right-2">
169
+ {#if downloadLink}
170
+ <a
171
+ class="rounded-lg border border-gray-100 p-1 text-xs text-gray-400 group-hover:block hover:text-gray-500 dark:border-gray-800 dark:text-gray-400 dark:hover:text-gray-300 md:hidden"
172
+ title="Download prompt and parameters"
173
+ type="button"
174
+ target="_blank"
175
+ href={downloadLink}
176
+ >
177
+ <CarbonDownload />
178
+ </a>
179
+ {/if}
180
+ {#if !readOnly}
181
+ <button
182
+ class="cursor-pointer rounded-lg border border-gray-100 p-1 text-xs text-gray-400 group-hover:block hover:text-gray-500 dark:border-gray-800 dark:text-gray-400 dark:hover:text-gray-300 md:hidden lg:-right-2"
183
+ title="Retry"
184
+ type="button"
185
+ on:click={() => dispatch("retry", { content: message.content, id: message.id })}
186
+ >
187
+ <CarbonRotate360 />
188
+ </button>
189
+ {/if}
190
+ </div>
191
+ {/if}
192
+ </div>
193
+ {/if}
src/lib/components/chat/ChatMessages.svelte ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { Message } from "$lib/types/Message";
3
+ import { snapScrollToBottom } from "$lib/actions/snapScrollToBottom";
4
+ import ScrollToBottomBtn from "$lib/components/ScrollToBottomBtn.svelte";
5
+ import { tick } from "svelte";
6
+ import { randomUUID } from "$lib/utils/randomUuid";
7
+ import type { Model } from "$lib/types/Model";
8
+ import type { LayoutData } from "../../../routes/$types";
9
+ import ChatIntroduction from "./ChatIntroduction.svelte";
10
+ import ChatMessage from "./ChatMessage.svelte";
11
+
12
+ export let messages: Message[];
13
+ export let loading: boolean;
14
+ export let pending: boolean;
15
+ export let isAuthor: boolean;
16
+ export let currentModel: Model;
17
+ export let settings: LayoutData["settings"];
18
+ export let models: Model[];
19
+ export let readOnly: boolean;
20
+
21
+ let chatContainer: HTMLElement;
22
+
23
+ async function scrollToBottom() {
24
+ await tick();
25
+ chatContainer.scrollTop = chatContainer.scrollHeight;
26
+ }
27
+
28
+ // If last message is from user, scroll to bottom
29
+ $: if (messages[messages.length - 1]?.from === "user") {
30
+ scrollToBottom();
31
+ }
32
+ </script>
33
+
34
+ <div
35
+ class="scrollbar-custom mr-1 h-full overflow-y-auto"
36
+ use:snapScrollToBottom={messages.length ? messages : false}
37
+ bind:this={chatContainer}
38
+ >
39
+ <div class="mx-auto flex h-full max-w-3xl flex-col gap-6 px-5 pt-6 sm:gap-8 xl:max-w-4xl">
40
+ {#each messages as message, i}
41
+ <ChatMessage
42
+ loading={loading && i === messages.length - 1}
43
+ {message}
44
+ {isAuthor}
45
+ {readOnly}
46
+ model={currentModel}
47
+ on:retry
48
+ on:vote
49
+ />
50
+ {:else}
51
+ <ChatIntroduction {settings} {models} {currentModel} on:message />
52
+ {/each}
53
+ {#if pending}
54
+ <ChatMessage
55
+ message={{ from: "assistant", content: "", id: randomUUID() }}
56
+ model={currentModel}
57
+ />
58
+ {/if}
59
+ <div class="h-36 flex-none" />
60
+ </div>
61
+ <ScrollToBottomBtn
62
+ class="bottom-36 right-4 max-md:hidden lg:right-10"
63
+ scrollNode={chatContainer}
64
+ />
65
+ </div>
src/lib/components/chat/ChatWindow.svelte ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { Message } from "$lib/types/Message";
3
+ import { createEventDispatcher } from "svelte";
4
+
5
+ import CarbonSendAltFilled from "~icons/carbon/send-alt-filled";
6
+ import CarbonExport from "~icons/carbon/export";
7
+
8
+ import ChatMessages from "./ChatMessages.svelte";
9
+ import ChatInput from "./ChatInput.svelte";
10
+ import StopGeneratingBtn from "../StopGeneratingBtn.svelte";
11
+ import type { Model } from "$lib/types/Model";
12
+ import type { LayoutData } from "../../../routes/$types";
13
+
14
+ export let messages: Message[] = [];
15
+ export let loading = false;
16
+ export let pending = false;
17
+ export let shared = false;
18
+ export let currentModel: Model;
19
+ export let models: Model[];
20
+ export let settings: LayoutData["settings"];
21
+
22
+ $: isReadOnly = !models.some((model) => model.id === currentModel.id);
23
+
24
+ let message: string;
25
+
26
+ const dispatch = createEventDispatcher<{
27
+ message: string;
28
+ share: void;
29
+ stop: void;
30
+ retry: { id: Message["id"]; content: string };
31
+ }>();
32
+
33
+ const handleSubmit = () => {
34
+ if (loading) return;
35
+ dispatch("message", message);
36
+ message = "";
37
+ };
38
+ </script>
39
+
40
+ <div class="relative min-h-0 min-w-0">
41
+ <ChatMessages
42
+ {loading}
43
+ {pending}
44
+ {settings}
45
+ {currentModel}
46
+ {models}
47
+ {messages}
48
+ readOnly={isReadOnly}
49
+ isAuthor={!shared}
50
+ on:message
51
+ on:vote
52
+ on:retry={(ev) => {
53
+ if (!loading) dispatch("retry", ev.detail);
54
+ }}
55
+ />
56
+ <div
57
+ class="dark:via-gray-80 pointer-events-none absolute inset-x-0 bottom-0 z-0 mx-auto flex w-full max-w-3xl flex-col items-center justify-center bg-gradient-to-t from-white via-white/80 to-white/0 px-3.5 py-4 dark:border-gray-800 dark:from-gray-900 dark:to-gray-900/0 max-md:border-t max-md:bg-white max-md:dark:bg-gray-900 sm:px-5 md:py-8 xl:max-w-4xl [&>*]:pointer-events-auto"
58
+ >
59
+ <StopGeneratingBtn
60
+ visible={loading}
61
+ className="right-5 mr-[1px] md:mr-0 md:right-7 top-6 md:top-10 z-10"
62
+ on:click={() => dispatch("stop")}
63
+ />
64
+ <form
65
+ on:submit|preventDefault={handleSubmit}
66
+ class="relative flex w-full max-w-4xl flex-1 items-center rounded-xl border bg-gray-100 focus-within:border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:focus-within:border-gray-500
67
+ {isReadOnly ? 'opacity-30' : ''}"
68
+ >
69
+ <div class="flex w-full flex-1 border-none bg-transparent">
70
+ <ChatInput
71
+ placeholder="Ask anything"
72
+ bind:value={message}
73
+ on:submit={handleSubmit}
74
+ maxRows={4}
75
+ disabled={isReadOnly}
76
+ />
77
+ <button
78
+ class="btn mx-1 my-1 h-[2.4rem] self-end rounded-lg bg-transparent p-1 px-[0.7rem] text-gray-400 disabled:opacity-60 enabled:hover:text-gray-700 dark:disabled:opacity-40 enabled:dark:hover:text-gray-100"
79
+ disabled={!message || loading || isReadOnly}
80
+ type="submit"
81
+ >
82
+ <CarbonSendAltFilled />
83
+ </button>
84
+ </div>
85
+ </form>
86
+ <div class="mt-2 flex justify-between self-stretch px-1 text-xs text-gray-400/90 max-sm:gap-2">
87
+ <p>
88
+ Model: <a
89
+ href="https://huggingface.co/{currentModel.name}"
90
+ target="_blank"
91
+ rel="noreferrer"
92
+ class="hover:underline">{currentModel.displayName}</a
93
+ > <span class="max-sm:hidden">·</span><br class="sm:hidden" /> Generated content may be inaccurate
94
+ or false.
95
+ </p>
96
+ {#if messages.length}
97
+ <button
98
+ class="flex flex-none items-center hover:text-gray-400 hover:underline max-sm:rounded-lg max-sm:bg-gray-50 max-sm:px-2.5 dark:max-sm:bg-gray-800"
99
+ type="button"
100
+ on:click={() => dispatch("share")}
101
+ >
102
+ <CarbonExport class="text-[.6rem] sm:mr-1.5 sm:text-yellow-500" />
103
+ <div class="max-sm:hidden">Share this conversation</div>
104
+ </button>
105
+ {/if}
106
+ </div>
107
+ </div>
108
+ </div>
src/lib/components/icons/IconChevron.svelte ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let classNames = "";
3
+ </script>
4
+
5
+ <svg
6
+ width="1em"
7
+ height="1em"
8
+ viewBox="0 0 15 6"
9
+ class={classNames}
10
+ fill="none"
11
+ xmlns="http://www.w3.org/2000/svg"
12
+ >
13
+ <path
14
+ d="M1.67236 1L7.67236 7L13.6724 1"
15
+ stroke="currentColor"
16
+ stroke-width="2"
17
+ stroke-linecap="round"
18
+ stroke-linejoin="round"
19
+ />
20
+ </svg>
src/lib/components/icons/IconCopy.svelte ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let classNames = "";
3
+ </script>
4
+
5
+ <svg
6
+ class={classNames}
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ aria-hidden="true"
9
+ fill="currentColor"
10
+ focusable="false"
11
+ role="img"
12
+ width="1em"
13
+ height="1em"
14
+ preserveAspectRatio="xMidYMid meet"
15
+ viewBox="0 0 32 32"
16
+ >
17
+ <path
18
+ d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z"
19
+ transform="translate(0)"
20
+ />
21
+ <path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)" /><rect
22
+ fill="none"
23
+ width="32"
24
+ height="32"
25
+ />
26
+ </svg>
src/lib/components/icons/IconDazzled.svelte ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let classNames = "";
3
+ </script>
4
+
5
+ <svg
6
+ xmlns="http://www.w3.org/2000/svg"
7
+ width="1em"
8
+ height="1em"
9
+ class={classNames}
10
+ fill="none"
11
+ viewBox="0 0 26 23"
12
+ >
13
+ <path
14
+ fill="url(#a)"
15
+ d="M.93 10.65A10.17 10.17 0 0 1 11.11.48h4.67a9.45 9.45 0 0 1 0 18.89H4.53L1.62 22.2a.38.38 0 0 1-.69-.28V10.65Z"
16
+ />
17
+ <path
18
+ fill="#000"
19
+ fill-rule="evenodd"
20
+ d="M11.52 7.4a1.86 1.86 0 1 1-3.72 0 1.86 1.86 0 0 1 3.72 0Zm7.57 0a1.86 1.86 0 1 1-3.73 0 1.86 1.86 0 0 1 3.73 0ZM8.9 12.9a.55.55 0 0 0-.11.35.76.76 0 0 1-1.51 0c0-.95.67-1.94 1.76-1.94 1.09 0 1.76 1 1.76 1.94H9.3a.55.55 0 0 0-.12-.35c-.06-.07-.1-.08-.13-.08s-.08 0-.14.08Zm4.04 0a.55.55 0 0 0-.12.35h-1.51c0-.95.68-1.94 1.76-1.94 1.1 0 1.77 1 1.77 1.94h-1.51a.55.55 0 0 0-.12-.35c-.06-.07-.11-.08-.14-.08-.02 0-.07 0-.13.08Zm-1.89.79c-.02 0-.07-.01-.13-.08a.55.55 0 0 1-.12-.36h-1.5c0 .95.67 1.95 1.75 1.95 1.1 0 1.77-1 1.77-1.95h-1.51c0 .16-.06.28-.12.36-.06.07-.11.08-.14.08Zm4.04 0c-.03 0-.08-.01-.14-.08a.55.55 0 0 1-.12-.36h-1.5c0 .95.67 1.95 1.76 1.95 1.08 0 1.76-1 1.76-1.95h-1.51c0 .16-.06.28-.12.36-.06.07-.11.08-.13.08Zm1.76-.44c0-.16.05-.28.12-.35.06-.07.1-.08.13-.08s.08 0 .14.08c.06.07.11.2.11.35a.76.76 0 0 0 1.51 0c0-.95-.67-1.94-1.76-1.94-1.09 0-1.76 1-1.76 1.94h1.5Z"
21
+ clip-rule="evenodd"
22
+ />
23
+ <defs>
24
+ <radialGradient
25
+ id="a"
26
+ cx="0"
27
+ cy="0"
28
+ r="1"
29
+ gradientTransform="matrix(0 31.37 -34.85 0 13.08 -9.02)"
30
+ gradientUnits="userSpaceOnUse"
31
+ >
32
+ <stop stop-color="#FFD21E" />
33
+ <stop offset="1" stop-color="red" />
34
+ </radialGradient>
35
+ </defs>
36
+ </svg>
src/lib/components/icons/IconLoading.svelte ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let classNames = "";
3
+ </script>
4
+
5
+ <svg
6
+ xmlns="http://www.w3.org/2000/svg"
7
+ width="40px"
8
+ height="25px"
9
+ viewBox="0 0 60 40"
10
+ preserveAspectRatio="xMidYMid"
11
+ class={classNames}
12
+ >
13
+ {#each Array(3) as _, index}
14
+ <g transform={`translate(${20 * index + 10} 20)`}>
15
+ {index}
16
+ <circle cx="0" cy="0" r="6" fill="currentColor">
17
+ <animateTransform
18
+ attributeName="transform"
19
+ type="scale"
20
+ begin={`${-0.375 + 0.15 * index}s`}
21
+ calcMode="spline"
22
+ keySplines="0.3 0 0.7 1;0.3 0 0.7 1"
23
+ values="0.5;1;0.5"
24
+ keyTimes="0;0.5;1"
25
+ dur="1s"
26
+ repeatCount="indefinite"
27
+ />
28
+ </circle>
29
+ </g>
30
+ {/each}
31
+ </svg>
src/lib/components/icons/Logo.svelte ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let classNames = "";
3
+ </script>
4
+
5
+ <svg
6
+ width="1em"
7
+ height="1em"
8
+ class={classNames}
9
+ viewBox="0 0 13 12"
10
+ fill="none"
11
+ xmlns="http://www.w3.org/2000/svg"
12
+ >
13
+ <path
14
+ fill="#FFD21E"
15
+ d="M1.76 5.63a3.7 3.7 0 0 1 3.7-3.7h1.7a3.43 3.43 0 0 1 0 6.87H3.07L2.01 9.83a.14.14 0 0 1-.25-.1v-4.1Z"
16
+ />
17
+ <path
18
+ fill="#32343D"
19
+ d="M7.37 4.8c.13.05.19.33.33.25a.54.54 0 0 0 .22-.73.54.54 0 0 0-.73-.22.54.54 0 0 0-.22.73c.06.13.27-.08.4-.03ZM4.83 4.8c-.14.05-.2.33-.33.25a.54.54 0 0 1-.23-.73A.54.54 0 0 1 5 4.1c.26.14.36.47.22.73-.06.13-.27-.08-.4-.03ZM6.12 7.4c1.06 0 1.4-.96 1.4-1.44 0-.49-.62.26-1.4.26-.77 0-1.4-.75-1.4-.26 0 .48.34 1.43 1.4 1.43Z"
20
+ />
21
+ <path
22
+ fill="#FF323D"
23
+ d="M6.97 7.12c-.2.16-.49.27-.85.27-.34 0-.6-.1-.81-.24a.94.94 0 0 1 .57-.49c.04-.01.09.06.13.14.05.07.1.15.14.15.05 0 .1-.08.14-.15.05-.08.1-.15.14-.13a.93.93 0 0 1 .54.45Z"
24
+ />
25
+ </svg>
src/lib/components/icons/LogoHuggingFaceBorderless.svelte ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let classNames = "";
3
+ </script>
4
+
5
+ <svg
6
+ class={classNames}
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ width="1em"
9
+ height="1em"
10
+ fill="none"
11
+ viewBox="0 0 95 88"
12
+ >
13
+ <path fill="#FFD21E" d="M47.21 76.5a34.75 34.75 0 1 0 0-69.5 34.75 34.75 0 0 0 0 69.5Z" />
14
+ <path
15
+ fill="#FF9D0B"
16
+ d="M81.96 41.75a34.75 34.75 0 1 0-69.5 0 34.75 34.75 0 0 0 69.5 0Zm-73.5 0a38.75 38.75 0 1 1 77.5 0 38.75 38.75 0 0 1-77.5 0Z"
17
+ />
18
+ <path
19
+ fill="#3A3B45"
20
+ d="M58.5 32.3c1.28.44 1.78 3.06 3.07 2.38a5 5 0 1 0-6.76-2.07c.61 1.15 2.55-.72 3.7-.32ZM34.95 32.3c-1.28.44-1.79 3.06-3.07 2.38a5 5 0 1 1 6.76-2.07c-.61 1.15-2.56-.72-3.7-.32ZM46.96 56.29c9.83 0 13-8.76 13-13.26 0-2.34-1.57-1.6-4.09-.36-2.33 1.15-5.46 2.74-8.9 2.74-7.19 0-13-6.88-13-2.38s3.16 13.26 13 13.26Z"
21
+ />
22
+ <mask id="a" width="27" height="16" x="33" y="41" maskUnits="userSpaceOnUse">
23
+ <path
24
+ fill="#fff"
25
+ d="M46.96 56.29c9.83 0 13-8.76 13-13.26 0-2.34-1.57-1.6-4.09-.36-2.33 1.15-5.46 2.74-8.9 2.74-7.19 0-13-6.88-13-2.38s3.16 13.26 13 13.26Z"
26
+ />
27
+ </mask>
28
+ <g mask="url(#a)">
29
+ <path
30
+ fill="#F94040"
31
+ d="M47.21 66.5a8.67 8.67 0 0 0 2.65-16.94c-.84-.26-1.73 2.6-2.65 2.6-.86 0-1.7-2.88-2.48-2.65a8.68 8.68 0 0 0 2.48 16.99Z"
32
+ />
33
+ </g>
34
+ <path
35
+ fill="#FF9D0B"
36
+ d="M70.71 37a3.25 3.25 0 1 0 0-6.5 3.25 3.25 0 0 0 0 6.5ZM24.21 37a3.25 3.25 0 1 0 0-6.5 3.25 3.25 0 0 0 0 6.5ZM17.52 48c-1.62 0-3.06.66-4.07 1.87a5.97 5.97 0 0 0-1.33 3.76 7.1 7.1 0 0 0-1.94-.3c-1.55 0-2.95.59-3.94 1.66a5.8 5.8 0 0 0-.8 7 5.3 5.3 0 0 0-1.79 2.82c-.24.9-.48 2.8.8 4.74a5.22 5.22 0 0 0-.37 5.02c1.02 2.32 3.57 4.14 8.52 6.1 3.07 1.22 5.89 2 5.91 2.01a44.33 44.33 0 0 0 10.93 1.6c5.86 0 10.05-1.8 12.46-5.34 3.88-5.69 3.33-10.9-1.7-15.92-2.77-2.78-4.62-6.87-5-7.77-.78-2.66-2.84-5.62-6.25-5.62a5.7 5.7 0 0 0-4.6 2.46c-1-1.26-1.98-2.25-2.86-2.82A7.4 7.4 0 0 0 17.52 48Zm0 4c.51 0 1.14.22 1.82.65 2.14 1.36 6.25 8.43 7.76 11.18.5.92 1.37 1.31 2.14 1.31 1.55 0 2.75-1.53.15-3.48-3.92-2.93-2.55-7.72-.68-8.01.08-.02.17-.02.24-.02 1.7 0 2.45 2.93 2.45 2.93s2.2 5.52 5.98 9.3c3.77 3.77 3.97 6.8 1.22 10.83-1.88 2.75-5.47 3.58-9.16 3.58-3.81 0-7.73-.9-9.92-1.46-.11-.03-13.45-3.8-11.76-7 .28-.54.75-.76 1.34-.76 2.38 0 6.7 3.54 8.57 3.54.41 0 .7-.17.83-.6.79-2.85-12.06-4.05-10.98-8.17.2-.73.71-1.02 1.44-1.02 3.14 0 10.2 5.53 11.68 5.53.11 0 .2-.03.24-.1.74-1.2.33-2.04-4.9-5.2-5.21-3.16-8.88-5.06-6.8-7.33.24-.26.58-.38 1-.38 3.17 0 10.66 6.82 10.66 6.82s2.02 2.1 3.25 2.1c.28 0 .52-.1.68-.38.86-1.46-8.06-8.22-8.56-11.01-.34-1.9.24-2.85 1.31-2.85Z"
37
+ />
38
+ <path
39
+ fill="#FFD21E"
40
+ d="M38.6 76.69c2.75-4.04 2.55-7.07-1.22-10.84-3.78-3.77-5.98-9.3-5.98-9.3s-.82-3.2-2.69-2.9c-1.87.3-3.24 5.08.68 8.01 3.91 2.93-.78 4.92-2.29 2.17-1.5-2.75-5.62-9.82-7.76-11.18-2.13-1.35-3.63-.6-3.13 2.2.5 2.79 9.43 9.55 8.56 11-.87 1.47-3.93-1.71-3.93-1.71s-9.57-8.71-11.66-6.44c-2.08 2.27 1.59 4.17 6.8 7.33 5.23 3.16 5.64 4 4.9 5.2-.75 1.2-12.28-8.53-13.36-4.4-1.08 4.11 11.77 5.3 10.98 8.15-.8 2.85-9.06-5.38-10.74-2.18-1.7 3.21 11.65 6.98 11.76 7.01 4.3 1.12 15.25 3.49 19.08-2.12Z"
41
+ />
42
+ <path
43
+ fill="#FF9D0B"
44
+ d="M77.4 48c1.62 0 3.07.66 4.07 1.87a5.97 5.97 0 0 1 1.33 3.76 7.1 7.1 0 0 1 1.95-.3c1.55 0 2.95.59 3.94 1.66a5.8 5.8 0 0 1 .8 7 5.3 5.3 0 0 1 1.78 2.82c.24.9.48 2.8-.8 4.74a5.22 5.22 0 0 1 .37 5.02c-1.02 2.32-3.57 4.14-8.51 6.1-3.08 1.22-5.9 2-5.92 2.01a44.33 44.33 0 0 1-10.93 1.6c-5.86 0-10.05-1.8-12.46-5.34-3.88-5.69-3.33-10.9 1.7-15.92 2.78-2.78 4.63-6.87 5.01-7.77.78-2.66 2.83-5.62 6.24-5.62a5.7 5.7 0 0 1 4.6 2.46c1-1.26 1.98-2.25 2.87-2.82A7.4 7.4 0 0 1 77.4 48Zm0 4c-.51 0-1.13.22-1.82.65-2.13 1.36-6.25 8.43-7.76 11.18a2.43 2.43 0 0 1-2.14 1.31c-1.54 0-2.75-1.53-.14-3.48 3.91-2.93 2.54-7.72.67-8.01a1.54 1.54 0 0 0-.24-.02c-1.7 0-2.45 2.93-2.45 2.93s-2.2 5.52-5.97 9.3c-3.78 3.77-3.98 6.8-1.22 10.83 1.87 2.75 5.47 3.58 9.15 3.58 3.82 0 7.73-.9 9.93-1.46.1-.03 13.45-3.8 11.76-7-.29-.54-.75-.76-1.34-.76-2.38 0-6.71 3.54-8.57 3.54-.42 0-.71-.17-.83-.6-.8-2.85 12.05-4.05 10.97-8.17-.19-.73-.7-1.02-1.44-1.02-3.14 0-10.2 5.53-11.68 5.53-.1 0-.19-.03-.23-.1-.74-1.2-.34-2.04 4.88-5.2 5.23-3.16 8.9-5.06 6.8-7.33-.23-.26-.57-.38-.98-.38-3.18 0-10.67 6.82-10.67 6.82s-2.02 2.1-3.24 2.1a.74.74 0 0 1-.68-.38c-.87-1.46 8.05-8.22 8.55-11.01.34-1.9-.24-2.85-1.31-2.85Z"
45
+ />
46
+ <path
47
+ fill="#FFD21E"
48
+ d="M56.33 76.69c-2.75-4.04-2.56-7.07 1.22-10.84 3.77-3.77 5.97-9.3 5.97-9.3s.82-3.2 2.7-2.9c1.86.3 3.23 5.08-.68 8.01-3.92 2.93.78 4.92 2.28 2.17 1.51-2.75 5.63-9.82 7.76-11.18 2.13-1.35 3.64-.6 3.13 2.2-.5 2.79-9.42 9.55-8.55 11 .86 1.47 3.92-1.71 3.92-1.71s9.58-8.71 11.66-6.44c2.08 2.27-1.58 4.17-6.8 7.33-5.23 3.16-5.63 4-4.9 5.2.75 1.2 12.28-8.53 13.36-4.4 1.08 4.11-11.76 5.3-10.97 8.15.8 2.85 9.05-5.38 10.74-2.18 1.69 3.21-11.65 6.98-11.76 7.01-4.31 1.12-15.26 3.49-19.08-2.12Z"
49
+ />
50
+ </svg>
src/lib/constants/publicSepToken.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export const PUBLIC_SEP_TOKEN = "</s>";