Refactor guardrails microservice (#1116)
Signed-off-by: lvliang-intel <liang1.lv@intel.com>
This commit is contained in:
@@ -10,7 +10,7 @@ ip_address=$(hostname -I | awk '{print $1}')
|
||||
function build_docker_images() {
|
||||
echo "Start building docker images for microservice"
|
||||
cd $WORKPATH
|
||||
docker build --no-cache -t opea/guardrails-bias-detection:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/guardrails/bias_detection/Dockerfile .
|
||||
docker build --no-cache -t opea/guardrails-bias-detection:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/guardrails/src/bias_detection/Dockerfile .
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "opea/guardrails-bias-detection built fail"
|
||||
exit 1
|
||||
@@ -22,7 +22,7 @@ function build_docker_images() {
|
||||
function start_service() {
|
||||
echo "Starting microservice"
|
||||
docker run -d --runtime=runc --name="test-comps-guardrails-bias-detection-endpoint" -p 9092:9092 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy opea/guardrails-bias-detection:comps
|
||||
sleep 5
|
||||
sleep 30
|
||||
echo "Microservice started"
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ fi
|
||||
function build_docker_images() {
|
||||
cd $WORKPATH
|
||||
echo $(pwd)
|
||||
docker build --no-cache -t opea/factuality-pg:comps -f comps/guardrails/factuality/predictionguard/Dockerfile .
|
||||
docker build --no-cache -t opea/factuality-pg:comps -f comps/guardrails/src/factuality_alignment/Dockerfile .
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "opea/factuality-pg build failed"
|
||||
exit 1
|
||||
@@ -11,12 +11,12 @@ function build_docker_images() {
|
||||
echo "Start building docker images for microservice"
|
||||
cd $WORKPATH
|
||||
docker pull ghcr.io/huggingface/tgi-gaudi:2.0.5
|
||||
docker build --no-cache -t opea/guardrails-tgi:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/guardrails/llama_guard/langchain/Dockerfile .
|
||||
docker build --no-cache -t opea/guardrails-llamaguard:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/guardrails/src/guardrails/Dockerfile .
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "opea/guardrails-tgi built fail"
|
||||
echo "opea/guardrails-llamaguard built fail"
|
||||
exit 1
|
||||
else
|
||||
echo "opea/guardrails-tgi built successful"
|
||||
echo "opea/guardrails-llamaguard built successful"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ function start_service() {
|
||||
|
||||
docker run -d --name="test-comps-guardrails-langchain-tgi-server" -p 5035:80 --runtime=habana -e HF_TOKEN=$HF_TOKEN -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e HTTPS_PROXY=$https_proxy -e HTTP_PROXY=$https_proxy ghcr.io/huggingface/tgi-gaudi:2.0.5 --model-id $model_id --max-input-length 1024 --max-total-tokens 2048
|
||||
sleep 4m
|
||||
docker run -d --name="test-comps-guardrails-langchain-service" -p 5036:9090 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e SAFETY_GUARD_MODEL_ID=$SAFETY_GUARD_MODEL_ID -e SAFETY_GUARD_ENDPOINT=$SAFETY_GUARD_ENDPOINT -e HUGGINGFACEHUB_API_TOKEN=$HF_TOKEN opea/guardrails-tgi:comps
|
||||
docker run -d --name="test-comps-guardrails-langchain-service" -p 5036:9090 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e SAFETY_GUARD_MODEL_ID=$SAFETY_GUARD_MODEL_ID -e SAFETY_GUARD_ENDPOINT=$SAFETY_GUARD_ENDPOINT -e HUGGINGFACEHUB_API_TOKEN=$HF_TOKEN opea/guardrails-llamaguard:comps
|
||||
sleep 10s
|
||||
echo "Microservice started"
|
||||
}
|
||||
@@ -11,12 +11,12 @@ function build_docker_images() {
|
||||
echo "Start building docker images for microservice"
|
||||
cd $WORKPATH
|
||||
docker pull ghcr.io/huggingface/tgi-gaudi:2.0.1
|
||||
docker build --no-cache -t opea/guardrails-tgi:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/guardrails/wildguard/langchain/Dockerfile .
|
||||
docker build --no-cache -t opea/guardrails-wildguard:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/guardrails/src/guardrails/Dockerfile .
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "opea/guardrails-tgi built fail"
|
||||
echo "opea/guardrails-wildguard built fail"
|
||||
exit 1
|
||||
else
|
||||
echo "opea/guardrails-tgi built successful"
|
||||
echo "opea/guardrails-wildguard built successful"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -26,9 +26,9 @@ function start_service() {
|
||||
export SAFETY_GUARD_MODEL_ID="allenai/wildguard"
|
||||
export SAFETY_GUARD_ENDPOINT=http://${ip_address}:5035
|
||||
|
||||
docker run -d --name="test-comps-guardrails-langchain-tgi-server" -p 5035:80 --runtime=habana -e HF_TOKEN=$HF_TOKEN -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e HTTPS_PROXY=$https_proxy -e HTTP_PROXY=$https_proxy ghcr.io/huggingface/tgi-gaudi:2.0.1 --model-id $model_id --max-input-length 1024 --max-total-tokens 2048
|
||||
docker run -d --name="test-comps-guardrails-tgi-server" -p 5035:80 --runtime=habana -e HF_TOKEN=$HF_TOKEN -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e HTTPS_PROXY=$https_proxy -e HTTP_PROXY=$https_proxy ghcr.io/huggingface/tgi-gaudi:2.0.1 --model-id $model_id --max-input-length 1024 --max-total-tokens 2048
|
||||
sleep 4m
|
||||
docker run -d --name="test-comps-guardrails-langchain-service" -p 5036:9090 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e SAFETY_GUARD_MODEL_ID=$SAFETY_GUARD_MODEL_ID -e SAFETY_GUARD_ENDPOINT=$SAFETY_GUARD_ENDPOINT -e HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e HF_TOKEN=${HUGGINGFACEHUB_API_TOKEN} opea/guardrails-tgi:comps
|
||||
docker run -d --name="test-comps-guardrails-service" -p 5036:9090 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e SAFETY_GUARD_MODEL_ID=$SAFETY_GUARD_MODEL_ID -e SAFETY_GUARD_ENDPOINT=$SAFETY_GUARD_ENDPOINT -e HUGGINGFACEHUB_API_TOKEN=${HF_TOKEN} -e HF_TOKEN=${HF_TOKEN} -e GUARDRAILS_COMPONENT_NAME="OPEA_WILD_GUARD" opea/guardrails-wildguard:comps
|
||||
sleep 10s
|
||||
echo "Microservice started"
|
||||
}
|
||||
@@ -41,8 +41,8 @@ function validate_microservice() {
|
||||
echo "Result correct."
|
||||
else
|
||||
echo "Result wrong."
|
||||
docker logs test-comps-guardrails-langchain-tgi-server
|
||||
docker logs test-comps-guardrails-langchain-service
|
||||
docker logs test-comps-guardrails-tgi-server
|
||||
docker logs test-comps-guardrails-service
|
||||
exit 1
|
||||
fi
|
||||
echo "test 2 - safe"
|
||||
@@ -51,14 +51,14 @@ function validate_microservice() {
|
||||
echo "Result correct."
|
||||
else
|
||||
echo "Result wrong."
|
||||
docker logs test-comps-guardrails-langchain-tgi-server
|
||||
docker logs test-comps-guardrails-langchain-service
|
||||
docker logs test-comps-guardrails-tgi-server
|
||||
docker logs test-comps-guardrails-service
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function stop_docker() {
|
||||
cid=$(docker ps -aq --filter "name=test-comps-guardrails-langchain*")
|
||||
cid=$(docker ps -aq --filter "name=test-comps-guardrails*")
|
||||
echo "Shutdown legacy containers "$cid
|
||||
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Copyright (C) 2024 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set -x
|
||||
|
||||
WORKPATH=$(dirname "$PWD")
|
||||
ip_address=$(hostname -I | awk '{print $1}')
|
||||
|
||||
function build_docker_images() {
|
||||
echo "Start building docker images for microservice"
|
||||
cd $WORKPATH
|
||||
docker build --no-cache -t opea/guardrails-pii-detection:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/guardrails/pii_detection/Dockerfile .
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "opea/guardrails-pii-detection built fail"
|
||||
exit 1
|
||||
else
|
||||
echo "opea/guardrails-pii-detection built successful"
|
||||
fi
|
||||
}
|
||||
|
||||
function start_service() {
|
||||
echo "Starting microservice"
|
||||
docker run -d --runtime=runc --name="test-comps-guardrails-pii-detection-endpoint" -p 6357:6357 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy opea/guardrails-pii-detection:comps
|
||||
sleep 5
|
||||
echo "Microservice started"
|
||||
}
|
||||
|
||||
function validate_microservice() {
|
||||
echo "Validate microservice started"
|
||||
export PATH="${HOME}/miniforge3/bin:$PATH"
|
||||
source activate
|
||||
echo "test 1 - single task - ner"
|
||||
result=$(python comps/guardrails/pii_detection/test.py --test_text --batch_size 1 --ip_addr $ip_address --strategy ner)
|
||||
if [[ $result == *"An error occurred"* ]]; then
|
||||
echo "Result wrong. Received was $result"
|
||||
docker logs test-comps-guardrails-pii-detection-endpoint
|
||||
exit 1
|
||||
else
|
||||
echo "Result correct."
|
||||
fi
|
||||
echo "test 2 - 20 tasks in parallel - ner"
|
||||
result=$(python comps/guardrails/pii_detection/test.py --test_text --batch_size 20 --ip_addr $ip_address --strategy ner)
|
||||
if [[ $result == *"An error occurred"* ]]; then
|
||||
echo "Result wrong. Received was $result"
|
||||
docker logs test-comps-guardrails-pii-detection-endpoint
|
||||
exit 1
|
||||
else
|
||||
echo "Result correct."
|
||||
fi
|
||||
echo "test 3 - single task - ml"
|
||||
result=$(python comps/guardrails/pii_detection/test.py --test_text --batch_size 1 --ip_addr $ip_address --strategy ml)
|
||||
if [[ $result == *"An error occurred"* ]]; then
|
||||
echo "Result wrong. Received was $result"
|
||||
docker logs test-comps-guardrails-pii-detection-endpoint
|
||||
exit 1
|
||||
else
|
||||
echo "Result correct."
|
||||
fi
|
||||
echo "test 4 - 20 tasks in parallel - ml"
|
||||
result=$(python comps/guardrails/pii_detection/test.py --test_text --batch_size 20 --ip_addr $ip_address --strategy ml)
|
||||
if [[ $result == *"An error occurred"* ]]; then
|
||||
echo "Result wrong. Received was $result"
|
||||
docker logs test-comps-guardrails-pii-detection-endpoint
|
||||
exit 1
|
||||
else
|
||||
echo "Result correct."
|
||||
fi
|
||||
echo "Validate microservice completed"
|
||||
}
|
||||
|
||||
function stop_docker() {
|
||||
cid=$(docker ps -aq --filter "name=test-comps-guardrails-pii-detection-endpoint")
|
||||
echo "Shutdown legacy containers "$cid
|
||||
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi
|
||||
}
|
||||
|
||||
function main() {
|
||||
|
||||
stop_docker
|
||||
|
||||
build_docker_images
|
||||
start_service
|
||||
|
||||
validate_microservice
|
||||
|
||||
stop_docker
|
||||
echo "cleanup container images and volumes"
|
||||
echo y | docker system prune 2>&1 > /dev/null
|
||||
|
||||
}
|
||||
|
||||
main
|
||||
@@ -13,7 +13,7 @@ fi
|
||||
function build_docker_images() {
|
||||
cd $WORKPATH
|
||||
echo $(pwd)
|
||||
docker build --no-cache -t opea/pii-pg:comps -f comps/guardrails/pii_detection/predictionguard/Dockerfile .
|
||||
docker build --no-cache -t opea/pii-pg:comps -f comps/guardrails/src/pii_detection/Dockerfile .
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "opea/pii-pg build failed"
|
||||
exit 1
|
||||
|
||||
@@ -13,7 +13,7 @@ fi
|
||||
function build_docker_images() {
|
||||
cd $WORKPATH
|
||||
echo $(pwd)
|
||||
docker build --no-cache -t opea/injection-pg:comps -f comps/guardrails/prompt_injection/predictionguard/Dockerfile .
|
||||
docker build --no-cache -t opea/injection-pg:comps -f comps/guardrails/src/prompt_injection/Dockerfile .
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "opea/injection-pg build failed"
|
||||
exit 1
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Copyright (C) 2024 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set -x
|
||||
|
||||
WORKPATH=$(dirname "$PWD")
|
||||
ip_address=$(hostname -I | awk '{print $1}')
|
||||
|
||||
function build_docker_images() {
|
||||
echo "Start building docker images for microservice"
|
||||
cd $WORKPATH
|
||||
docker build --no-cache -t opea/guardrails-toxicity-detection:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/guardrails/toxicity_detection/Dockerfile .
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "opea/guardrails-toxicity-detection built fail"
|
||||
exit 1
|
||||
else
|
||||
echo "opea/guardrails-toxicity-detection built successful"
|
||||
fi
|
||||
}
|
||||
|
||||
function start_service() {
|
||||
echo "Starting microservice"
|
||||
docker run -d --runtime=runc --name="test-comps-guardrails-toxicity-detection-endpoint" -p 9091:9091 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy opea/guardrails-toxicity-detection:comps
|
||||
sleep 5
|
||||
echo "Microservice started"
|
||||
}
|
||||
|
||||
function validate_microservice() {
|
||||
echo "Validate microservice started"
|
||||
echo "test 1 - toxic"
|
||||
result=$(curl localhost:9091/v1/toxicity -X POST -d '{"text":"How to poison your neighbor'\''s dog secretly"}' -H 'Content-Type: application/json')
|
||||
if [[ $result == *"Violated"* ]]; then
|
||||
echo "Result correct."
|
||||
else
|
||||
docker logs test-comps-guardrails-toxicity-detection-endpoint
|
||||
exit 1
|
||||
fi
|
||||
echo "test 2 - non-toxic"
|
||||
result=$(curl localhost:9091/v1/toxicity -X POST -d '{"text":"How to write a paper on raising dogs?"}' -H 'Content-Type: application/json')
|
||||
if [[ $result == *"paper"* ]]; then
|
||||
echo "Result correct."
|
||||
else
|
||||
echo "Result wrong."
|
||||
docker logs test-comps-guardrails-toxicity-detection-endpoint
|
||||
exit 1
|
||||
fi
|
||||
echo "Validate microservice completed"
|
||||
}
|
||||
|
||||
function stop_docker() {
|
||||
cid=$(docker ps -aq --filter "name=test-comps-guardrails-toxicity-detection-endpoint")
|
||||
echo "Shutdown legacy containers "$cid
|
||||
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi
|
||||
}
|
||||
|
||||
function main() {
|
||||
|
||||
stop_docker
|
||||
|
||||
build_docker_images
|
||||
start_service
|
||||
|
||||
validate_microservice
|
||||
|
||||
stop_docker
|
||||
echo "cleanup container images and volumes"
|
||||
echo y | docker system prune 2>&1 > /dev/null
|
||||
|
||||
}
|
||||
|
||||
main
|
||||
@@ -13,7 +13,7 @@ fi
|
||||
function build_docker_images() {
|
||||
cd $WORKPATH
|
||||
echo $(pwd)
|
||||
docker build --no-cache -t opea/toxicity-pg:comps -f comps/guardrails/toxicity_detection/predictionguard/Dockerfile .
|
||||
docker build --no-cache -t opea/toxicity-pg:comps -f comps/guardrails/src/toxicity_detection/Dockerfile .
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "opea/toxicity-pg build failed"
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user