Skip to content

Commit

Permalink
adding bedrock test script
Browse files Browse the repository at this point in the history
Signed-off-by: vihanth sura <[email protected]>
  • Loading branch information
Vihanth committed Dec 16, 2024
1 parent 866d767 commit 35e898a
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions tests/llms/test_llms_text-generation_bedrock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

set -x

WORKPATH=$(dirname "$PWD")
LOG_PATH="$WORKPATH/tests"
ip_address=$(hostname -I | awk '{print $1}')

function build_docker_images() {
cd $WORKPATH
docker build --no-cache -t opea/bedrock:latest \
--build-arg https_proxy=$https_proxy \
--build-arg http_proxy=$http_proxy \
-f comps/llms/text-generation/bedrock/Dockerfile .
if [ $? -ne 0 ]; then
echo "opea/bedrock:latest built fail"
exit 1
else
echo "opea/bedrock:latest built successful"
fi
}

function start_service() {
# Check for required AWS credentials
if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
echo "AWS credentials not set in environment"
exit 1
fi

docker run -d --name="bedrock-test" \
-p 9009:9000 \
--ipc=host \
-e http_proxy=$http_proxy \
-e https_proxy=$https_proxy \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
opea/bedrock:latest

# Give the service time to start
sleep 10s
}

function validate_microservice() {
bedrock_port=9009
result=$(http_proxy="" curl http://${ip_address}:${bedrock_port}/v1/chat/completions \
-X POST \
-d '{"model": "us.anthropic.claude-3-haiku-20240307-v1:0", "messages": [{"role": "user", "content": "What is Deep Learning?"}], "max_tokens":17, "stream": "true"}' \
-H 'Content-Type: application/json')

if [[ $result == *"data: [DONE]"* ]]; then
echo "Result correct."
echo "$result" >> ${LOG_PATH}/bedrock.log
else
echo "Result wrong. Received was $result"
docker logs bedrock-test >> ${LOG_PATH}/bedrock.log
exit 1
fi
}

function stop_docker() {
cid=$(docker ps -aq --filter "name=bedrock-test")
if [[ ! -z "$cid" ]]; then
docker stop $cid && docker rm $cid && sleep 1s
fi
}


function main() {
stop_docker

build_docker_images
start_service

validate_microservice

stop_docker
echo y | docker system prune
}

main

0 comments on commit 35e898a

Please sign in to comment.