Skip to content

Commit

Permalink
Revert change regarding config folder
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarrazin committed Dec 6, 2023
1 parent 3fd71d4 commit 8751c6b
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ LICENSE
README.md
node_modules/
.svelte-kit/
config/*
!config/.env
.env*
!.env
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build Docker image
run: docker build --secret id=DOTENV_LOCAL,src=config/.env.ci -t chat-ui:latest .
run: docker build --secret id=DOTENV_LOCAL,src=.env.ci -t chat-ui:latest .
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ vite.config.js.timestamp-*
vite.config.ts.timestamp-*
SECRET_CONFIG
.idea
!config/.env.ci
!config/.env
!config/.env.template
!.env.ci
!.env
!.env.template
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN --mount=type=cache,target=/app/.npm \

COPY --link --chown=1000 . .

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

FROM node:20-slim
Expand Down
2 changes: 1 addition & 1 deletion PROMPTS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Prompt templates

These are the templates used to format the conversation history for different models used in HuggingChat. Set them in your `config/.env.local` [like so](https://github.com/huggingface/chat-ui#chatprompttemplate).
These are the templates used to format the conversation history for different models used in HuggingChat. Set them in your `.env.local` [like so](https://github.com/huggingface/chat-ui#chatprompttemplate).

## Llama 2

Expand Down
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Read the full tutorial [here](https://huggingface.co/docs/hub/spaces-sdks-docker

## Setup

The default config for Chat UI is stored in the `config/.env` file. You will need to override some values to get Chat UI to run locally. This is done in `config/.env.local`.
The default config for Chat UI is stored in the `.env` file. You will need to override some values to get Chat UI to run locally. This is done in `.env.local`.

Start by creating a `.env.local` file in the `conf` folder. The bare minimum config you need to get Chat UI to run locally is the following:

Expand All @@ -45,25 +45,28 @@ MONGODB_URL=<the URL to your MongoDB instance>
HF_TOKEN=<your access token>
```

### Database
## Launch using Docker

The chat history is stored in a MongoDB instance, and having a DB instance available is needed for Chat UI to work.

You can use a local MongoDB instance. The easiest way is to spin one up using docker:
Once you have your `.env.local` file ready, you can launch Chat UI locally using docker. Start by pulling the image

```bash
docker run -d -p 27017:27017 --name mongo-chatui mongo:latest
docker pull ghcr.io/huggingface/chat-ui:latest
```

In which case the url of your DB will be `MONGODB_URL=mongodb://localhost:27017`.

Alternatively, you can use a [free MongoDB Atlas](https://www.mongodb.com/pricing) instance for this, Chat UI should fit comfortably within their free tier. After which you can set the `MONGODB_URL` variable in `.env.local` to match your instance.
Then run the image in the same folder where your `.env.local` is, with the following command:

### Hugging Face Access Token
```bash
DOTENV_LOCAL=$(<env.local) \
docker run --rm \
-e DOTENV_LOCAL \
-e USE_LOCAL_DB=true \
-p 3000:3000 \
chat-ui
```

If you use a remote inference endpoint, you will need a Hugging Face access token to run Chat UI locally. You can get one from [your Hugging Face profile](https://huggingface.co/settings/tokens).
`USE_LOCAL_DB` is optional, and will spin up a MongoDB instance inside the container. If you want to use your own MongoDB instance, just unset this variable and use `MONGODB_URL` in your `.env.local` file.

## Launch
## Launch in dev mode

After you're done with the `.env.local` file you can run Chat UI locally with:

Expand Down
10 changes: 5 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
if test -z "${DOTENV_LOCAL}" ; then
if ! test -f "/app/config/.env.local" ; then
if ! test -f "/app/.env.local" ; then
echo "DOTENV_LOCAL was not found in the ENV variables and .env.local is not set using a bind volume. We are using the default .env config."
fi;
else
echo "DOTENV_LOCAL was found in the ENV variables. Creating config/.env.local file."
cat <<< "$DOTENV_LOCAL" > /app/config/.env.local
echo "DOTENV_LOCAL was found in the ENV variables. Creating env.local file."
cat <<< "$DOTENV_LOCAL" > /app/.env.local
fi;

if [ "$USE_LOCAL_DB" = true ] ; then
echo "USE_LOCAL_DB is set to true. Appending MONGODB_URL"

touch /app/config/.env.local
echo -e "\nMONGODB_URL=mongodb://localhost:27017" >> /app/config/.env.local
touch /app/.env.local
echo -e "\nMONGODB_URL=mongodb://localhost:27017" >> /app/.env.local

mkdir -p /data/db
mongod &
Expand Down
8 changes: 4 additions & 4 deletions scripts/updateLocalEnv.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "fs";

const SECRET_CONFIG = fs.existsSync("config/.env.SECRET_CONFIG")
? fs.readFileSync("config/.env.SECRET_CONFIG", "utf8")
const SECRET_CONFIG = fs.existsSync("env.SECRET_CONFIG")
? fs.readFileSync(".env.SECRET_CONFIG", "utf8")
: process.env.SECRET_CONFIG;

if (!SECRET_CONFIG) {
Expand All @@ -11,10 +11,10 @@ if (!SECRET_CONFIG) {
}

// Read the content of the file .env.template
const PUBLIC_CONFIG = fs.readFileSync("config/.env.template", "utf8");
const PUBLIC_CONFIG = fs.readFileSync(".env.template", "utf8");

// Prepend the content of the env variable SECRET_CONFIG
const full_config = `${PUBLIC_CONFIG}\n${SECRET_CONFIG}`;

// Write full_config to .env.local
fs.writeFileSync("config/.env.local", full_config);
fs.writeFileSync(".env.local", full_config);
2 changes: 1 addition & 1 deletion scripts/updateProdEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const MONGODB_URL = process.env.MONGODB_URL;
const HF_TOKEN = process.env.HF_TOKEN ?? process.env.HF_ACCESS_TOKEN; // token used for API requests in prod

// Read the content of the file .env.template
const PUBLIC_CONFIG = fs.readFileSync("config/.env.template", "utf8");
const PUBLIC_CONFIG = fs.readFileSync(".env.template", "utf8");

// Prepend the content of the env variable SECRET_CONFIG
const full_config = `${PUBLIC_CONFIG}
Expand Down
4 changes: 2 additions & 2 deletions svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import adapter from "@sveltejs/adapter-node";
import { vitePreprocess } from "@sveltejs/kit/vite";
import dotenv from "dotenv";

dotenv.config({ path: "./config/.env.local" });
dotenv.config({ path: "./config/.env" });
dotenv.config({ path: "./.env.local" });
dotenv.config({ path: "./.env" });

process.env.PUBLIC_VERSION = process.env.npm_package_version;

Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const defaultTheme = require("tailwindcss/defaultTheme");
const colors = require("tailwindcss/colors");

import dotenv from "dotenv";
dotenv.config({ path: "./config/.env" });
dotenv.config({ path: "./.env" });

/** @type {import('tailwindcss').Config} */
export default {
Expand Down

0 comments on commit 8751c6b

Please sign in to comment.