From aed70da3cead5afe0f1ed83287540654087c46b4 Mon Sep 17 00:00:00 2001 From: Kefei Zhang Date: Tue, 25 Jun 2024 14:29:58 +0800 Subject: [PATCH] GMC: add Codetrans example (#115) * add codetrans example * add codetrans e2e script Signed-off-by: KfreeZ --------- Signed-off-by: KfreeZ Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/workflows/scripts/e2e/gmc_test.sh | 63 +++++++++++++++++++ .../config/samples/codetrans.yaml | 32 ++++++++++ 2 files changed, 95 insertions(+) create mode 100644 microservices-connector/config/samples/codetrans.yaml diff --git a/.github/workflows/scripts/e2e/gmc_test.sh b/.github/workflows/scripts/e2e/gmc_test.sh index e1467d06..498e9ce5 100755 --- a/.github/workflows/scripts/e2e/gmc_test.sh +++ b/.github/workflows/scripts/e2e/gmc_test.sh @@ -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 @@ -34,6 +36,9 @@ function validate_gmc() { echo "validate codegen" validate_codegen + echo "validate codetrans" + validate_codetrans + get_gmc_controller_logs } @@ -41,6 +46,7 @@ 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 } @@ -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 @@ -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 diff --git a/microservices-connector/config/samples/codetrans.yaml b/microservices-connector/config/samples/codetrans.yaml new file mode 100644 index 00000000..17654497 --- /dev/null +++ b/microservices-connector/config/samples/codetrans.yaml @@ -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