Skip to content

Commit

Permalink
fix working local
Browse files Browse the repository at this point in the history
update Dockerfiles
update automation also for podman usage
update initial user / apikey
add logging to application
add new folder for example uploadfile
  • Loading branch information
thomassuedbroecker committed Feb 21, 2024
1 parent 9baad9f commit e3b31b5
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 67 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```

Expand Down Expand Up @@ -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
```

Expand Down
5 changes: 3 additions & 2 deletions code/.env-template
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export CUSTOM_MODEL_PROMPT="Code:\n\n<<CONTEXT>>\n\nQuestion:\n\n<<QUESTION>>\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
11 changes: 7 additions & 4 deletions code/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions code/docker/Dockerfile.optimized
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 27 additions & 1 deletion code/modules/load_env.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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")):
Expand All @@ -189,7 +214,8 @@ def load_apikey_env():
authenicationStatus = True

authenicationJSON = { "USER": USER,
"APIKEY":APIKEY
"APIKEY":APIKEY,
"APPLOG":APPLOG
}
print(authenicationJSON)

Expand Down
78 changes: 41 additions & 37 deletions code/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions code/simple-qa-pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
19 changes: 11 additions & 8 deletions scripts/ce-deployment/deploy-to-code-engine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"

Expand All @@ -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
Expand Down
File renamed without changes.

0 comments on commit e3b31b5

Please sign in to comment.