Skip to content

Commit 295b818

Browse files
authored
Add codetrans example test for genaiexample (#339)
* add codetrans example for genaiexample. Signed-off-by: zhlsunshine <huailong.zhang@intel.com>
1 parent 960cf38 commit 295b818

File tree

5 files changed

+399
-1
lines changed

5 files changed

+399
-1
lines changed

.github/workflows/docker-compose-e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
job1:
2626
uses: ./.github/workflows/reuse-get-test-matrix.yml
2727
with:
28-
diff_excluded_files: '.github|README.md|*.txt|deprecate|kubernetes|manifest|assets'
28+
diff_excluded_files: '.github|README.md|*.txt|deprecate|kubernetes|manifest|gmc|assets'
2929

3030
mega-image-build:
3131
needs: job1
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
apiVersion: gmc.opea.io/v1alpha3
5+
kind: GMConnector
6+
metadata:
7+
labels:
8+
app.kubernetes.io/name: gmconnector
9+
app.kubernetes.io/managed-by: kustomize
10+
gmc/platform: gaudi
11+
name: codetrans
12+
namespace: codetrans
13+
spec:
14+
routerConfig:
15+
name: router
16+
serviceName: router-service
17+
nodes:
18+
root:
19+
routerType: Sequence
20+
steps:
21+
- name: Llm
22+
data: $response
23+
internalService:
24+
serviceName: codetrans-service
25+
config:
26+
endpoint: /v1/chat/completions
27+
- name: TgiGaudi
28+
internalService:
29+
serviceName: tgi-gaudi-svc
30+
config:
31+
LLM_MODEL_ID: HuggingFaceH4/mistral-7b-grok
32+
endpoint: /generate
33+
isDownstreamService: true
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
apiVersion: gmc.opea.io/v1alpha3
5+
kind: GMConnector
6+
metadata:
7+
labels:
8+
app.kubernetes.io/name: gmconnector
9+
app.kubernetes.io/managed-by: kustomize
10+
gmc/platform: xeon
11+
name: codetrans
12+
namespace: codetrans
13+
spec:
14+
routerConfig:
15+
name: router
16+
serviceName: router-service
17+
nodes:
18+
root:
19+
routerType: Sequence
20+
steps:
21+
- name: Llm
22+
data: $response
23+
internalService:
24+
serviceName: codetrans-service
25+
config:
26+
endpoint: /v1/chat/completions
27+
- name: Tgi
28+
internalService:
29+
serviceName: tgi-service
30+
config:
31+
LLM_MODEL_ID: HuggingFaceH4/mistral-7b-grok
32+
endpoint: /generate
33+
isDownstreamService: true

CodeTrans/tests/test_gmc_on_gaudi.sh

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#!/bin/bash
2+
# Copyright (C) 2024 Intel Corporation
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
set -xe
6+
USER_ID=$(whoami)
7+
LOG_PATH=/home/$(whoami)/logs
8+
MOUNT_DIR=/home/$USER_ID/.cache/huggingface/hub
9+
IMAGE_REPO=${IMAGE_REPO:-}
10+
11+
function init_codetrans() {
12+
wget https://raw.githubusercontent.com/opea-project/GenAIInfra/main/microservices-connector/config/crd/bases/gmc.opea.io_gmconnectors.yaml
13+
wget https://raw.githubusercontent.com/opea-project/GenAIInfra/main/microservices-connector/config/rbac/gmc-manager-rbac.yaml
14+
wget https://raw.githubusercontent.com/opea-project/GenAIInfra/main/microservices-connector/config/manager/gmc-manager.yaml
15+
wget -O manifests/gmc-router.yaml https://raw.githubusercontent.com/opea-project/GenAIInfra/main/microservices-connector/config/gmcrouter/gmc-router.yaml
16+
17+
# replace namespace for gmc-router and gmc-manager
18+
sed -i "s|namespace: system|namespace: $SYSTEM_NAMESPACE|g" ./gmc-manager.yaml
19+
sed -i "s|namespace: system|namespace: $SYSTEM_NAMESPACE|g" ./gmc-manager-rbac.yaml
20+
sed -i "s|name: system|name: $SYSTEM_NAMESPACE|g" ./gmc-manager-rbac.yaml
21+
# replace the mount dir "path: /mnt/model" with "path: $CHART_MOUNT"
22+
find . -name '*.yaml' -type f -exec sed -i "s#path: /mnt/models#path: $MOUNT_DIR#g" {} \;
23+
# replace the repository "image: opea/*" with "image: ${IMAGE_REPO}opea/"
24+
find . -name '*.yaml' -type f -exec sed -i "s#image: opea/*#image: ${IMAGE_REPO}opea/#g" {} \;
25+
find . -name '*.yaml' -type f -exec sed -i "s#image: \"opea/*#image: ${IMAGE_REPO}opea\"/#g" {} \;
26+
# set huggingface token
27+
find . -name '*.yaml' -type f -exec sed -i "s#\${HUGGINGFACEHUB_API_TOKEN}#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \;
28+
# replace namespace "default" with real namespace
29+
find . -name '*.yaml' -type f -exec sed -i "s#default.svc#$APP_NAMESPACE.svc#g" {} \;
30+
}
31+
32+
function install_codetrans() {
33+
# Make sure you have to use image tag $VERSION for microservice-connector installation
34+
echo "install microservice-connector, using repo $DOCKER_REGISTRY and tag $VERSION"
35+
echo "using namespace $SYSTEM_NAMESPACE and $APP_NAMESPACE"
36+
37+
kubectl apply -f ./gmc.opea.io_gmconnectors.yaml
38+
kubectl apply -f ./gmc-manager-rbac.yaml
39+
kubectl create configmap gmcyaml -n $SYSTEM_NAMESPACE --from-file $(pwd)/../kubernetes/manifests
40+
kubectl apply -f ./gmc-manager.yaml
41+
42+
# Wait until the gmc controller pod is ready
43+
wait_until_pod_ready "gmc-controller" $SYSTEM_NAMESPACE "gmc-controller"
44+
kubectl get pods -n $SYSTEM_NAMESPACE
45+
rm -f ./gmc.opea.io_gmconnectors.yaml ./gmc-manager-rbac.yaml ./gmc-manager.yaml manifests/gmc-router.yaml
46+
}
47+
48+
function validate_codetrans() {
49+
kubectl create ns $APP_NAMESPACE
50+
sed -i "s|namespace: codetrans|namespace: $APP_NAMESPACE|g" ./codetrans_gaudi.yaml
51+
kubectl apply -f ./codetrans_gaudi.yaml
52+
53+
# Wait until the router service is ready
54+
echo "Waiting for the codetrans router service to be ready..."
55+
wait_until_pod_ready "codetrans router" $APP_NAMESPACE "router-service"
56+
output=$(kubectl get pods -n $APP_NAMESPACE)
57+
echo $output
58+
59+
# deploy client pod for testing
60+
kubectl create deployment client-test -n $APP_NAMESPACE --image=python:3.8.13 -- sleep infinity
61+
62+
# wait for client pod ready
63+
wait_until_pod_ready "client-test" $APP_NAMESPACE "client-test"
64+
# giving time to populating data
65+
sleep 60
66+
67+
kubectl get pods -n $APP_NAMESPACE
68+
# send request to codetrans
69+
export CLIENT_POD=$(kubectl get pod -n $APP_NAMESPACE -l app=client-test -o jsonpath={.items..metadata.name})
70+
echo "$CLIENT_POD"
71+
accessUrl=$(kubectl get gmc -n $APP_NAMESPACE -o jsonpath="{.items[?(@.metadata.name=='codetrans')].status.accessUrl}")
72+
kubectl exec "$CLIENT_POD" -n $APP_NAMESPACE -- curl $accessUrl -X POST -d '{"language_from": "Golang","language_to": "Python","source_code": "package main\n\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello, World!\");\n}"}' -H 'Content-Type: application/json' > $LOG_PATH/gmc_codetrans.log
73+
exit_code=$?
74+
if [ $exit_code -ne 0 ]; then
75+
echo "codetrans failed, please check the logs in ${LOG_PATH}!"
76+
exit 1
77+
fi
78+
79+
echo "Checking response results, make sure the output is reasonable. "
80+
local status=false
81+
if [[ -f $LOG_PATH/gmc_codetrans.log ]] && \
82+
[[ $(grep -c "import" $LOG_PATH/gmc_codetrans.log) != 0 ]]; then
83+
status=true
84+
fi
85+
if [ $status == false ]; then
86+
if [[ -f $LOG_PATH/gmc_codetrans.log ]]; then
87+
cat $LOG_PATH/gmc_codetrans.log
88+
fi
89+
echo "Response check failed, please check the logs in artifacts!"
90+
exit 1
91+
else
92+
echo "Response check succeed!"
93+
fi
94+
}
95+
96+
function wait_until_pod_ready() {
97+
echo "Waiting for the $1 to be ready..."
98+
max_retries=30
99+
retry_count=0
100+
while ! is_pod_ready $2 $3; do
101+
if [ $retry_count -ge $max_retries ]; then
102+
echo "$1 is not ready after waiting for a significant amount of time"
103+
get_gmc_controller_logs
104+
exit 1
105+
fi
106+
echo "$1 is not ready yet. Retrying in 10 seconds..."
107+
sleep 10
108+
output=$(kubectl get pods -n $2)
109+
echo $output
110+
retry_count=$((retry_count + 1))
111+
done
112+
}
113+
114+
function is_pod_ready() {
115+
if [ "$2" == "gmc-controller" ]; then
116+
pod_status=$(kubectl get pods -n $1 -o jsonpath='{.items[].status.conditions[?(@.type=="Ready")].status}')
117+
else
118+
pod_status=$(kubectl get pods -n $1 -l app=$2 -o jsonpath='{.items[].status.conditions[?(@.type=="Ready")].status}')
119+
fi
120+
if [ "$pod_status" == "True" ]; then
121+
return 0
122+
else
123+
return 1
124+
fi
125+
}
126+
127+
function get_gmc_controller_logs() {
128+
# Fetch the name of the pod with the app-name gmc-controller in the specified namespace
129+
pod_name=$(kubectl get pods -n $SYSTEM_NAMESPACE -l control-plane=gmc-controller -o jsonpath='{.items[0].metadata.name}')
130+
131+
# Check if the pod name was found
132+
if [ -z "$pod_name" ]; then
133+
echo "No pod found with app-name gmc-controller in namespace $SYSTEM_NAMESPACE"
134+
return 1
135+
fi
136+
137+
# Get the logs of the found pod
138+
echo "Fetching logs for pod $pod_name in namespace $SYSTEM_NAMESPACE..."
139+
kubectl logs $pod_name -n $SYSTEM_NAMESPACE
140+
}
141+
142+
if [ $# -eq 0 ]; then
143+
echo "Usage: $0 <function_name>"
144+
exit 1
145+
fi
146+
147+
case "$1" in
148+
init_CodeTrans)
149+
pushd ChatQnA/kubernetes
150+
init_codetrans
151+
popd
152+
;;
153+
install_CodeTrans)
154+
pushd ChatQnA/kubernetes
155+
install_codetrans
156+
popd
157+
;;
158+
validate_CodeTrans)
159+
pushd CodeTrans/kubernetes
160+
validate_codetrans
161+
popd
162+
;;
163+
*)
164+
echo "Unknown function: $1"
165+
;;
166+
esac

0 commit comments

Comments
 (0)