Skip to content

Commit 69c509d

Browse files
committed
Load configuration at runtime instead of build time
This will make it possible to self contained docker images which can then be used in simple docker/kubernetes deployments.
1 parent 450bfce commit 69c509d

38 files changed

+238
-280
lines changed

.env

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
# Use .env.local to change these variables
22
# DO NOT EDIT THIS FILE WITH SENSITIVE DATA
33

4-
MONGODB_URL=#your mongodb URL here
5-
MONGODB_DB_NAME=chat-ui
6-
MONGODB_DIRECT_CONNECTION=false
4+
VITE_MONGODB_URL=#your mongodb URL here
5+
VITE_MONGODB_DB_NAME=chat-ui
6+
VITE_MONGODB_DIRECT_CONNECTION=false
77

8-
COOKIE_NAME=hf-chat
9-
HF_TOKEN=#hf_<token> from from https://huggingface.co/settings/token
10-
HF_API_ROOT=https://api-inference.huggingface.co/models
11-
OPENAI_API_KEY=#your openai api key here
8+
VITE_COOKIE_NAME=hf-chat
9+
VITE_HF_TOKEN=#hf_<token> from from https://huggingface.co/settings/token
10+
VITE_HF_API_ROOT=https://api-inference.huggingface.co/models
11+
VITE_OPENAI_API_KEY=#your openai api key here
1212

13-
HF_ACCESS_TOKEN=#LEGACY! Use HF_TOKEN instead
13+
VITE_HF_ACCESS_TOKEN=#LEGACY! Use HF_TOKEN instead
1414

1515
# used to activate search with web functionality. disabled if none are defined. choose one of the following:
16-
YDC_API_KEY=#your docs.you.com api key here
17-
SERPER_API_KEY=#your serper.dev api key here
18-
SERPAPI_KEY=#your serpapi key here
19-
SERPSTACK_API_KEY=#your serpstack api key here
20-
USE_LOCAL_WEBSEARCH=#set to true to parse google results yourself, overrides other API keys
16+
VITE_YDC_API_KEY=#your docs.you.com api key here
17+
VITE_SERPER_API_KEY=#your serper.dev api key here
18+
VITE_SERPAPI_KEY=#your serpapi key here
19+
VITE_SERPSTACK_API_KEY=#your serpstack api key here
20+
VITE_USE_LOCAL_WEBSEARCH=#set to true to parse google results yourself, overrides other API keys
2121

22-
WEBSEARCH_ALLOWLIST=`[]` # if it's defined, allow websites from only this list.
23-
WEBSEARCH_BLOCKLIST=`[]` # if it's defined, block websites from this list.
22+
VITE_WEBSEARCH_ALLOWLIST=`[]` # if it's defined, allow websites from only this list.
23+
VITE_WEBSEARCH_BLOCKLIST=`[]` # if it's defined, block websites from this list.
2424

2525
# Parameters to enable open id login
26-
OPENID_CONFIG=`{
26+
VITE_OPENID_CONFIG=`{
2727
"PROVIDER_URL": "",
2828
"CLIENT_ID": "",
2929
"CLIENT_SECRET": "",
3030
"SCOPES": ""
3131
}`
3232

3333
# /!\ legacy openid settings, prefer the config above
34-
OPENID_CLIENT_ID=
35-
OPENID_CLIENT_SECRET=
36-
OPENID_SCOPES="openid profile" # Add "email" for some providers like Google that do not provide preferred_username
37-
OPENID_PROVIDER_URL=https://huggingface.co # for Google, use https://accounts.google.com
38-
OPENID_TOLERANCE=
39-
OPENID_RESOURCE=
34+
VITE_OPENID_CLIENT_ID=
35+
VITE_OPENID_CLIENT_SECRET=
36+
VITE_OPENID_SCOPES="openid profile" # Add "email" for some providers like Google that do not provide preferred_username
37+
VITE_OPENID_PROVIDER_URL=https://huggingface.co # for Google, use https://accounts.google.com
38+
VITE_OPENID_TOLERANCE=
39+
VITE_OPENID_RESOURCE=
4040

4141
# Parameters to enable a global mTLS context for client fetch requests
42-
USE_CLIENT_CERTIFICATE=false
43-
CERT_PATH=#
44-
KEY_PATH=#
45-
CA_PATH=#
46-
CLIENT_KEY_PASSWORD=#
47-
REJECT_UNAUTHORIZED=true
48-
49-
TEXT_EMBEDDING_MODELS = `[
42+
VITE_USE_CLIENT_CERTIFICATE=false
43+
VITE_CERT_PATH=#
44+
VITE_KEY_PATH=#
45+
VITE_CA_PATH=#
46+
VITE_CLIENT_KEY_PASSWORD=#
47+
VITE_REJECT_UNAUTHORIZED=true
48+
49+
VITE_TEXT_EMBEDDING_MODELS = `[
5050
{
5151
"name": "Xenova/gte-small",
5252
"displayName": "Xenova/gte-small",
@@ -59,7 +59,7 @@ TEXT_EMBEDDING_MODELS = `[
5959
]`
6060

6161
# 'name', 'userMessageToken', 'assistantMessageToken' are required
62-
MODELS=`[
62+
VITE_MODELS=`[
6363
{
6464
"name": "mistralai/Mistral-7B-Instruct-v0.1",
6565
"displayName": "mistralai/Mistral-7B-Instruct-v0.1",
@@ -91,8 +91,8 @@ MODELS=`[
9191
}
9292
]`
9393

94-
OLD_MODELS=`[]`# any removed models, `{ name: string, displayName?: string, id?: string }`
95-
TASK_MODEL= # name of the model used for tasks such as summarizing title, creating query, etc.
94+
VITE_OLD_MODELS=`[]`# any removed models, `{ name: string, displayName?: string, id?: string }`
95+
VITE_TASK_MODEL= # name of the model used for tasks such as summarizing title, creating query, etc.
9696

9797
PUBLIC_ORIGIN=#https://huggingface.co
9898
PUBLIC_SHARE_PREFIX=#https://hf.co/chat
@@ -106,33 +106,33 @@ PUBLIC_ANNOUNCEMENT_BANNERS=`[
106106
}
107107
]`
108108

109-
PARQUET_EXPORT_DATASET=
110-
PARQUET_EXPORT_HF_TOKEN=
111-
PARQUET_EXPORT_SECRET=
109+
VITE_PARQUET_EXPORT_DATASET=
110+
VITE_PARQUET_EXPORT_HF_TOKEN=
111+
VITE_PARQUET_EXPORT_SECRET=
112112

113-
RATE_LIMIT= # requests per minute
114-
MESSAGES_BEFORE_LOGIN=# how many messages a user can send in a conversation before having to login. set to 0 to force login right away
113+
VITE_RATE_LIMIT= # requests per minute
114+
VITE_MESSAGES_BEFORE_LOGIN=# how many messages a user can send in a conversation before having to login. set to 0 to force login right away
115115

116-
APP_BASE="" # base path of the app, e.g. /chat, left blank as default
116+
VITE_APP_BASE="" # base path of the app, e.g. /chat, left blank as default
117117
PUBLIC_APP_NAME=ChatUI # name used as title throughout the app
118118
PUBLIC_APP_ASSETS=chatui # used to find logos & favicons in static/$PUBLIC_APP_ASSETS
119119
PUBLIC_APP_COLOR=blue # can be any of tailwind colors: https://tailwindcss.com/docs/customizing-colors#default-color-palette
120120
PUBLIC_APP_DESCRIPTION=# description used throughout the app (if not set, a default one will be used)
121121
PUBLIC_APP_DATA_SHARING=#set to 1 to enable options & text regarding data sharing
122122
PUBLIC_APP_DISCLAIMER=#set to 1 to show a disclaimer on login page
123123
PUBLIC_APP_DISCLAIMER_MESSAGE="Disclaimer: AI is an area of active research with known problems such as biased generation and misinformation. Do not use this application for high-stakes decisions or advice."
124-
LLM_SUMMERIZATION=true
124+
VITE_LLM_SUMMERIZATION=true
125125

126-
EXPOSE_API=true
126+
VITE_EXPOSE_API=true
127127
# PUBLIC_APP_NAME=HuggingChat
128128
# PUBLIC_APP_ASSETS=huggingchat
129129
# PUBLIC_APP_COLOR=yellow
130130
# PUBLIC_APP_DESCRIPTION="Making the community's best AI chat models available to everyone."
131131
# PUBLIC_APP_DATA_SHARING=1
132132
# PUBLIC_APP_DISCLAIMER=1
133133

134-
ENABLE_ASSISTANTS=false #set to true to enable assistants feature
134+
VITE_ENABLE_ASSISTANTS=false #set to true to enable assistants feature
135135

136-
ALTERNATIVE_REDIRECT_URLS=`[]` #valide alternative redirect URL for OAuth
136+
VITE_ALTERNATIVE_REDIRECT_URLS=`[]` #valide alternative redirect URL for OAuth
137137

138-
WEBHOOK_URL_REPORT_ASSISTANT=#provide webhook url to get notified when an assistant gets reported
138+
VITE_WEBHOOK_URL_REPORT_ASSISTANT=#provide webhook url to get notified when an assistant gets reported

.env.ci

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
MONGODB_URL=mongodb://localhost:27017/
1+
VITE_MONGODB_URL=mongodb://localhost:27017/

.env.template

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# template used in production for HuggingChat.
22

3-
MODELS=`[
3+
VITE_MODELS=`[
44
{
55
"name" : "mistralai/Mixtral-8x7B-Instruct-v0.1",
66
"description" : "The latest MoE model from Mistral AI! 8x7B and outperforms Llama 2 70B in most benchmarks.",
@@ -207,7 +207,7 @@ MODELS=`[
207207
}
208208
]`
209209

210-
OLD_MODELS=`[
210+
VITE_OLD_MODELS=`[
211211
{"name":"bigcode/starcoder"},
212212
{"name":"OpenAssistant/oasst-sft-6-llama-30b-xor"},
213213
{"name":"HuggingFaceH4/zephyr-7b-alpha"},
@@ -217,9 +217,9 @@ OLD_MODELS=`[
217217
{"name": "codellama/CodeLlama-34b-Instruct-hf"}
218218
]`
219219

220-
TASK_MODEL='mistralai/Mistral-7B-Instruct-v0.1'
220+
VITE_TASK_MODEL='mistralai/Mistral-7B-Instruct-v0.1'
221221

222-
APP_BASE="/chat"
222+
VITE_APP_BASE="/chat"
223223
PUBLIC_ORIGIN=https://huggingface.co
224224
PUBLIC_SHARE_PREFIX=https://hf.co/chat
225225
PUBLIC_ANNOUNCEMENT_BANNERS=`[]`
@@ -232,8 +232,8 @@ PUBLIC_APP_DISCLAIMER_MESSAGE="Disclaimer: AI is an area of active research with
232232
PUBLIC_APP_DATA_SHARING=1
233233
PUBLIC_APP_DISCLAIMER=1
234234

235-
RATE_LIMIT=16
236-
MESSAGES_BEFORE_LOGIN=5# how many messages a user can send in a conversation before having to login. set to 0 to force login right away
235+
VITE_RATE_LIMIT=16
236+
VITE_MESSAGES_BEFORE_LOGIN=5# how many messages a user can send in a conversation before having to login. set to 0 to force login right away
237237

238238
PUBLIC_GOOGLE_ANALYTICS_ID=G-8Q63TH4CSL
239239
PUBLIC_PLAUSIBLE_SCRIPT_URL="/js/script.js"
@@ -242,9 +242,9 @@ PUBLIC_PLAUSIBLE_SCRIPT_URL="/js/script.js"
242242
# ADDRESS_HEADER=X-Forwarded-For
243243
# XFF_DEPTH=2
244244

245-
ENABLE_ASSISTANTS=true
246-
EXPOSE_API=true
245+
VITE_ENABLE_ASSISTANTS=true
246+
VITE_EXPOSE_API=true
247247

248-
ALTERNATIVE_REDIRECT_URLS=`[
248+
VITE_ALTERNATIVE_REDIRECT_URLS=`[
249249
huggingchat://login/callback
250250
]`

Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ RUN --mount=type=cache,target=/app/.npm \
1818

1919
COPY --link --chown=1000 . .
2020

21-
RUN --mount=type=secret,id=DOTENV_LOCAL,dst=.env.local \
22-
npm run build
21+
RUN npm run build
2322

2423
FROM node:20-slim
2524

26-
RUN npm install -g pm2
25+
WORKDIR /app
26+
27+
RUN npm install -g pm2 dotenv-cli
2728

2829
COPY --from=builder-production /app/node_modules /app/node_modules
2930
COPY --link --chown=1000 package.json /app/package.json
3031
COPY --from=builder /app/build /app/build
3132

32-
CMD pm2 start /app/build/index.js -i $CPU_CORES --no-daemon
33+
CMD dotenv -e .env -c -- pm2 start /app/build/index.js -i $CPU_CORES --no-daemon

0 commit comments

Comments
 (0)