From fbb5182f669dfb1d538afbae82aaa9bbbb5137a2 Mon Sep 17 00:00:00 2001 From: Andy Yen <38731840+onlyjackfrost@users.noreply.github.com> Date: Fri, 28 Jun 2024 13:26:55 +0800 Subject: [PATCH] Chore: override compose file if using custom llm (#458) * override compose file if using custom llm * add required flag on llm compose file * update readme --- docker/README.md | 16 +++++++++++----- docker/docker-compose.llm.yaml | 5 +++++ docker/docker-compose.yaml | 3 --- wren-launcher/commands/launch.go | 23 ----------------------- wren-launcher/utils/docker.go | 20 ++++++++++++++++---- 5 files changed, 32 insertions(+), 35 deletions(-) create mode 100644 docker/docker-compose.llm.yaml diff --git a/docker/README.md b/docker/README.md index 3994e87ac..8bb34dbd2 100644 --- a/docker/README.md +++ b/docker/README.md @@ -18,9 +18,15 @@ Path structure as following: ## Network * Check out [Network drivers overview](https://docs.docker.com/network/drivers/) to learn more about `bridge` network driver. -## How to start +## How to start with OpenAI 1. copy `.env.example` to `.env.local` and modify the OpenAI API key. -2. (optional) copy `.env.ai.example` to `.env.ai` and fill in necessary information if you would like to use custom LLM. -3. (optional) if your port 3000 is occupied, you can modify the `HOST_PORT` in `.env.example`. -4. start all services: `docker-compose --env-file .env.local up -d` -5. stop all services: `docker-compose --env-file .env.local down` \ No newline at end of file +2. start all services: `docker-compose --env-file .env.local up -d`. +3. stop all services: `docker-compose --env-file .env.local down`. + +## How to start with custom LLM +1. copy `.env.example` to `.env.local` and modify the OpenAI API key. +2. copy `.env.ai.example` to `.env.ai` and fill in necessary information if you would like to use custom LLM. +3. start all services(with custom LLM): `docker-compose -f docker-compose.yaml -f docker-compose.llm.yaml --env-file .env.local up -d`. +4. start all services(with custom LLM): `docker-compose -f docker-compose.yaml -f docker-compose.llm.yaml --env-file .env.local up -d`. + +>Note: If your port 3000 is occupied, you can modify the `HOST_PORT` in `.env.example`. \ No newline at end of file diff --git a/docker/docker-compose.llm.yaml b/docker/docker-compose.llm.yaml new file mode 100644 index 000000000..c6121851d --- /dev/null +++ b/docker/docker-compose.llm.yaml @@ -0,0 +1,5 @@ +services: + wren-ai-service: + env_file: + - path: ${PROJECT_DIR}/.env.ai + required: true diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 6cbbf70d6..b930216bf 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -63,9 +63,6 @@ services: # sometimes the console won't show print messages, # using PYTHONUNBUFFERED: 1 can fix this PYTHONUNBUFFERED: 1 - env_file: - - path: ${PROJECT_DIR}/.env.ai - required: false networks: - wren depends_on: diff --git a/wren-launcher/commands/launch.go b/wren-launcher/commands/launch.go index 5e82177c5..cb14683e2 100644 --- a/wren-launcher/commands/launch.go +++ b/wren-launcher/commands/launch.go @@ -125,24 +125,6 @@ func isEnvFileValidForCustomLLM(projectDir string) error { return nil } -func renameEnvFileForCustomLLM(projectDir string) error { - // rename .env.ai file to .env.ai.old - envFilePath := path.Join(projectDir, ".env.ai") - - if _, err := os.Stat(envFilePath); err == nil { - newEnvFilePath := path.Join(projectDir, ".env.ai.old") - renameErr := os.Rename(envFilePath, newEnvFilePath) - if renameErr != nil { - return renameErr - } - - return nil - } - - return nil -} - - func Launch() { // recover from panic defer func() { @@ -168,11 +150,6 @@ func Launch() { openaiApiKey := "" openaiGenerationModel := "" if llmProvider == "OpenAI" { - err = renameEnvFileForCustomLLM(projectDir) - if err != nil { - panic(err) - } - // ask for OpenAI API key pterm.Print("\n") openaiApiKey, _ = askForAPIKey() diff --git a/wren-launcher/utils/docker.go b/wren-launcher/utils/docker.go index 928ff2fe5..300e5d3db 100644 --- a/wren-launcher/utils/docker.go +++ b/wren-launcher/utils/docker.go @@ -24,9 +24,10 @@ import ( const ( // please change the version when the version is updated - WREN_PRODUCT_VERSION string = "0.6.0-rc.1" - DOCKER_COMPOSE_YAML_URL string = "https://raw.githubusercontent.com/Canner/WrenAI/" + WREN_PRODUCT_VERSION + "/docker/docker-compose.yaml" - DOCKER_COMPOSE_ENV_URL string = "https://raw.githubusercontent.com/Canner/WrenAI/" + WREN_PRODUCT_VERSION + "/docker/.env.example" + WREN_PRODUCT_VERSION string = "0.6.0-rc.1" + DOCKER_COMPOSE_YAML_URL string = "https://raw.githubusercontent.com/Canner/WrenAI/" + WREN_PRODUCT_VERSION + "/docker/docker-compose.yaml" + DOCKER_COMPOSE_LLM_YAML_URL string = "https://raw.githubusercontent.com/Canner/WrenAI/" + WREN_PRODUCT_VERSION + "/docker/docker-compose.llm.yaml" + DOCKER_COMPOSE_ENV_URL string = "https://raw.githubusercontent.com/Canner/WrenAI/" + WREN_PRODUCT_VERSION + "/docker/.env.example" // pg user PG_USERNAME string = "wren-user" @@ -166,6 +167,14 @@ func PrepareDockerFiles(openaiApiKey string, openaiGenerationModel string, hostP return err } + // download docker-compose.llm.yaml file + composeLLMFile := path.Join(projectDir, "docker-compose.llm.yaml") + pterm.Info.Println("Downloading docker-compose.llm file to", composeLLMFile) + err = downloadFile(composeLLMFile, DOCKER_COMPOSE_LLM_YAML_URL) + if err != nil { + return err + } + pg_pwd, err := getPGPassword(WrenRC{projectDir}) if err != nil { return err @@ -227,10 +236,13 @@ func RunDockerCompose(projectName string, projectDir string, llmProvider string) composeFilePath := path.Join(projectDir, "docker-compose.yaml") envFile := path.Join(projectDir, ".env") envFiles := []string{envFile} + configPaths := []string{composeFilePath} if llmProvider == "Custom" { customEnvFile := path.Join(projectDir, ".env.ai") + llmComposeFile := path.Join(projectDir, "docker-compose.llm.yaml") envFiles = append(envFiles, customEnvFile) + configPaths = append(configPaths, llmComposeFile) } // docker-compose up @@ -256,7 +268,7 @@ func RunDockerCompose(projectName string, projectDir string, llmProvider string) // Create a default project options struct projectOptions := cmdCompose.ProjectOptions{ ProjectName: projectName, - ConfigPaths: []string{composeFilePath}, + ConfigPaths: configPaths, WorkDir: projectDir, EnvFiles: envFiles, }