|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (C) 2024 Intel Corporation |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +set -e |
| 6 | +IMAGE_REPO=${IMAGE_REPO:-"opea"} |
| 7 | +IMAGE_TAG=${IMAGE_TAG:-"latest"} |
| 8 | +echo "REGISTRY=IMAGE_REPO=${IMAGE_REPO}" |
| 9 | +echo "TAG=IMAGE_TAG=${IMAGE_TAG}" |
| 10 | +export REGISTRY=${IMAGE_REPO} |
| 11 | +export TAG=${IMAGE_TAG} |
| 12 | + |
| 13 | +WORKPATH=$(dirname "$PWD") |
| 14 | +LOG_PATH="$WORKPATH/tests" |
| 15 | +ip_address=$(hostname -I | awk '{print $1}') |
| 16 | + |
| 17 | +function build_docker_images() { |
| 18 | + echo "Building Docker Images...." |
| 19 | + cd $WORKPATH/docker_image_build |
| 20 | + if [ ! -d "GenAIComps" ] ; then |
| 21 | + echo "Cloning GenAIComps repository" |
| 22 | + git clone https://github.com/opea-project/GenAIComps.git && cd GenAIComps && git checkout "${opea_branch:-"main"}" && cd ../ |
| 23 | + fi |
| 24 | + service_list="dataprep-redis embedding-tei retriever-redis doc-index-retriever" |
| 25 | + docker compose -f build.yaml build ${service_list} --no-cache > ${LOG_PATH}/docker_image_build.log |
| 26 | + |
| 27 | + docker pull ghcr.io/huggingface/text-embeddings-inference:cpu-1.5 |
| 28 | + docker pull redis/redis-stack:7.2.0-v9 |
| 29 | + docker images && sleep 1s |
| 30 | + |
| 31 | + echo "Docker images built!" |
| 32 | +} |
| 33 | + |
| 34 | +function start_services() { |
| 35 | + echo "Starting Docker Services...." |
| 36 | + cd $WORKPATH/docker_compose/intel/cpu/xeon |
| 37 | + export EMBEDDING_MODEL_ID="BAAI/bge-base-en-v1.5" |
| 38 | + export TEI_EMBEDDING_ENDPOINT="http://${ip_address}:6006" |
| 39 | + export REDIS_URL="redis://${ip_address}:6379" |
| 40 | + export INDEX_NAME="rag-redis" |
| 41 | + export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} |
| 42 | + export MEGA_SERVICE_HOST_IP=${ip_address} |
| 43 | + export EMBEDDING_SERVICE_HOST_IP=${ip_address} |
| 44 | + export RETRIEVER_SERVICE_HOST_IP=${ip_address} |
| 45 | + |
| 46 | + # Start Docker Containers |
| 47 | + docker compose -f compose_without_rerank.yaml up -d |
| 48 | + sleep 5m |
| 49 | + echo "Docker services started!" |
| 50 | +} |
| 51 | + |
| 52 | +function validate() { |
| 53 | + local CONTENT="$1" |
| 54 | + local EXPECTED_RESULT="$2" |
| 55 | + local SERVICE_NAME="$3" |
| 56 | + |
| 57 | + if echo "$CONTENT" | grep -q "$EXPECTED_RESULT"; then |
| 58 | + echo "[ $SERVICE_NAME ] Content is as expected: $CONTENT." |
| 59 | + echo 0 |
| 60 | + else |
| 61 | + echo "[ $SERVICE_NAME ] Content does not match the expected result: $CONTENT" |
| 62 | + echo 1 |
| 63 | + fi |
| 64 | +} |
| 65 | + |
| 66 | +function validate_megaservice() { |
| 67 | + echo "===========Ingest data==================" |
| 68 | + local CONTENT=$(http_proxy="" curl -X POST "http://${ip_address}:6007/v1/dataprep" \ |
| 69 | + -H "Content-Type: multipart/form-data" \ |
| 70 | + -F 'link_list=["https://opea.dev/"]') |
| 71 | + local EXIT_CODE=$(validate "$CONTENT" "Data preparation succeeded" "dataprep-redis-service-xeon") |
| 72 | + echo "$EXIT_CODE" |
| 73 | + local EXIT_CODE="${EXIT_CODE:0-1}" |
| 74 | + echo "return value is $EXIT_CODE" |
| 75 | + if [ "$EXIT_CODE" == "1" ]; then |
| 76 | + docker logs dataprep-redis-server | tee -a ${LOG_PATH}/dataprep-redis-service-xeon.log |
| 77 | + return 1 |
| 78 | + fi |
| 79 | + |
| 80 | + # Curl the Mega Service |
| 81 | + echo "================Testing retriever service: Text Request ================" |
| 82 | + cd $WORKPATH/tests |
| 83 | + local CONTENT=$(http_proxy="" curl http://${ip_address}:8889/v1/retrievaltool -X POST -H "Content-Type: application/json" -d '{ |
| 84 | + "text": "Explain the OPEA project?" |
| 85 | + }') |
| 86 | + # local CONTENT=$(python test.py --host_ip ${ip_address} --request_type text) |
| 87 | + local EXIT_CODE=$(validate "$CONTENT" "OPEA" "doc-index-retriever-service-xeon") |
| 88 | + echo "$EXIT_CODE" |
| 89 | + local EXIT_CODE="${EXIT_CODE:0-1}" |
| 90 | + echo "return value is $EXIT_CODE" |
| 91 | + if [ "$EXIT_CODE" == "1" ]; then |
| 92 | + echo "=============Embedding container log==================" |
| 93 | + docker logs embedding-tei-server | tee -a ${LOG_PATH}/doc-index-retriever-service-xeon.log |
| 94 | + echo "=============Retriever container log==================" |
| 95 | + docker logs retriever-redis-server | tee -a ${LOG_PATH}/doc-index-retriever-service-xeon.log |
| 96 | + echo "=============Doc-index-retriever container log==================" |
| 97 | + docker logs doc-index-retriever-server | tee -a ${LOG_PATH}/doc-index-retriever-service-xeon.log |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | + |
| 101 | + echo "================Testing retriever service: ChatCompletion Request================" |
| 102 | + cd $WORKPATH/tests |
| 103 | + local CONTENT=$(python test.py --host_ip ${ip_address} --request_type chat_completion) |
| 104 | + local EXIT_CODE=$(validate "$CONTENT" "OPEA" "doc-index-retriever-service-xeon") |
| 105 | + echo "$EXIT_CODE" |
| 106 | + local EXIT_CODE="${EXIT_CODE:0-1}" |
| 107 | + echo "return value is $EXIT_CODE" |
| 108 | + if [ "$EXIT_CODE" == "1" ]; then |
| 109 | + echo "=============Embedding container log==================" |
| 110 | + docker logs embedding-tei-server | tee -a ${LOG_PATH}/doc-index-retriever-service-xeon.log |
| 111 | + echo "=============Retriever container log==================" |
| 112 | + docker logs retriever-redis-server | tee -a ${LOG_PATH}/doc-index-retriever-service-xeon.log |
| 113 | + echo "=============Doc-index-retriever container log==================" |
| 114 | + docker logs doc-index-retriever-server | tee -a ${LOG_PATH}/doc-index-retriever-service-xeon.log |
| 115 | + exit 1 |
| 116 | + fi |
| 117 | +} |
| 118 | + |
| 119 | +function stop_docker() { |
| 120 | + cd $WORKPATH/docker_compose/intel/cpu/xeon |
| 121 | + container_list=$(cat compose.yaml | grep container_name | cut -d':' -f2) |
| 122 | + for container_name in $container_list; do |
| 123 | + cid=$(docker ps -aq --filter "name=$container_name") |
| 124 | + echo "Stopping container $container_name" |
| 125 | + if [[ ! -z "$cid" ]]; then docker rm $cid -f && sleep 1s; fi |
| 126 | + done |
| 127 | +} |
| 128 | + |
| 129 | +function main() { |
| 130 | + |
| 131 | + stop_docker |
| 132 | + build_docker_images |
| 133 | + echo "Dump current docker ps" |
| 134 | + docker ps |
| 135 | + start_time=$(date +%s) |
| 136 | + start_services |
| 137 | + end_time=$(date +%s) |
| 138 | + duration=$((end_time-start_time)) |
| 139 | + echo "Mega service start duration is $duration s" |
| 140 | + validate_megaservice |
| 141 | + |
| 142 | + stop_docker |
| 143 | + echo y | docker system prune |
| 144 | + |
| 145 | +} |
| 146 | + |
| 147 | +main |
0 commit comments