Skip to content

Commit

Permalink
Cli bug fix (#61)
Browse files Browse the repository at this point in the history
* add .env.production when save settings

Signed-off-by: cbh778899 <[email protected]>

* update match case to avoid bugs

Signed-off-by: cbh778899 <[email protected]>

---------

Signed-off-by: cbh778899 <[email protected]>
  • Loading branch information
cbh778899 authored Aug 20, 2024
1 parent b59203e commit 5cdb5f4
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 11 deletions.
12 changes: 6 additions & 6 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ALLOW_ORIGIN=*
ALLOW_ORIGIN="*"
STATIC_API_KEY_ENABLED=0
ENABLE_HTTPS=0
ENABLE_PLUGIN=0
HTTPS_KEY_PATH=*
HTTPS_CERT_PATH=*
HTTPS_CA_PATH=*
SYSTEM_INSTRUCTION=*
AVAILABLE_APIS=ALL
HTTPS_KEY_PATH="*/privkey.pem"
HTTPS_CERT_PATH="*/cert.pem"
HTTPS_CA_PATH="*/chain.pem"
SYSTEM_INSTRUCTION="*"
AVAILABLE_APIS="ALL"
4 changes: 2 additions & 2 deletions docker-compose-adv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
container_name: ${INFERENCE_ENG}
image: gclub/llama.cpp:${INFERENCE_ENG_VERSION}
restart: always
deploy: # https://github.com/compose-spec/compose-spec/blob/master/deploy.md
deploy:
resources:
reservations:
cpus: "${NUM_CPU_CORES}"
Expand All @@ -19,7 +19,7 @@ services:
container_name: ${EMBEDDING_ENG}
image: gclub/llama.cpp:${INFERENCE_ENG_VERSION}
restart: always
deploy: # https://github.com/compose-spec/compose-spec/blob/master/deploy.md
deploy:
resources:
reservations:
cpus: "${NUM_CPU_CORES_EMBEDDING}"
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ if(isRouteEnabled("index", "docs")) {
const PORT = process.env.PORT || 8000
if(
+process.env.ENABLE_HTTPS &&
process.env.HTTPS_KEY_PATH !== "*" &&
process.env.HTTPS_CERT_PATH !== '*'
!process.env.HTTPS_KEY_PATH.startsWith("*") &&
!process.env.HTTPS_CERT_PATH.startsWith("*")
) {
const ssl_options = {
key: readFileSync(process.env.HTTPS_KEY_PATH),
cert: readFileSync(process.env.HTTPS_CERT_PATH)
}
if(process.env.HTTPS_CA_PATH && process.env.HTTPS_CA_PATH !== '*') {
if(process.env.HTTPS_CA_PATH && !process.env.HTTPS_CA_PATH.startsWith("*")) {
ssl_options.ca = readFileSync(process.env.HTTPS_CA_PATH);
}
createServer(ssl_options, app).listen(PORT, '0.0.0.0', () => {
Expand Down
53 changes: 53 additions & 0 deletions setup/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,50 @@ void saveSettings(int show_message) {
);
fclose(f);

// ENV PRODUCTION
int all_apis_available =
api_index_doc_enabled &&
api_index_stats_enabled &&
api_index_healthy_enabled &&
api_inference_comp_enabled &&
api_inference_rag_enabled &&
api_token_enabled &&
api_embedding_calc_enabled &&
api_embedding_ds_enabled &&
api_version_enabled;
char* api_enabled_str;
if(all_apis_available) {
api_enabled_str = "ALL";
} else {
asprintf(&api_enabled_str, AVAILABLE_APIS_FORMAT,
api_index_doc_enabled,
api_index_stats_enabled,
api_index_healthy_enabled,
api_inference_comp_enabled,
api_inference_rag_enabled,
api_token_enabled,
api_embedding_calc_enabled,
api_embedding_ds_enabled,
api_version_enabled
);
}

f = fopen(".env.production", "w");
fprintf(f, ENV_PRODUCTION_FILE,
allow_origin_name,
static_api_key_enabled,
https_enabled,
plugin_enabled,
https_cert_path_container, https_privkey_name,
https_cert_path_container, https_cert_name,
https_cert_path_container, https_ca_name,
system_instruction,
api_enabled_str
);
fclose(f);

if(!all_apis_available) free(api_enabled_str);

// DOCKER-COMPOSE
f = fopen("docker-compose-adv.yaml", "w");
// check if should bind secret volume to host machine
Expand All @@ -618,14 +662,23 @@ void saveSettings(int show_message) {
}
// check if should bind any volume to host machine
int volume_bind_check = dev_mode_enabled || secret_bind_check;

int static_api_key_availibility =
static_api_key_enabled &&
strcmp(static_api_key_value, "*") != 0;

char* static_api_key_str;
if(static_api_key_availibility) asprintf(&static_api_key_str, COMPOSE_FILE_STATIC_API_KEY, static_api_key_value);

fprintf(f, DOCKER_COMPOSE_FILE,
static_api_key_availibility ? static_api_key_str : "",
volume_bind_check ? COMPOSE_FILE_VOLUME_SECTION : "",
dev_mode_enabled ? COMPOSE_FILE_DEV_MODE : "",
secret_bind_check ? docker_compose_ssl_str : ""
);

if(secret_bind_check) free(docker_compose_ssl_str);
if(static_api_key_availibility) free(static_api_key_str);
fclose(f);

// DOCKERFILE
Expand Down
18 changes: 18 additions & 0 deletions setup/setup_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@
" build:\n"\
" dockerfile: setup/Dockerfile\n"\
" context: .\n"\
"%s"\
"%s%s%s"\
" expose:\n"\
" - ${APP_EXPOSE_PORT}\n"\
Expand All @@ -550,11 +551,15 @@

#define COMPOSE_FILE_VOLUME_SECTION " volumes:\n"
#define COMPOSE_FILE_DEV_MODE " - .:/app\n"
#define COMPOSE_FILE_STATIC_API_KEY \
" environment:\n"\
" - STATIC_API_KEY=%s\n"
#define COMPOSE_FILE_SSL_INFO \
" - %s/%s:%s/%s\n"\
" - %s/%s:%s/%s\n"\
" - %s/%s:%s/%s\n"


#define ENV_FILE \
"APP_PORT=8000\n"\
"APP_EXPOSE_PORT=%s\n"\
Expand All @@ -572,6 +577,19 @@
"LANGUAGE_MODEL_NAME=%s\n"\
"EMBEDDING_MODEL_NAME=all-MiniLM-L6-v2-Q4_K_M-v2.gguf\n"\

#define ENV_PRODUCTION_FILE \
"ALLOW_ORIGIN=\"%s\"\n"\
"STATIC_API_KEY_ENABLED=%d\n"\
"ENABLE_HTTPS=%d\n"\
"ENABLE_PLUGIN=%d\n"\
"HTTPS_KEY_PATH=\"%s/%s\"\n"\
"HTTPS_CERT_PATH=\"%s/%s\"\n"\
"HTTPS_CA_PATH=\"%s/%s\"\n"\
"SYSTEM_INSTRUCTION=\"%s\"\n"\
"AVAILABLE_APIS=\"%s\""

#define AVAILABLE_APIS_FORMAT "%d%d%d.%d%d.%d.%d%d.%d"

#define DOCKERFILE \
"FROM node:20.15.1-slim\n"\
"WORKDIR /app\n"\
Expand Down

0 comments on commit 5cdb5f4

Please sign in to comment.