Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarrazin authored May 3, 2024
2 parents 91f8de1 + 5703512 commit 59ce922
Show file tree
Hide file tree
Showing 97 changed files with 2,413 additions and 639 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ node_modules/
.svelte-kit/
.env*
!.env
!.env.local
.env.local
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,6 @@ WEBHOOK_URL_REPORT_ASSISTANT=#provide webhook url to get notified when an assist
ALLOWED_USER_EMAILS=`[]` # if it's defined, only these emails will be allowed to use the app

USAGE_LIMITS=`{}`
ALLOW_INSECURE_COOKIES=false # recommended to keep this to false but set to true if you need to run over http without tls
METRICS_PORT=
LOG_LEVEL=info
8 changes: 5 additions & 3 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ MODELS=`[
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/cohere-logo.png",
"parameters": {
"stop": ["<|END_OF_TURN_TOKEN|>"],
"truncate" : 24576,
"max_new_tokens" : 8192,
"truncate" : 28672,
"max_new_tokens" : 4096,
"temperature" : 0.3
},
"promptExamples" : [
Expand Down Expand Up @@ -206,8 +206,9 @@ MODELS=`[
"modelUrl": "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct",
"websiteUrl": "https://azure.microsoft.com/en-us/blog/introducing-phi-3-redefining-whats-possible-with-slms/",
"preprompt": "",
"chatPromptTemplate": "<s>{{preprompt}}{{#each messages}}{{#ifUser}}<|user|>\n{{content}}<|end|>\n<|assistant|>\n{{/ifUser}}{{#ifAssistant}}{{content}}<|end|>\n{{/ifAssistant}}{{/each}}",
"parameters": {
"stop": ["</s>", "<|end|>", "<|endoftext|>", "<|assistant|>"],
"stop": ["<|end|>", "<|endoftext|>", "<|assistant|>"],
"max_new_tokens": 1024,
"truncate": 3071
},
Expand All @@ -230,6 +231,7 @@ MODELS=`[
"parameters": {
"temperature": 0.1,
"stop": ["<|eot_id|>"],
"truncate": 1024,
},
"unlisted": true
}
Expand Down
16 changes: 16 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
changelog:
exclude:
labels:
- huggingchat
- CI/CD
- documentation
categories:
- title: Features
labels:
- enhancement
- title: Bugfixes
labels:
- bug
- title: Other changes
labels:
- "*"
6 changes: 3 additions & 3 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
branches:
- "*"
paths:
- "Dockerfile.local"
- "Dockerfile"
- "entrypoint.sh"
workflow_dispatch:
release:
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.local
file: Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.local
file: Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Deploy to k8s
on:
# run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build-and-publish-huggingchat-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Tailscale
uses: huggingface/tailscale-action@main
with:
authkey: ${{ secrets.TAILSCALE_AUTHKEY }}

- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
registry.internal.huggingface.tech/chat-ui/chat-ui
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha,enable={{is_default_branch}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Registry
uses: docker/login-action@v2
with:
registry: registry.internal.huggingface.tech
username: ${{ secrets.DOCKER_INTERNAL_USERNAME }}
password: ${{ secrets.DOCKER_INTERNAL_PASSWORD }}

- name: Build and Publish HuggingChat image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
cache-to: type=gha,mode=max,scope=amd64
cache-from: type=gha,scope=amd64
provenance: false
build-args: |
INCLUDE_DB=false
APP_BASE=/chat
PUBLIC_APP_COLOR=yellow
deploy:
name: Deploy on prod
runs-on: ubuntu-latest
needs: ["build-and-publish-huggingchat-image"]
steps:
- name: Inject slug/short variables
uses: rlespinasse/[email protected]

- name: Gen values
run: |
VALUES=$(cat <<-END
image:
tag: "sha-${{ env.GITHUB_SHA_SHORT }}"
END
)
echo "VALUES=$(echo "$VALUES" | yq -o=json | jq tostring)" >> $GITHUB_ENV
- name: Deploy on infra-deployments
uses: aurelien-baudet/workflow-dispatch@v2
with:
workflow: Update application values
repo: huggingface/infra-deployments
wait-for-completion: true
wait-for-completion-interval: 10s
display-workflow-run-url-interval: 10s
ref: refs/heads/main
token: ${{ secrets.ARGO_CD_TOKEN }}
inputs: '{"path": "hub/chat-ui/chat-ui.yaml", "values": ${{ env.VALUES }}, "url": "${{ github.event.head_commit.url }}"}'
2 changes: 1 addition & 1 deletion .github/workflows/deploy-release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to production
name: Deploy to production spaces
on:
# run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
24 changes: 0 additions & 24 deletions .github/workflows/deploy-staging.yml

This file was deleted.

1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules
/build
/.svelte-kit
/package
/chart
.env
.env.*
!.env.example
Expand Down
66 changes: 56 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# syntax=docker/dockerfile:1
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
# you will also find guides on how best to write your Dockerfile
ARG INCLUDE_DB=false

# stage that install the dependencies
FROM node:20 as builder-production

WORKDIR /app
Expand All @@ -12,31 +15,74 @@ RUN --mount=type=cache,target=/app/.npm \

FROM builder-production as builder

ARG APP_BASE=
ARG PUBLIC_APP_COLOR=blue

RUN --mount=type=cache,target=/app/.npm \
npm set cache /app/.npm && \
npm ci

COPY --link --chown=1000 . .

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

FROM node:20-slim
RUN npm install -g pm2
# mongo image
FROM mongo:latest as mongo

RUN userdel -r node
# image to be used if INCLUDE_DB is false
FROM node:20-slim as local_db_false

# image to be used if INCLUDE_DB is true
FROM node:20-slim as local_db_true

RUN apt-get update
RUN apt-get install gnupg curl -y
# copy mongo from the other stage
COPY --from=mongo /usr/bin/mongo* /usr/bin/

ENV MONGODB_URL=mongodb://localhost:27017
RUN mkdir -p /data/db
RUN chown -R 1000:1000 /data/db

# final image
FROM local_db_${INCLUDE_DB} as final

# build arg to determine if the database should be included
ARG INCLUDE_DB=false
ENV INCLUDE_DB=${INCLUDE_DB}

# svelte requires APP_BASE at build time so it must be passed as a build arg
ARG APP_BASE=
# tailwind requires the primary theme to be known at build time so it must be passed as a build arg
ARG PUBLIC_APP_COLOR=blue

RUN useradd -m -u 1000 user

# install dotenv-cli
RUN npm install -g dotenv-cli

# switch to a user that works for spaces
RUN userdel -r node
RUN useradd -m -u 1000 user
USER user

ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH

WORKDIR /app

COPY --from=builder-production --chown=1000 /app/node_modules /app/node_modules
COPY --link --chown=1000 package.json /app/package.json
COPY --from=builder --chown=1000 /app/build /app/build
# add a .env.local if the user doesn't bind a volume to it
RUN touch /app/.env.local

# get the default config, the entrypoint script and the server script
COPY --chown=1000 package.json /app/package.json
COPY --chown=1000 .env /app/.env
COPY --chown=1000 entrypoint.sh /app/entrypoint.sh
COPY --chown=1000 gcp-*.json /app/

CMD pm2 start /app/build/index.js -i $CPU_CORES --no-daemon
#import the build & dependencies
COPY --from=builder --chown=1000 /app/build /app/build
COPY --from=builder --chown=1000 /app/node_modules /app/node_modules

RUN chmod +x /app/entrypoint.sh

CMD ["/bin/bash", "-c", "/app/entrypoint.sh"]
28 changes: 0 additions & 28 deletions Dockerfile.local

This file was deleted.

13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ A chat interface using open source models, eg OpenAssistant or Llama. It is a Sv
3. [Web Search](#web-search)
4. [Text Embedding Models](#text-embedding-models)
5. [Extra parameters](#extra-parameters)
6. [Deploying to a HF Space](#deploying-to-a-hf-space)
7. [Building](#building)
6. [Common issues](#common-issues)
7. [Deploying to a HF Space](#deploying-to-a-hf-space)
8. [Building](#building)

## No Setup Deploy

Expand Down Expand Up @@ -740,6 +741,14 @@ MODELS=`[
]`
```

## Common issues

### 403:You don't have access to this conversation

Most likely you are running chat-ui over HTTP. The recommended option is to setup something like NGINX to handle HTTPS and proxy the requests to chat-ui. If you really need to run over HTTP you can add `ALLOW_INSECURE_COOKIES=true` to your `.env.local`.

Make sure to set your `PUBLIC_ORIGIN` in your `.env.local` to the correct URL as well.

## Deploying to a HF Space

Create a `DOTENV_LOCAL` secret to your HF space with the content of your .env.local, and they will be picked up automatically when you run.
Expand Down
5 changes: 5 additions & 0 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: chat-ui
version: 0.0.0-latest
type: application
icon: https://huggingface.co/front/assets/huggingface_logo-noborder.svg
Loading

0 comments on commit 59ce922

Please sign in to comment.