Skip to content

Commit

Permalink
Refine ChatQnA Test Script (#227)
Browse files Browse the repository at this point in the history
* refine chatqna test script

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* delete comments

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

* modify expected result of embedding

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

* update rerank expected result

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

* update llm expected result

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

* update docker compose yaml

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

* fix conda issue

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

* add log_path for log collection

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

---------

Signed-off-by: letonghan <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
letonghan and pre-commit-ci[bot] authored May 31, 2024
1 parent 5cf70c3 commit 4eb9986
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 219 deletions.
8 changes: 4 additions & 4 deletions ChatQnA/docker/gaudi/docker_compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ services:
LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
LANGCHAIN_PROJECT: "opea-retriever-service"
restart: unless-stopped
tei-xeon-service:
tei-reranking-service:
image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.2
container_name: tei-xeon-server
container_name: tei-reranking-gaudi-server
ports:
- "8808:80"
volumes:
Expand All @@ -99,7 +99,7 @@ services:
image: opea/reranking-tei:latest
container_name: reranking-tei-gaudi-server
depends_on:
- tei-xeon-service
- tei-reranking-service
ports:
- "8000:8000"
ipc: host
Expand Down Expand Up @@ -154,7 +154,7 @@ services:
- tei-embedding-service
- embedding
- retriever
- tei-xeon-service
- tei-reranking-service
- reranking
- tgi-service
- llm
Expand Down
8 changes: 4 additions & 4 deletions ChatQnA/docker/xeon/docker_compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ services:
LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
LANGCHAIN_PROJECT: "opea-retriever-service"
restart: unless-stopped
tei-xeon-service:
tei-reranking-service:
image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.2
container_name: tei-xeon-server
container_name: tei-reranking-server
ports:
- "8808:80"
volumes:
Expand All @@ -95,7 +95,7 @@ services:
image: opea/reranking-tei:latest
container_name: reranking-tei-xeon-server
depends_on:
- tei-xeon-service
- tei-reranking-service
ports:
- "8000:8000"
ipc: host
Expand Down Expand Up @@ -145,7 +145,7 @@ services:
- tei-embedding-service
- embedding
- retriever
- tei-xeon-service
- tei-reranking-service
- reranking
- tgi_service
- llm
Expand Down
199 changes: 91 additions & 108 deletions ChatQnA/tests/test_chatqna_on_gaudi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,130 +73,113 @@ function start_services() {
done
}

function validate_microservices() {
# Check if the microservices are running correctly.
# TODO: Any results check required??
curl ${ip_address}:8090/embed \
-X POST \
-d '{"inputs":"What is Deep Learning?"}' \
-H 'Content-Type: application/json' >${LOG_PATH}/embed.log
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Microservice failed, please check the logs in artifacts!"
docker logs tei-embedding-gaudi-server >>${LOG_PATH}/embed.log
exit 1
fi
sleep 1s

curl http://${ip_address}:6000/v1/embeddings \
-X POST \
-d '{"text":"hello"}' \
-H 'Content-Type: application/json' >${LOG_PATH}/embeddings.log
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Microservice failed, please check the logs in artifacts!"
docker logs embedding-tei-server >>${LOG_PATH}/embeddings.log
exit 1
fi
sleep 1s

export PATH="${HOME}/miniforge3/bin:$PATH"
source activate
test_embedding=$(python -c "import random; embedding = [random.uniform(-1, 1) for _ in range(768)]; print(embedding)")
curl http://${ip_address}:7000/v1/retrieval \
-X POST \
-d '{"text":"test","embedding":${test_embedding}}' \
-H 'Content-Type: application/json' > ${LOG_PATH}/retrieval.log
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Microservice failed, please check the logs in artifacts!"
docker logs retriever-redis-server >>${LOG_PATH}/retrieval.log
exit 1
fi
sleep 1s

curl http://${ip_address}:8808/rerank \
-X POST \
-d '{"query":"What is Deep Learning?", "texts": ["Deep Learning is not...", "Deep learning is..."]}' \
-H 'Content-Type: application/json' >${LOG_PATH}/rerank.log
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Microservice failed, please check the logs in artifacts!"
docker logs tei-xeon-server >>${LOG_PATH}/rerank.log
function validate_services() {
local URL="$1"
local EXPECTED_RESULT="$2"
local SERVICE_NAME="$3"
local DOCKER_NAME="$4"
local INPUT_DATA="$5"

local HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "$INPUT_DATA" -H 'Content-Type: application/json' "$URL")
if [ "$HTTP_STATUS" -eq 200 ]; then
echo "[ $SERVICE_NAME ] HTTP status is 200. Checking content..."

local CONTENT=$(curl -s -X POST -d "$INPUT_DATA" -H 'Content-Type: application/json' "$URL" | tee ${LOG_PATH}/${SERVICE_NAME}.log)

if echo "$CONTENT" | grep -q "$EXPECTED_RESULT"; then
echo "[ $SERVICE_NAME ] Content is as expected."
else
echo "[ $SERVICE_NAME ] Content does not match the expected result: $CONTENT"
docker logs ${DOCKER_NAME} >> ${LOG_PATH}/${SERVICE_NAME}.log
exit 1
fi
else
echo "[ $SERVICE_NAME ] HTTP status is not 200. Received status was $HTTP_STATUS"
docker logs ${DOCKER_NAME} >> ${LOG_PATH}/${SERVICE_NAME}.log
exit 1
fi
sleep 1s
}

curl http://${ip_address}:8000/v1/reranking \
-X POST \
-d '{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}]}' \
-H 'Content-Type: application/json' >${LOG_PATH}/reranking.log
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Microservice failed, please check the logs in artifacts!"
docker logs reranking-tei-gaudi-server >>${LOG_PATH}/reranking.log
exit 1
fi
sleep 1s
function validate_microservices() {
# Check if the microservices are running correctly.

curl http://${ip_address}:8008/generate \
-X POST \
-d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":64, "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 1s
# tei for embedding service
validate_services \
"${ip_address}:8090/embed" \
"\[\[" \
"tei-embedding" \
"tei-embedding-gaudi-server" \
'{"inputs":"What is Deep Learning?"}'

# embedding microservice
validate_services \
"${ip_address}:6000/v1/embeddings" \
'"text":"What is Deep Learning?","embedding":\[' \
"embedding" \
"embedding-tei-server" \
'{"text":"What is Deep Learning?"}'

sleep 1m # retrieval can't curl as expected, try to wait for more time

# retrieval microservice
test_embedding=$(python3 -c "import random; embedding = [random.uniform(-1, 1) for _ in range(768)]; print(embedding)")
validate_services \
"${ip_address}:7000/v1/retrieval" \
" " \
"retrieval" \
"retriever-redis-server" \
"{\"text\":\"What is the revenue of Nike in 2023?\",\"embedding\":${test_embedding}}"

# tei for rerank microservice
validate_services \
"${ip_address}:8808/rerank" \
'{"index":1,"score":' \
"tei-rerank" \
"tei-reranking-gaudi-server" \
'{"query":"What is Deep Learning?", "texts": ["Deep Learning is not...", "Deep learning is..."]}'

# rerank microservice
validate_services \
"${ip_address}:8000/v1/reranking" \
"Deep learning is..." \
"rerank" \
"reranking-tei-gaudi-server" \
'{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}]}'

# tgi for llm service
validate_services \
"${ip_address}:8008/generate" \
"generated_text" \
"tgi-llm" \
"tgi-gaudi-server" \
'{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17, "do_sample": true}}'

# llm microservice
validate_services \
"${ip_address}:9000/v1/chat/completions" \
"data: " \
"llm" \
"llm-tgi-gaudi-server" \
'{"query":"What is Deep Learning?"}'

curl http://${ip_address}:9000/v1/chat/completions \
-X POST \
-d '{"text":"What is Deep Learning?"}' \
-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 1s
}

function validate_megaservice() {
# Curl the Mega Service
curl http://${ip_address}:8888/v1/chatqna -H "Content-Type: application/json" -d '{
"messages": "What is the revenue of Nike in 2023?"}' > ${LOG_PATH}/curl_megaservice.log
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Megaservice failed, please check the logs in artifacts!"
docker logs chatqna-gaudi-backend-server >> ${LOG_PATH}/curl_megaservice.log
exit 1
fi

echo "Checking response results, make sure the output is reasonable. "
local status=false
if [[ -f $LOG_PATH/curl_megaservice.log ]] &&
[[ $(grep -c "billion" $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
validate_services \
"${ip_address}:8888/v1/chatqna" \
"billion" \
"mega-chatqna" \
"chatqna-gaudi-backend-server" \
'{"messages": "What is the revenue of Nike in 2023?"}'

echo "Checking response format, make sure the output format is acceptable for UI."
# TODO
}

function validate_frontend() {
cd $WORKPATH/docker/ui/svelte
local conda_env_name="ChatQnA_e2e"
export PATH=${HOME}/miniconda3/bin/:$PATH
export PATH=${HOME}/miniforge3/bin/:$PATH
conda remove -n ${conda_env_name} --all -y
conda create -n ${conda_env_name} python=3.12 -y
source activate ${conda_env_name}
Expand Down
Loading

0 comments on commit 4eb9986

Please sign in to comment.