Skip to content

Commit

Permalink
GMC: add Codetrans example (#115)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
KfreeZ and pre-commit-ci[bot] authored Jun 25, 2024
1 parent d204a77 commit aed70da
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/scripts/e2e/gmc_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ MOUNT_DIR=/home/$USER_ID/.cache/huggingface/hub

IMAGE_REPO=${OPEA_IMAGE_REPO:-""}
CODEGEN_NAMESPACE="${APP_NAMESPACE}-codegen"
CODETRANS_NAMESPACE="${APP_NAMESPACE}-codetrans"


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

echo "validate codetrans"
validate_codetrans

get_gmc_controller_logs
}

function cleanup_gmc() {
echo "clean up microservice-connector"
kubectl delete ns $APP_NAMESPACE
kubectl delete ns $CODEGEN_NAMESPACE
kubectl delete ns $CODETRANS_NAMESPACE
kubectl delete ns $SYSTEM_NAMESPACE
kubectl delete crd gmconnectors.gmc.opea.io
}
Expand Down Expand Up @@ -91,6 +97,9 @@ function validate_chatqna() {
status=true
fi
if [ $status == false ]; then
if [[ -f $LOG_PATH/curl_chatqna.log ]]; then
cat $LOG_PATH/curl_chatqna.log
fi
echo "Response check failed, please check the logs in artifacts!"
exit 1
else
Expand Down Expand Up @@ -139,6 +148,60 @@ function validate_codegen() {
status=true
fi
if [ $status == false ]; then
if [[ -f $LOG_PATH/gmc_codegen.log ]]; then
cat $LOG_PATH/gmc_codegen.log
fi
echo "Response check failed, please check the logs in artifacts!"
cat $LOG_PATH/gmc_codegen.log
exit 1
else
echo "Response check succeed!"
fi
}

function validate_codetrans() {
# todo select gaudi or xeon
kubectl create ns $CODETRANS_NAMESPACE
sed -i "s|namespace: codetrans|namespace: $CODETRANS_NAMESPACE|g" $(pwd)/config/samples/codetrans.yaml
kubectl apply -f $(pwd)/config/samples/codetrans.yaml

# Wait until the router service is ready
echo "Waiting for the codetrans router service to be ready..."
wait_until_pod_ready "codetrans router" $CODETRANS_NAMESPACE "router-service"
output=$(kubectl get pods -n $CODETRANS_NAMESPACE)
echo $output


# deploy client pod for testing
kubectl create deployment client-test -n $CODETRANS_NAMESPACE --image=python:3.8.13 -- sleep infinity

# wait for client pod ready
wait_until_pod_ready "client-test" $CODETRANS_NAMESPACE "client-test"
# giving time to populating data
sleep 60

kubectl get pods -n $CODETRANS_NAMESPACE
# send request to codetrans
export CLIENT_POD=$(kubectl get pod -n $CODETRANS_NAMESPACE -l app=client-test -o jsonpath={.items..metadata.name})
echo "$CLIENT_POD"
accessUrl=$(kubectl get gmc -n $CODETRANS_NAMESPACE -o jsonpath="{.items[?(@.metadata.name=='codetrans')].status.accessUrl}")
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
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "codetrans failed, please check the logs in ${LOG_PATH}!"
exit 1
fi

echo "Checking response results, make sure the output is reasonable. "
local status=false
if [[ -f $LOG_PATH/gmc_codetrans.log ]] && \
[[ $(grep -c "import" $LOG_PATH/gmc_codetrans.log) != 0 ]]; then
status=true
fi
if [ $status == false ]; then
if [[ -f $LOG_PATH/gmc_codetrans.log ]]; then
cat $LOG_PATH/gmc_codetrans.log
fi
echo "Response check failed, please check the logs in artifacts!"
exit 1
else
Expand Down
32 changes: 32 additions & 0 deletions microservices-connector/config/samples/codetrans.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

apiVersion: gmc.opea.io/v1alpha3
kind: GMConnector
metadata:
labels:
app.kubernetes.io/name: gmconnector
app.kubernetes.io/managed-by: kustomize
name: codetrans
namespace: codetrans
spec:
routerConfig:
name: router
serviceName: router-service
nodes:
root:
routerType: Sequence
steps:
- name: Llm
data: $response
internalService:
serviceName: codetrans-service
config:
endpoint: /v1/chat/completions
- name: Tgi
internalService:
serviceName: tgi-service
config:
LLM_MODEL_ID: HuggingFaceH4/mistral-7b-grok
endpoint: /generate
isDownstreamService: true

0 comments on commit aed70da

Please sign in to comment.