Skip to content

Commit aed70da

Browse files
GMC: add Codetrans example (#115)
* add codetrans example * add codetrans e2e script Signed-off-by: KfreeZ <[email protected]> --------- Signed-off-by: KfreeZ <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d204a77 commit aed70da

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

.github/workflows/scripts/e2e/gmc_test.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ MOUNT_DIR=/home/$USER_ID/.cache/huggingface/hub
99

1010
IMAGE_REPO=${OPEA_IMAGE_REPO:-""}
1111
CODEGEN_NAMESPACE="${APP_NAMESPACE}-codegen"
12+
CODETRANS_NAMESPACE="${APP_NAMESPACE}-codetrans"
13+
1214

1315
function install_gmc() {
1416
# Make sure you have to use image tag $VERSION for microservice-connector installation
@@ -34,13 +36,17 @@ function validate_gmc() {
3436
echo "validate codegen"
3537
validate_codegen
3638

39+
echo "validate codetrans"
40+
validate_codetrans
41+
3742
get_gmc_controller_logs
3843
}
3944

4045
function cleanup_gmc() {
4146
echo "clean up microservice-connector"
4247
kubectl delete ns $APP_NAMESPACE
4348
kubectl delete ns $CODEGEN_NAMESPACE
49+
kubectl delete ns $CODETRANS_NAMESPACE
4450
kubectl delete ns $SYSTEM_NAMESPACE
4551
kubectl delete crd gmconnectors.gmc.opea.io
4652
}
@@ -91,6 +97,9 @@ function validate_chatqna() {
9197
status=true
9298
fi
9399
if [ $status == false ]; then
100+
if [[ -f $LOG_PATH/curl_chatqna.log ]]; then
101+
cat $LOG_PATH/curl_chatqna.log
102+
fi
94103
echo "Response check failed, please check the logs in artifacts!"
95104
exit 1
96105
else
@@ -139,6 +148,60 @@ function validate_codegen() {
139148
status=true
140149
fi
141150
if [ $status == false ]; then
151+
if [[ -f $LOG_PATH/gmc_codegen.log ]]; then
152+
cat $LOG_PATH/gmc_codegen.log
153+
fi
154+
echo "Response check failed, please check the logs in artifacts!"
155+
cat $LOG_PATH/gmc_codegen.log
156+
exit 1
157+
else
158+
echo "Response check succeed!"
159+
fi
160+
}
161+
162+
function validate_codetrans() {
163+
# todo select gaudi or xeon
164+
kubectl create ns $CODETRANS_NAMESPACE
165+
sed -i "s|namespace: codetrans|namespace: $CODETRANS_NAMESPACE|g" $(pwd)/config/samples/codetrans.yaml
166+
kubectl apply -f $(pwd)/config/samples/codetrans.yaml
167+
168+
# Wait until the router service is ready
169+
echo "Waiting for the codetrans router service to be ready..."
170+
wait_until_pod_ready "codetrans router" $CODETRANS_NAMESPACE "router-service"
171+
output=$(kubectl get pods -n $CODETRANS_NAMESPACE)
172+
echo $output
173+
174+
175+
# deploy client pod for testing
176+
kubectl create deployment client-test -n $CODETRANS_NAMESPACE --image=python:3.8.13 -- sleep infinity
177+
178+
# wait for client pod ready
179+
wait_until_pod_ready "client-test" $CODETRANS_NAMESPACE "client-test"
180+
# giving time to populating data
181+
sleep 60
182+
183+
kubectl get pods -n $CODETRANS_NAMESPACE
184+
# send request to codetrans
185+
export CLIENT_POD=$(kubectl get pod -n $CODETRANS_NAMESPACE -l app=client-test -o jsonpath={.items..metadata.name})
186+
echo "$CLIENT_POD"
187+
accessUrl=$(kubectl get gmc -n $CODETRANS_NAMESPACE -o jsonpath="{.items[?(@.metadata.name=='codetrans')].status.accessUrl}")
188+
kubectl exec "$CLIENT_POD" -n $CODETRANS_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
189+
exit_code=$?
190+
if [ $exit_code -ne 0 ]; then
191+
echo "codetrans failed, please check the logs in ${LOG_PATH}!"
192+
exit 1
193+
fi
194+
195+
echo "Checking response results, make sure the output is reasonable. "
196+
local status=false
197+
if [[ -f $LOG_PATH/gmc_codetrans.log ]] && \
198+
[[ $(grep -c "import" $LOG_PATH/gmc_codetrans.log) != 0 ]]; then
199+
status=true
200+
fi
201+
if [ $status == false ]; then
202+
if [[ -f $LOG_PATH/gmc_codetrans.log ]]; then
203+
cat $LOG_PATH/gmc_codetrans.log
204+
fi
142205
echo "Response check failed, please check the logs in artifacts!"
143206
exit 1
144207
else
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
name: codetrans
11+
namespace: codetrans
12+
spec:
13+
routerConfig:
14+
name: router
15+
serviceName: router-service
16+
nodes:
17+
root:
18+
routerType: Sequence
19+
steps:
20+
- name: Llm
21+
data: $response
22+
internalService:
23+
serviceName: codetrans-service
24+
config:
25+
endpoint: /v1/chat/completions
26+
- name: Tgi
27+
internalService:
28+
serviceName: tgi-service
29+
config:
30+
LLM_MODEL_ID: HuggingFaceH4/mistral-7b-grok
31+
endpoint: /generate
32+
isDownstreamService: true

0 commit comments

Comments
 (0)