|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (C) 2024 Intel Corporation |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +set -x |
| 6 | + |
| 7 | +WORKPATH=$(dirname "$PWD") |
| 8 | +ip_address=$(hostname -I | awk '{print $1}') |
| 9 | +function build_docker_images() { |
| 10 | + cd $WORKPATH |
| 11 | + docker build --no-cache --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -t opea/reranking-predictionguard:comps -f comps/reranks/predictionguard/Dockerfile . |
| 12 | + if [ $? -ne 0 ]; then |
| 13 | + echo "opea/reranking-predictionguard built fail" |
| 14 | + exit 1 |
| 15 | + else |
| 16 | + echo "opea/reranking-predictionguard built successful" |
| 17 | + fi |
| 18 | +} |
| 19 | + |
| 20 | +function start_service() { |
| 21 | + predictionguard_service_port=9000 |
| 22 | + unset http_proxy |
| 23 | + |
| 24 | + docker run -d --name="test-comps-reranking-predictionguard-server" \ |
| 25 | + -p ${predictionguard_service_port}:9000 \ |
| 26 | + --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy \ |
| 27 | + -e PREDICTIONGUARD_API_KEY=${PREDICTIONGUARD_API_KEY} \ |
| 28 | + opea/reranking-predictionguard:comps |
| 29 | + |
| 30 | + sleep 1m |
| 31 | +} |
| 32 | + |
| 33 | +function validate_microservice() { |
| 34 | + predictionguard_service_port=9000 |
| 35 | + result=$(http_proxy="" curl http://${ip_address}:${predictionguard_service_port}/v1/reranking\ |
| 36 | + -X POST \ |
| 37 | + -d '{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}]}' \ |
| 38 | + -H 'Content-Type: application/json') |
| 39 | + if [[ $result == *"reranked_docs"* ]]; then |
| 40 | + echo "Result correct." |
| 41 | + else |
| 42 | + echo "Result wrong. Received was $result" |
| 43 | + docker logs test-comps-reranking-predictionguard-server |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +} |
| 47 | + |
| 48 | +function stop_docker() { |
| 49 | + cid=$(docker ps -aq --filter "name=test-comps-rerank*") |
| 50 | + if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi |
| 51 | +} |
| 52 | + |
| 53 | +function main() { |
| 54 | + |
| 55 | + stop_docker |
| 56 | + |
| 57 | + build_docker_images |
| 58 | + start_service |
| 59 | + |
| 60 | + validate_microservice |
| 61 | + |
| 62 | + stop_docker |
| 63 | + echo y | docker system prune |
| 64 | + |
| 65 | +} |
| 66 | + |
| 67 | +main |
0 commit comments