nsarrazin HF staff commited on
Commit
aee1b53
1 Parent(s): a7dd688

initial commit

Browse files
Files changed (3) hide show
  1. .env.template +74 -0
  2. Dockerfile +74 -0
  3. entrypoint.sh +19 -0
.env.template ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use .env.local to change these variables
2
+ # DO NOT EDIT THIS FILE WITH SENSITIVE DATA
3
+
4
+ MONGODB_URL=mongodb://127.0.0.1:27017
5
+ MONGODB_DB_NAME=chat-ui
6
+ MONGODB_DIRECT_CONNECTION=false
7
+
8
+
9
+ COOKIE_NAME=${SPACE_ID}
10
+ HF_ACCESS_TOKEN=#hf_<token> from from https://huggingface.co/settings/token
11
+
12
+ # used to activate search with web functionality. disabled if not defined
13
+ SERPAPI_KEY=#your serpapi key here
14
+
15
+ # Parameters to enable "Sign in with HF"
16
+ OPENID_CLIENT_ID=
17
+ OPENID_CLIENT_SECRET=
18
+ OPENID_SCOPES="openid profile" # Add "email" for some providers like Google that do not provide preferred_username
19
+ OPENID_PROVIDER_URL=https://huggingface.co # for Google, use https://accounts.google.com
20
+
21
+
22
+ # 'name', 'userMessageToken', 'assistantMessageToken' are required
23
+ MODELS=`[
24
+ {
25
+ "name": "${MODEL_NAME}",
26
+ "userMessageToken": "<|prompter|>",
27
+ "assistantMessageToken": "<|assistant|>",
28
+ "messageEndToken": "<|endoftext|>",
29
+ "preprompt": "${PREPROMPT}",
30
+ "promptExamples": [
31
+ {
32
+ "title": "Python Fibonacci",
33
+ "prompt": "How can I write a Python function to generate the nth Fibonacci number?"
34
+ }, {
35
+ "title": "What is a meme?",
36
+ "prompt": "What is a meme, and what's the history behind this word?"
37
+ }, {
38
+ "title": "Regex",
39
+ "prompt": "Create a regex to extract dates from logs"
40
+ }
41
+ ],
42
+ "endpoints": [
43
+ {
44
+ "url": "http://127.0.0.1:8080"
45
+ }
46
+ ],
47
+ "parameters": {
48
+ "temperature": ${MODEL_TEMPERATURE},
49
+ "top_p": 0.95,
50
+ "repetition_penalty": 1.2,
51
+ "top_k": 50,
52
+ "truncate": 1000,
53
+ "max_new_tokens": 1024
54
+ }
55
+ }
56
+ ]`
57
+ OLD_MODELS=`[]`# any removed models, `{ name: string, displayName?: string, id?: string }`
58
+
59
+ APP_BASE=
60
+ PUBLIC_ORIGIN=${SPACE_HOST}
61
+ PUBLIC_SHARE_PREFIX=${SPACE_HOST}
62
+ PUBLIC_GOOGLE_ANALYTICS_ID=#G-XXXXXXXX / Leave empty to disable
63
+ PUBLIC_DEPRECATED_GOOGLE_ANALYTICS_ID=#UA-XXXXXXXX-X / Leave empty to disable
64
+ PUBLIC_ANNOUNCEMENT_BANNERS=`[
65
+ {
66
+ "title": "Chat UI is now open sourced on GitHub",
67
+ "linkTitle": "GitHub repo",
68
+ "linkHref": "https://github.com/huggingface/chat-ui"
69
+ }
70
+ ]`
71
+
72
+ PARQUET_EXPORT_DATASET=
73
+ PARQUET_EXPORT_HF_TOKEN=
74
+ PARQUET_EXPORT_SECRET=
Dockerfile ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:19 as chatui-builder
2
+
3
+ WORKDIR /app
4
+
5
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
6
+ git && \
7
+ rm -rf /var/lib/apt/lists/*
8
+
9
+ RUN git clone https://github.com/huggingface/chat-ui.git
10
+
11
+ WORKDIR /app/chat-ui
12
+
13
+ RUN --mount=type=cache,target=/app/.npm \
14
+ npm set cache /app/.npm && \
15
+ npm ci
16
+
17
+ RUN envsubst < ".env.template" > ".env.local"
18
+
19
+ COPY .env.local .env.local
20
+ RUN npm run build
21
+
22
+ FROM ghcr.io/huggingface/text-generation-inference:latest
23
+
24
+ ENV TZ=Europe/Paris \
25
+ PORT=3000
26
+
27
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
28
+ gnupg \
29
+ curl && \
30
+ rm -rf /var/lib/apt/lists/*
31
+
32
+ RUN curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
33
+ gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
34
+ --dearmor
35
+
36
+ RUN echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-6.0.list
37
+
38
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
39
+ mongodb-org && \
40
+ rm -rf /var/lib/apt/lists/*
41
+
42
+ RUN mkdir -p /data/db
43
+ RUN chown -R 1000:1000 /data
44
+
45
+ RUN curl -fsSL https://deb.nodesource.com/setup_19.x | /bin/bash -
46
+
47
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
48
+ nodejs && \
49
+ rm -rf /var/lib/apt/lists/*
50
+
51
+ RUN mkdir /app
52
+ RUN chown -R 1000:1000 /app
53
+
54
+ RUN useradd -m -u 1000 user
55
+
56
+ # Switch to the "user" user
57
+ USER user
58
+
59
+ ENV HOME=/home/user \
60
+ PATH=/home/user/.local/bin:$PATH
61
+
62
+ RUN npm config set prefix /home/user/.local
63
+ RUN npm install -g pm2
64
+
65
+ COPY --from=chatui-builder --chown=1000 /app/chat-ui/node_modules /app/node_modules
66
+ COPY --from=chatui-builder --chown=1000 /app/chat-ui/package.json /app/package.json
67
+ COPY --from=chatui-builder --chown=1000 /app/chat-ui/build /app/build
68
+
69
+ COPY entrypoint.sh entrypoint.sh
70
+
71
+ ENTRYPOINT ["/bin/bash"]
72
+ CMD ["entrypoint.sh"]
73
+
74
+
entrypoint.sh ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Start the local Mongo database
4
+ mongod &
5
+
6
+ # Start the text-generation-inference process
7
+ text-generation-launcher --model-id $MODEL_NAME --num-shard 1 --port 8080 --trust_remote_code &
8
+
9
+ # Wait for text-generation-inference to start
10
+ curl --retry 60 --retry-delay 60 --retry-connrefused http://127.0.0.1:8080/health
11
+
12
+ # Start the chat-ui process
13
+ pm2 start /app/build/index.js -i $CPU_CORES --no-daemon &
14
+
15
+ # Wait for any process to exit
16
+ wait -n
17
+
18
+ # Exit with status of process that exited first
19
+ exit $?