Skip to content

Commit 4eb9986

Browse files
Refine ChatQnA Test Script (#227)
* 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>
1 parent 5cf70c3 commit 4eb9986

File tree

4 files changed

+188
-219
lines changed

4 files changed

+188
-219
lines changed

ChatQnA/docker/gaudi/docker_compose.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ services:
8383
LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
8484
LANGCHAIN_PROJECT: "opea-retriever-service"
8585
restart: unless-stopped
86-
tei-xeon-service:
86+
tei-reranking-service:
8787
image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.2
88-
container_name: tei-xeon-server
88+
container_name: tei-reranking-gaudi-server
8989
ports:
9090
- "8808:80"
9191
volumes:
@@ -99,7 +99,7 @@ services:
9999
image: opea/reranking-tei:latest
100100
container_name: reranking-tei-gaudi-server
101101
depends_on:
102-
- tei-xeon-service
102+
- tei-reranking-service
103103
ports:
104104
- "8000:8000"
105105
ipc: host
@@ -154,7 +154,7 @@ services:
154154
- tei-embedding-service
155155
- embedding
156156
- retriever
157-
- tei-xeon-service
157+
- tei-reranking-service
158158
- reranking
159159
- tgi-service
160160
- llm

ChatQnA/docker/xeon/docker_compose.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ services:
7979
LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
8080
LANGCHAIN_PROJECT: "opea-retriever-service"
8181
restart: unless-stopped
82-
tei-xeon-service:
82+
tei-reranking-service:
8383
image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.2
84-
container_name: tei-xeon-server
84+
container_name: tei-reranking-server
8585
ports:
8686
- "8808:80"
8787
volumes:
@@ -95,7 +95,7 @@ services:
9595
image: opea/reranking-tei:latest
9696
container_name: reranking-tei-xeon-server
9797
depends_on:
98-
- tei-xeon-service
98+
- tei-reranking-service
9999
ports:
100100
- "8000:8000"
101101
ipc: host
@@ -145,7 +145,7 @@ services:
145145
- tei-embedding-service
146146
- embedding
147147
- retriever
148-
- tei-xeon-service
148+
- tei-reranking-service
149149
- reranking
150150
- tgi_service
151151
- llm

ChatQnA/tests/test_chatqna_on_gaudi.sh

Lines changed: 91 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -73,130 +73,113 @@ function start_services() {
7373
done
7474
}
7575

76-
function validate_microservices() {
77-
# Check if the microservices are running correctly.
78-
# TODO: Any results check required??
79-
curl ${ip_address}:8090/embed \
80-
-X POST \
81-
-d '{"inputs":"What is Deep Learning?"}' \
82-
-H 'Content-Type: application/json' >${LOG_PATH}/embed.log
83-
exit_code=$?
84-
if [ $exit_code -ne 0 ]; then
85-
echo "Microservice failed, please check the logs in artifacts!"
86-
docker logs tei-embedding-gaudi-server >>${LOG_PATH}/embed.log
87-
exit 1
88-
fi
89-
sleep 1s
90-
91-
curl http://${ip_address}:6000/v1/embeddings \
92-
-X POST \
93-
-d '{"text":"hello"}' \
94-
-H 'Content-Type: application/json' >${LOG_PATH}/embeddings.log
95-
exit_code=$?
96-
if [ $exit_code -ne 0 ]; then
97-
echo "Microservice failed, please check the logs in artifacts!"
98-
docker logs embedding-tei-server >>${LOG_PATH}/embeddings.log
99-
exit 1
100-
fi
101-
sleep 1s
102-
103-
export PATH="${HOME}/miniforge3/bin:$PATH"
104-
source activate
105-
test_embedding=$(python -c "import random; embedding = [random.uniform(-1, 1) for _ in range(768)]; print(embedding)")
106-
curl http://${ip_address}:7000/v1/retrieval \
107-
-X POST \
108-
-d '{"text":"test","embedding":${test_embedding}}' \
109-
-H 'Content-Type: application/json' > ${LOG_PATH}/retrieval.log
110-
exit_code=$?
111-
if [ $exit_code -ne 0 ]; then
112-
echo "Microservice failed, please check the logs in artifacts!"
113-
docker logs retriever-redis-server >>${LOG_PATH}/retrieval.log
114-
exit 1
115-
fi
116-
sleep 1s
117-
118-
curl http://${ip_address}:8808/rerank \
119-
-X POST \
120-
-d '{"query":"What is Deep Learning?", "texts": ["Deep Learning is not...", "Deep learning is..."]}' \
121-
-H 'Content-Type: application/json' >${LOG_PATH}/rerank.log
122-
exit_code=$?
123-
if [ $exit_code -ne 0 ]; then
124-
echo "Microservice failed, please check the logs in artifacts!"
125-
docker logs tei-xeon-server >>${LOG_PATH}/rerank.log
76+
function validate_services() {
77+
local URL="$1"
78+
local EXPECTED_RESULT="$2"
79+
local SERVICE_NAME="$3"
80+
local DOCKER_NAME="$4"
81+
local INPUT_DATA="$5"
82+
83+
local HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "$INPUT_DATA" -H 'Content-Type: application/json' "$URL")
84+
if [ "$HTTP_STATUS" -eq 200 ]; then
85+
echo "[ $SERVICE_NAME ] HTTP status is 200. Checking content..."
86+
87+
local CONTENT=$(curl -s -X POST -d "$INPUT_DATA" -H 'Content-Type: application/json' "$URL" | tee ${LOG_PATH}/${SERVICE_NAME}.log)
88+
89+
if echo "$CONTENT" | grep -q "$EXPECTED_RESULT"; then
90+
echo "[ $SERVICE_NAME ] Content is as expected."
91+
else
92+
echo "[ $SERVICE_NAME ] Content does not match the expected result: $CONTENT"
93+
docker logs ${DOCKER_NAME} >> ${LOG_PATH}/${SERVICE_NAME}.log
94+
exit 1
95+
fi
96+
else
97+
echo "[ $SERVICE_NAME ] HTTP status is not 200. Received status was $HTTP_STATUS"
98+
docker logs ${DOCKER_NAME} >> ${LOG_PATH}/${SERVICE_NAME}.log
12699
exit 1
127100
fi
128101
sleep 1s
102+
}
129103

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

142-
curl http://${ip_address}:8008/generate \
143-
-X POST \
144-
-d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":64, "do_sample": true}}' \
145-
-H 'Content-Type: application/json' >${LOG_PATH}/generate.log
146-
exit_code=$?
147-
if [ $exit_code -ne 0 ]; then
148-
echo "Microservice failed, please check the logs in artifacts!"
149-
docker logs tgi-gaudi-server >>${LOG_PATH}/generate.log
150-
exit 1
151-
fi
152-
sleep 1s
107+
# tei for embedding service
108+
validate_services \
109+
"${ip_address}:8090/embed" \
110+
"\[\[" \
111+
"tei-embedding" \
112+
"tei-embedding-gaudi-server" \
113+
'{"inputs":"What is Deep Learning?"}'
114+
115+
# embedding microservice
116+
validate_services \
117+
"${ip_address}:6000/v1/embeddings" \
118+
'"text":"What is Deep Learning?","embedding":\[' \
119+
"embedding" \
120+
"embedding-tei-server" \
121+
'{"text":"What is Deep Learning?"}'
122+
123+
sleep 1m # retrieval can't curl as expected, try to wait for more time
124+
125+
# retrieval microservice
126+
test_embedding=$(python3 -c "import random; embedding = [random.uniform(-1, 1) for _ in range(768)]; print(embedding)")
127+
validate_services \
128+
"${ip_address}:7000/v1/retrieval" \
129+
" " \
130+
"retrieval" \
131+
"retriever-redis-server" \
132+
"{\"text\":\"What is the revenue of Nike in 2023?\",\"embedding\":${test_embedding}}"
133+
134+
# tei for rerank microservice
135+
validate_services \
136+
"${ip_address}:8808/rerank" \
137+
'{"index":1,"score":' \
138+
"tei-rerank" \
139+
"tei-reranking-gaudi-server" \
140+
'{"query":"What is Deep Learning?", "texts": ["Deep Learning is not...", "Deep learning is..."]}'
141+
142+
# rerank microservice
143+
validate_services \
144+
"${ip_address}:8000/v1/reranking" \
145+
"Deep learning is..." \
146+
"rerank" \
147+
"reranking-tei-gaudi-server" \
148+
'{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}]}'
149+
150+
# tgi for llm service
151+
validate_services \
152+
"${ip_address}:8008/generate" \
153+
"generated_text" \
154+
"tgi-llm" \
155+
"tgi-gaudi-server" \
156+
'{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17, "do_sample": true}}'
157+
158+
# llm microservice
159+
validate_services \
160+
"${ip_address}:9000/v1/chat/completions" \
161+
"data: " \
162+
"llm" \
163+
"llm-tgi-gaudi-server" \
164+
'{"query":"What is Deep Learning?"}'
153165

154-
curl http://${ip_address}:9000/v1/chat/completions \
155-
-X POST \
156-
-d '{"text":"What is Deep Learning?"}' \
157-
-H 'Content-Type: application/json' >${LOG_PATH}/completions.log
158-
exit_code=$?
159-
if [ $exit_code -ne 0 ]; then
160-
echo "Microservice failed, please check the logs in artifacts!"
161-
docker logs llm-tgi-gaudi-server >>${LOG_PATH}/completions.log
162-
exit 1
163-
fi
164-
sleep 1s
165166
}
166167

167168
function validate_megaservice() {
168169
# Curl the Mega Service
169-
curl http://${ip_address}:8888/v1/chatqna -H "Content-Type: application/json" -d '{
170-
"messages": "What is the revenue of Nike in 2023?"}' > ${LOG_PATH}/curl_megaservice.log
171-
exit_code=$?
172-
if [ $exit_code -ne 0 ]; then
173-
echo "Megaservice failed, please check the logs in artifacts!"
174-
docker logs chatqna-gaudi-backend-server >> ${LOG_PATH}/curl_megaservice.log
175-
exit 1
176-
fi
177-
178-
echo "Checking response results, make sure the output is reasonable. "
179-
local status=false
180-
if [[ -f $LOG_PATH/curl_megaservice.log ]] &&
181-
[[ $(grep -c "billion" $LOG_PATH/curl_megaservice.log) != 0 ]]; then
182-
status=true
183-
fi
184-
185-
if [ $status == false ]; then
186-
echo "Response check failed, please check the logs in artifacts!"
187-
exit 1
188-
else
189-
echo "Response check succeed!"
190-
fi
170+
validate_services \
171+
"${ip_address}:8888/v1/chatqna" \
172+
"billion" \
173+
"mega-chatqna" \
174+
"chatqna-gaudi-backend-server" \
175+
'{"messages": "What is the revenue of Nike in 2023?"}'
191176

192-
echo "Checking response format, make sure the output format is acceptable for UI."
193-
# TODO
194177
}
195178

196179
function validate_frontend() {
197180
cd $WORKPATH/docker/ui/svelte
198181
local conda_env_name="ChatQnA_e2e"
199-
export PATH=${HOME}/miniconda3/bin/:$PATH
182+
export PATH=${HOME}/miniforge3/bin/:$PATH
200183
conda remove -n ${conda_env_name} --all -y
201184
conda create -n ${conda_env_name} python=3.12 -y
202185
source activate ${conda_env_name}

0 commit comments

Comments
 (0)