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
This commit is contained in:
Andy Yen
2024-06-28 13:26:55 +08:00
committed by GitHub
parent 7ad9edc9bc
commit fbb5182f66
5 changed files with 32 additions and 35 deletions
+11 -5
View File
@@ -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`
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`.
+5
View File
@@ -0,0 +1,5 @@
services:
wren-ai-service:
env_file:
- path: ${PROJECT_DIR}/.env.ai
required: true
-3
View File
@@ -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:
-23
View File
@@ -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()
+16 -4
View File
@@ -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,
}