diff --git a/.gitignore b/.gitignore index e4bb97b..cbedad5 100644 --- a/.gitignore +++ b/.gitignore @@ -168,9 +168,11 @@ configmap_values.txt # additional simple-pipeline-env-3.11 +simple-pipeline-env-3 .env .DS_Store documentation/~$live-stream.pptx .vscode/launch.json additional_notes.md assistant/additional_information/ +code/.env_backup diff --git a/README.md b/README.md index d02c5b3..2b9442d 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,8 @@ git clone https://github.com/thomassuedbroecker/simple-pipeline.git ```sh cd simple-pipeline/code -python3.11 -m venv simple-pipeline-env-3.11 -source ./simple-pipeline-env-3.11/bin/activate +python3 -m venv simple-pipeline-env-3 +source ./simple-pipeline-env-3/bin/activate ``` * Install needed Python libs and create a `requirements.txt` file @@ -42,19 +42,24 @@ python3 -m pip install --upgrade pip python3 -m pip install "fastapi[all]" python3 -m pip install requests python3 -m pip install pydantic -python3 -m pip install touch -#python3 -m pip install pytorch #Only with GPU -python3 -m pip install torch torchvision +python3 -m pip install torch python3 -m pip install accelerate -python3 -m pip install auto-gptq python3 -m pip install typing python3 -m pip install transformers -python3 -m pip install git+https://github.com/huggingface/transformers -python3 -m pip freeze > requirements.txt +#python3 -m pip install git+https://github.com/huggingface/transformers ``` +* Save your configuration in requirements.txt + ```sh python3 -m pip install --upgrade pip +python3 -m pip freeze > requirements.txt +deactivate +``` + +* Install from configuration from requirements.txt + +```sh python3 -m pip install -r requirements.txt ``` @@ -94,14 +99,15 @@ export IBMCLOUD_APIKEY= # APP export APP_USER=admin export APP_APIKEY=admin +export APPLOG=INFO ``` ### 3.3 Run `simple-qa-pipeline` server ```sh cd code -source ./simple-pipeline-env-3.11/bin/activate -source .env +source ./simple-pipeline-env-3/bin/activate +source ./.env python3 simple-qa-pipeline.py ``` diff --git a/code/.env-template b/code/.env-template index 92b5322..b0dd515 100644 --- a/code/.env-template +++ b/code/.env-template @@ -22,5 +22,6 @@ export CUSTOM_MODEL_PROMPT="Code:\n\n<>\n\nQuestion:\n\n<>\n\ export IBMCLOUD_APIKEY= export IBMCLOUD_URL=https://iam.cloud.ibm.com/identity/token # APP -export APP_USER=admin -export APP_APIKEY=admin +export APP_USER=adm +export APP_APIKEY=admin123 +export APPLOG=INFO diff --git a/code/docker/Dockerfile b/code/docker/Dockerfile index b4ead61..e05f151 100644 --- a/code/docker/Dockerfile +++ b/code/docker/Dockerfile @@ -2,10 +2,13 @@ FROM python:3.11.2-slim-buster # Install needed environment RUN apt-get -y update; apt-get -y install curl -RUN python -m pip install --upgrade pip -RUN python -m pip install "fastapi[all]" -RUN python -m pip install requests -RUN python -m pip install pydantic +RUN python3 -m pip install --upgrade pip +RUN python3 -m pip install "fastapi[all]" +RUN python3 -m pip install requests +RUN python3 -m pip install pydantic +RUN python3 -m pip install torch +RUN python3 -m pip install accelerate +RUN python3 -m pip install transformers #RUN python -m pip freeze > requirements.txt RUN addgroup simple_qa_pipeline_group diff --git a/code/docker/Dockerfile.optimized b/code/docker/Dockerfile.optimized index 3292e2a..3f21c8c 100644 --- a/code/docker/Dockerfile.optimized +++ b/code/docker/Dockerfile.optimized @@ -6,11 +6,14 @@ FROM python:3.11.2-slim-buster as BUILDER_IMAGE WORKDIR /app # Install needed environment -RUN python -m pip install --upgrade pip -RUN python -m pip install requests -RUN python -m pip install "fastapi[all]" -RUN python -m pip install pydantic - +RUN apt-get -y update; apt-get -y install curl +RUN python3 -m pip install --upgrade pip +RUN python3 -m pip install "fastapi[all]" +RUN python3 -m pip install requests +RUN python3 -m pip install pydantic +RUN python3 -m pip install torch +RUN python3 -m pip install accelerate +RUN python3 -m pip install transformers # Create modeles folder RUN mkdir modules diff --git a/code/modules/load_env.py b/code/modules/load_env.py index bfd708d..c0cafab 100644 --- a/code/modules/load_env.py +++ b/code/modules/load_env.py @@ -1,4 +1,24 @@ import os +import logging +import sys + +################################## +# Configure Logging +# load config +if (os.environ.get("APP_LOG") == None): + APPLOG = "INFO" +else: + APPLOG = os.environ.get("APP_LOG") + +# set logging +if (str(APPLOG)=="DEBUG"): + logging.basicConfig(stream=sys.stdout,level=logging.DEBUG) +elif (str(APPLOG)=="INFO"): + logging.basicConfig(stream=sys.stdout,level=logging.INFO) +elif (str(APPLOG)=="WARNING"): + logging.basicConfig(stream=sys.stdout,level=logging.WARNING) +else: + logging.basicConfig(stream=sys.stdout,level=logging.INFO) def load_ibmcloud_env(): if (os.environ.get("IBMCLOUD_APIKEY") == None): @@ -181,6 +201,11 @@ def load_apikey_env(): APIKEY = "apikey" else: APIKEY = os.environ.get("APP_APIKEY") + + if (os.environ.get("APPLOG") == None): + APPLOG = "INFO" + else: + APPLOG = os.environ.get("APPLOG") if ((USER=="admin") or (APIKEY=="apikey")): @@ -189,7 +214,8 @@ def load_apikey_env(): authenicationStatus = True authenicationJSON = { "USER": USER, - "APIKEY":APIKEY + "APIKEY":APIKEY, + "APPLOG":APPLOG } print(authenicationJSON) diff --git a/code/requirements.txt b/code/requirements.txt index 69f4e76..0529b6d 100644 --- a/code/requirements.txt +++ b/code/requirements.txt @@ -1,47 +1,51 @@ -annotated-types==0.5.0 -anyio==3.7.1 -certifi==2023.5.7 -charset-normalizer==3.2.0 -click==8.1.6 -dnspython==2.4.0 -email-validator==2.0.0.post2 -fastapi==0.100.0 +accelerate==0.27.2 +annotated-types==0.6.0 +anyio==4.3.0 +certifi==2024.2.2 +charset-normalizer==3.3.2 +click==8.1.7 +dnspython==2.6.1 +email-validator==2.1.0.post1 +fastapi==0.109.2 filelock==3.13.1 -fsspec==2023.12.2 +fsspec==2024.2.0 h11==0.14.0 -httpcore==0.17.3 -httptools==0.6.0 -httpx==0.24.1 +httpcore==1.0.3 +httptools==0.6.1 +httpx==0.26.0 huggingface-hub==0.20.3 -idna==3.4 +idna==3.6 itsdangerous==2.1.2 -Jinja2==3.1.2 -MarkupSafe==2.1.3 -numpy==1.26.3 -orjson==3.9.2 +Jinja2==3.1.3 +MarkupSafe==2.1.5 +mpmath==1.3.0 +networkx==3.2.1 +numpy==1.26.4 +orjson==3.9.14 packaging==23.2 -pydantic==2.0.3 -pydantic-extra-types==2.0.0 -pydantic-settings==2.0.2 -pydantic_core==2.3.0 -python-dotenv==1.0.0 -python-multipart==0.0.6 +psutil==5.9.8 +pydantic==2.6.1 +pydantic-extra-types==2.5.0 +pydantic-settings==2.2.1 +pydantic_core==2.16.2 +python-dotenv==1.0.1 +python-multipart==0.0.9 PyYAML==6.0.1 regex==2023.12.25 requests==2.31.0 -safetensors==0.4.1 +safetensors==0.4.2 sniffio==1.3.0 -starlette==0.27.0 -tokenizers==0.15.0 -touch==2020.12.3 -tqdm==4.66.1 -transformers==4.37.0 +starlette==0.36.3 +sympy==1.12 +tokenizers==0.15.2 +torch==2.2.0 +tqdm==4.66.2 +transformers==4.37.2 typing==3.7.4.3 -typing_extensions==4.7.1 -ujson==5.8.0 -urllib3==2.0.4 -uvicorn==0.23.1 -uvloop==0.17.0 -values==2020.12.3 -watchfiles==0.19.0 -websockets==11.0.3 +typing_extensions==4.9.0 +ujson==5.9.0 +urllib3==2.2.1 +uvicorn==0.27.1 +uvloop==0.19.0 +watchfiles==0.21.0 +websockets==12.0 diff --git a/code/simple-qa-pipeline.py b/code/simple-qa-pipeline.py index 51b4e96..1a9cc5f 100644 --- a/code/simple-qa-pipeline.py +++ b/code/simple-qa-pipeline.py @@ -3,6 +3,9 @@ from fastapi.security import HTTPBasic, HTTPBasicCredentials from starlette.status import HTTP_401_UNAUTHORIZED from fastapi.openapi.utils import get_openapi +import logging +import sys + ################################## # Custom modules from modules.load_env import load_watson_discovery_env, load_apikey_env, load_watson_x_env @@ -14,6 +17,18 @@ from modules.requests_watsonx_deployments import get_answer_from_watsonx_deployment from modules.requests_local_custom_model import custom_model_simple_prompt +################################## +# Configure Logging +log_config, log_validation = load_apikey_env() +if (str(log_config["APPLOG"])=="DEBUG"): + logging.basicConfig(stream=sys.stdout,level=logging.DEBUG) +elif (str(log_config["APPLOG"])=="INFO"): + logging.basicConfig(stream=sys.stdout,level=logging.INFO) +elif (str(log_config["APPLOG"])=="WARNING"): + logging.basicConfig(stream=sys.stdout,level=logging.WARNING) +else: + logging.basicConfig(stream=sys.stdout,level=logging.INFO) + ################################## # Set basic auth as security security = HTTPBasic() diff --git a/scripts/ce-deployment/deploy-to-code-engine.sh b/scripts/ce-deployment/deploy-to-code-engine.sh index 833c9d1..e7284c7 100644 --- a/scripts/ce-deployment/deploy-to-code-engine.sh +++ b/scripts/ce-deployment/deploy-to-code-engine.sh @@ -15,6 +15,9 @@ export REUSE_REPO_URL=${3:-"no_repo_url_id"} export REUSE_REPO_ENV_NAME=${4:-"no_env_file_name"} export REUSE="false" +#export ENGINE=docker +export ENGINE=podman + # Optional to change export CODEENGINE_CR_ACCESS_NAME=$CR export CODEENGINE_CR_SERVER_NAME=$CR @@ -36,11 +39,11 @@ export FOLDERNAME="" # ********************************************************************************** function check_docker () { - ERROR=$(docker ps 2>&1) + ERROR=$(${ENGINE} ps 2>&1) RESULT=$(echo $ERROR | grep 'Cannot' | awk '{print $1;}') VERIFY="Cannot" if [ "$RESULT" == "$VERIFY" ]; then - echo "Docker is not running. Stop script execution." + echo "${ENGINE} is not running. Stop script execution." exit 1 fi } @@ -96,7 +99,7 @@ function build_and_push_container () { # 3. Build container image echo "****** BUILD *********" cd "$HOME_PATH"/../../code - docker build -f "$HOME_PATH"/../../code/docker/"$QA_DOCKERFILE_NAME" -t "$CODEENGINE_APP_IMAGE_URL" . + ${ENGINE} build -f "$HOME_PATH"/../../code/docker/"$QA_DOCKERFILE_NAME" -t "$CODEENGINE_APP_IMAGE_URL" . cd "$HOME_PATH" # 4. Login to IBM Cloud Container Registry @@ -122,8 +125,8 @@ function build_and_push_container () { # 8. Create new container image if it doesn't exists CURR_CONTAINER_IMAGE=$(ibmcloud cr image-list | grep $CI_TAG | awk '{print $2;}') if [ "$CI_TAG" != "$CURR_CONTAINER_IMAGE" ]; then - docker login -u iamapikey -p $IBM_CLOUD_API_KEY $CR_REGION - docker push "$CODEENGINE_APP_IMAGE_URL" + ${ENGINE} login -u iamapikey -p $IBM_CLOUD_API_KEY $CR_REGION + ${ENGINE} push "$CODEENGINE_APP_IMAGE_URL" else echo "Container exists: ($CODEENGINE_APP_IMAGE_URL)" fi @@ -334,7 +337,7 @@ function build_and_push_container_reuse () { # Build from restore code cd "$TEMP_REUSE_FOLDER"/simple-qa-pipeline/code - docker build -f "$TEMP_REUSE_FOLDER"/simple-qa-pipeline/code/docker/"$QA_DOCKERFILE_NAME" -t "$CODEENGINE_APP_IMAGE_URL" . + ${ENGINE} build -f "$TEMP_REUSE_FOLDER"/simple-qa-pipeline/code/docker/"$QA_DOCKERFILE_NAME" -t "$CODEENGINE_APP_IMAGE_URL" . cd "$HOME_PATH" @@ -360,8 +363,8 @@ function build_and_push_container_reuse () { # Create new container image if it doesn't exists CURR_CONTAINER_IMAGE=$(ibmcloud cr image-list | grep $CI_TAG | awk '{print $2;}') if [ "$CI_TAG" != "$CURR_CONTAINER_IMAGE" ]; then - docker login -u iamapikey -p $IBM_CLOUD_API_KEY $CR_REGION - docker push "$CODEENGINE_APP_IMAGE_URL" + ${ENGINE} login -u iamapikey -p $IBM_CLOUD_API_KEY $CR_REGION + ${ENGINE} push "$CODEENGINE_APP_IMAGE_URL" else echo "Container exists: ($CODEENGINE_APP_IMAGE_URL)" fi diff --git a/example-sql-schema.sql b/uploadfiles/example-sql-schema.sql similarity index 100% rename from example-sql-schema.sql rename to uploadfiles/example-sql-schema.sql