Refactor CodeTrans with GenAIComps Microservices (#115)
Signed-off-by: letonghan <letong.han@intel.com> Signed-off-by: Spycsh <sihan.chen@intel.com> Signed-off-by: lvliang-intel <liang1.lv@intel.com> Co-authored-by: chensuyue <suyue.chen@intel.com>
This commit is contained in:
122
CodeTrans/tests/test_codetrans_on_gaudi.sh
Normal file
122
CodeTrans/tests/test_codetrans_on_gaudi.sh
Normal file
@@ -0,0 +1,122 @@
|
||||
#!/bin/bash
|
||||
# Copyright (C) 2024 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set -x
|
||||
|
||||
WORKPATH=$(dirname "$PWD")
|
||||
LOG_PATH="$WORKPATH/tests"
|
||||
ip_address=$(hostname -I | awk '{print $1}')
|
||||
|
||||
function build_docker_images() {
|
||||
cd $WORKPATH
|
||||
git clone https://github.com/opea-project/GenAIComps.git
|
||||
cd GenAIComps
|
||||
|
||||
docker build -t opea/gen-ai-comps:llm-tgi-gaudi-server -f comps/llms/langchain/docker/Dockerfile .
|
||||
|
||||
docker pull ghcr.io/huggingface/tgi-gaudi:1.2.1
|
||||
|
||||
cd $WORKPATH/microservice/gaudi
|
||||
docker build --no-cache -t opea/gen-ai-comps:codetrans-megaservice-server -f docker/Dockerfile .
|
||||
|
||||
cd $WORKPATH/ui
|
||||
docker build --no-cache -t opea/gen-ai-comps:codetrans-ui-server -f docker/Dockerfile .
|
||||
|
||||
docker images
|
||||
}
|
||||
|
||||
function start_services() {
|
||||
cd $WORKPATH/microservice/gaudi
|
||||
|
||||
export http_proxy=${http_proxy}
|
||||
export https_proxy=${http_proxy}
|
||||
export LLM_MODEL_ID="HuggingFaceH4/mistral-7b-grok"
|
||||
export TGI_LLM_ENDPOINT="http://${ip_address}:8008"
|
||||
export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
|
||||
export MEGA_SERVICE_HOST_IP=${ip_address}
|
||||
export BACKEND_SERVICE_ENDPOINT="http://${ip_address}:7777/v1/codetrans"
|
||||
|
||||
# Start Docker Containers
|
||||
# TODO: Replace the container name with a test-specific name
|
||||
docker compose -f docker_compose.yaml up -d
|
||||
|
||||
sleep 2m # Waits 2 minutes
|
||||
}
|
||||
|
||||
function validate_microservices() {
|
||||
# Check if the microservices are running correctly.
|
||||
# TODO: Any results check required??
|
||||
curl http://${ip_address}:8008/generate \
|
||||
-X POST \
|
||||
-d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17, "do_sample": true}}' \
|
||||
-H 'Content-Type: application/json' > ${LOG_PATH}/generate.log
|
||||
exit_code=$?
|
||||
if [ $exit_code -ne 0 ]; then
|
||||
echo "Microservice failed, please check the logs in artifacts!"
|
||||
docker logs tgi-gaudi-server >> ${LOG_PATH}/generate.log
|
||||
exit 1
|
||||
fi
|
||||
sleep 5s
|
||||
|
||||
curl http://${ip_address}:9000/v1/chat/completions \
|
||||
-X POST \
|
||||
-d '{"query":" ### System: Please translate the following Golang codes into Python codes. ### Original codes: '\'''\'''\''Golang \npackage main\n\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello, World!\");\n '\'''\'''\'' ### Translated codes:"}' \
|
||||
-H 'Content-Type: application/json' > ${LOG_PATH}/completions.log
|
||||
exit_code=$?
|
||||
if [ $exit_code -ne 0 ]; then
|
||||
echo "Microservice failed, please check the logs in artifacts!"
|
||||
docker logs llm-tgi-gaudi-server >> ${LOG_PATH}/completions.log
|
||||
exit 1
|
||||
fi
|
||||
sleep 5s
|
||||
}
|
||||
|
||||
function validate_megaservice() {
|
||||
# Curl the Mega Service
|
||||
curl http://${ip_address}:7777/v1/codetrans -H "Content-Type: application/json" -d '{"language_from": "Golang","language_to": "Python","source_code": "package main\n\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello, World!\");\n}"}' > ${LOG_PATH}/curl_megaservice.log
|
||||
|
||||
echo "Checking response results, make sure the output is reasonable. "
|
||||
local status=false
|
||||
if [[ -f $LOG_PATH/curl_megaservice.log ]] && \
|
||||
[[ $(grep -c "@#\$print" $LOG_PATH/curl_megaservice.log) != 0 ]]; then
|
||||
status=true
|
||||
fi
|
||||
|
||||
if [ $status == false ]; then
|
||||
echo "Response check failed, please check the logs in artifacts!"
|
||||
docker logs codetrans-gaudi-backend-server >> ${LOG_PATH}/curl_megaservice.log
|
||||
exit 1
|
||||
else
|
||||
echo "Response check succeed!"
|
||||
fi
|
||||
|
||||
echo "Checking response format, make sure the output format is acceptable for UI."
|
||||
# TODO
|
||||
}
|
||||
|
||||
function stop_docker() {
|
||||
cd $WORKPATH/microservice/gaudi
|
||||
container_list=$(cat docker_compose.yaml | grep container_name | cut -d':' -f2)
|
||||
for container_name in $container_list; do
|
||||
cid=$(docker ps -aq --filter "name=$container_name")
|
||||
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi
|
||||
done
|
||||
}
|
||||
|
||||
function main() {
|
||||
|
||||
stop_docker
|
||||
|
||||
build_docker_images
|
||||
start_services
|
||||
|
||||
validate_microservices
|
||||
validate_megaservice
|
||||
|
||||
stop_docker
|
||||
echo y | docker system prune
|
||||
|
||||
}
|
||||
|
||||
main
|
||||
106
CodeTrans/tests/test_codetrans_on_xeon.sh
Normal file
106
CodeTrans/tests/test_codetrans_on_xeon.sh
Normal file
@@ -0,0 +1,106 @@
|
||||
#!/bin/bash
|
||||
# Copyright (C) 2024 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set -xe
|
||||
|
||||
|
||||
WORKPATH=$(dirname "$PWD")
|
||||
LOG_PATH="$WORKPATH/tests"
|
||||
ip_address=$(hostname -I | awk '{print $1}')
|
||||
|
||||
function build_docker_images() {
|
||||
cd $WORKPATH
|
||||
git clone https://github.com/opea-project/GenAIComps.git
|
||||
cd GenAIComps
|
||||
|
||||
docker build -t opea/gen-ai-comps:llm-tgi-server -f comps/llms/langchain/docker/Dockerfile .
|
||||
|
||||
cd $WORKPATH/microservice/xeon
|
||||
docker build --no-cache -t opea/gen-ai-comps:codetrans-megaservice-server -f docker/Dockerfile .
|
||||
|
||||
cd $WORKPATH/ui
|
||||
docker build --no-cache -t opea/gen-ai-comps:codetrans-ui-server -f docker/Dockerfile .
|
||||
|
||||
docker images
|
||||
}
|
||||
|
||||
function start_services() {
|
||||
cd $WORKPATH/microservice/xeon
|
||||
export http_proxy=${http_proxy}
|
||||
export https_proxy=${http_proxy}
|
||||
export LLM_MODEL_ID="HuggingFaceH4/mistral-7b-grok"
|
||||
export TGI_LLM_ENDPOINT="http://${ip_address}:8008"
|
||||
export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
|
||||
export MEGA_SERVICE_HOST_IP=${ip_address}
|
||||
export BACKEND_SERVICE_ENDPOINT="http://${ip_address}:7777/v1/codetrans"
|
||||
|
||||
# Start Docker Containers
|
||||
# TODO: Replace the container name with a test-specific name
|
||||
docker compose -f docker_compose.yaml up -d
|
||||
|
||||
sleep 1m
|
||||
}
|
||||
|
||||
function validate_microservices() {
|
||||
curl http://${ip_address}:8008/generate \
|
||||
-X POST \
|
||||
-d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17, "do_sample": true}}' \
|
||||
-H 'Content-Type: application/json' > ${LOG_PATH}/generate.log
|
||||
sleep 5s
|
||||
|
||||
curl http://${ip_address}:9000/v1/chat/completions \
|
||||
-X POST \
|
||||
-d '{"query":" ### System: Please translate the following Golang codes into Python codes. ### Original codes: '\'''\'''\''Golang \npackage main\n\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello, World!\");\n '\'''\'''\'' ### Translated codes:"}' \
|
||||
-H 'Content-Type: application/json' > ${LOG_PATH}/completions.log
|
||||
sleep 5s
|
||||
}
|
||||
|
||||
function validate_megaservice() {
|
||||
# Curl the Mega Service
|
||||
curl http://${ip_address}:7777/v1/codetrans -H "Content-Type: application/json" -d '{"language_from": "Golang","language_to": "Python","source_code": "package main\n\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello, World!\");\n}"}' > ${LOG_PATH}/curl_megaservice.log
|
||||
|
||||
echo "Checking response results, make sure the output is reasonable. "
|
||||
local status=false
|
||||
if [[ -f $LOG_PATH/curl_megaservice.log ]] && \
|
||||
[[ $(grep -c "@#$print" $LOG_PATH/curl_megaservice.log) != 0 ]]; then
|
||||
status=true
|
||||
fi
|
||||
|
||||
if [ $status == false ]; then
|
||||
echo "Response check failed, please check the logs in artifacts!"
|
||||
exit 1
|
||||
else
|
||||
echo "Response check succeed!"
|
||||
fi
|
||||
|
||||
echo "Checking response format, make sure the output format is acceptable for UI."
|
||||
# TODO
|
||||
|
||||
}
|
||||
|
||||
function stop_docker() {
|
||||
cd $WORKPATH/microservice/xeon
|
||||
container_list=$(cat docker_compose.yaml | grep container_name | cut -d':' -f2)
|
||||
for container_name in $container_list; do
|
||||
cid=$(docker ps -aq --filter "name=$container_name")
|
||||
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi
|
||||
done
|
||||
}
|
||||
|
||||
function main() {
|
||||
|
||||
stop_docker
|
||||
|
||||
build_docker_images
|
||||
start_services
|
||||
|
||||
validate_microservices
|
||||
validate_megaservice
|
||||
|
||||
stop_docker
|
||||
echo y | docker system prune
|
||||
|
||||
}
|
||||
|
||||
main
|
||||
Reference in New Issue
Block a user