diff --git a/.dockerignore b/.dockerignore index 42d784d60de..f5831adcbed 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,5 +6,5 @@ LICENSE README.md node_modules/ .svelte-kit/ -config/* -!config/.env \ No newline at end of file +.env* +!.env \ No newline at end of file diff --git a/config/.env b/.env similarity index 100% rename from config/.env rename to .env diff --git a/config/.env.ci b/.env.ci similarity index 100% rename from config/.env.ci rename to .env.ci diff --git a/config/.env.template b/.env.template similarity index 100% rename from config/.env.template rename to .env.template diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index 8009827ed35..38992d5d595 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -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 . diff --git a/.gitignore b/.gitignore index c4c552a201e..7e8c5e8f85a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,6 @@ vite.config.js.timestamp-* vite.config.ts.timestamp-* SECRET_CONFIG .idea -!config/.env.ci -!config/.env -!config/.env.template \ No newline at end of file +!.env.ci +!.env +!.env.template \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4f893b62405..a88846db80e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/PROMPTS.md b/PROMPTS.md index 6721f85c1b4..25954eaa64f 100644 --- a/PROMPTS.md +++ b/PROMPTS.md @@ -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 diff --git a/README.md b/README.md index 56699fe898f..67bc7fc9d7d 100644 --- a/README.md +++ b/README.md @@ -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: @@ -45,25 +45,28 @@ MONGODB_URL= HF_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=$( /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 & diff --git a/scripts/updateLocalEnv.ts b/scripts/updateLocalEnv.ts index 4e008f7b4f3..43a94cf15cd 100644 --- a/scripts/updateLocalEnv.ts +++ b/scripts/updateLocalEnv.ts @@ -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) { @@ -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); diff --git a/scripts/updateProdEnv.ts b/scripts/updateProdEnv.ts index 6b2b48c8f45..aae0a638894 100644 --- a/scripts/updateProdEnv.ts +++ b/scripts/updateProdEnv.ts @@ -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} diff --git a/svelte.config.js b/svelte.config.js index 12851d2f76b..e93decaf872 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -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; diff --git a/tailwind.config.cjs b/tailwind.config.cjs index 18a2362e3e0..773347ec02b 100644 --- a/tailwind.config.cjs +++ b/tailwind.config.cjs @@ -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 {