Skip to content

Commit f520480

Browse files
committed
Add unit test script for chat app
1 parent 3a00c21 commit f520480

File tree

7 files changed

+132
-60
lines changed

7 files changed

+132
-60
lines changed

web-apps/build.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

web-apps/chat/defaults.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11

2-
model_name:
3-
model_instruction: "You are a helpful and cheerful AI assistant. Please respond appropriately."
4-
backend_url:
2+
# Default target is a local ollama instance
3+
# running inside the same docker network
4+
model_name: smollm2:135m
5+
backend_url: http://ollama:11434
6+
57
host_address: 0.0.0.0
68

9+
model_instruction: "You are a helpful and cheerful AI assistant. Please respond appropriately."
10+
711
page_title: Large Language Model
812

913
# LLM request parameters

web-apps/chat/test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import os
2+
import unittest
3+
4+
# from unittest import mock
5+
from gradio_client import Client
6+
7+
url = os.environ.get("GRADIO_URL", "http://localhost:7860")
8+
client = Client(url)
9+
10+
class TestSuite(unittest.TestCase):
11+
12+
def test_gradio_api(self):
13+
result = client.predict("Hi", api_name="/chat")
14+
self.assertGreater(len(result), 0)
15+
16+
# def test_mock_response(self):
17+
# with mock.patch('app.client.stream_response', return_value=(char for char in "Mocked")) as mock_response:
18+
# result = client.predict("Hi", api_name="/chat")
19+
# # mock_response.assert_called_once_with("Hi", [])
20+
# self.assertEqual(result, "Mocked")
21+
22+
if __name__ == "__main__":
23+
unittest.main()

web-apps/functions.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

web-apps/kind-images.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
set -e
22

3-
source functions.sh
3+
find_images() {
4+
images=""
5+
for dir in $(ls $1); do
6+
if [[ -f $1/$dir/Dockerfile ]]; then
7+
images+="$dir "
8+
fi
9+
done
10+
echo $images
11+
}
412

513
if [[ -z $1 ]]; then
614
echo "Published image tag must be provided as sole command line arg"

web-apps/run.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

web-apps/test-images.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
set -e
3+
4+
IMAGE_TAG="${1:-latest}"
5+
echo Testing image tag $IMAGE_TAG
6+
7+
find_images() {
8+
images=""
9+
for dir in $(ls $1); do
10+
if [[ -f $1/$dir/Dockerfile ]]; then
11+
images+="$dir "
12+
fi
13+
done
14+
echo $images
15+
}
16+
17+
image_name() {
18+
echo ghcr.io/stackhpc/azimuth-llm-$1-ui
19+
}
20+
21+
build() {
22+
if [[ -f $1/Dockerfile ]]; then
23+
echo Building $1 docker image
24+
docker build . -t $(image_name $1) -f $1/Dockerfile
25+
else
26+
echo No Dockerfile found for $1
27+
exit 1
28+
fi
29+
}
30+
31+
log () {
32+
echo
33+
echo $@
34+
}
35+
36+
test() {
37+
38+
echo
39+
echo "----- Starting test process for $1 app -----"
40+
echo
41+
42+
DOCKER_NET_NAME=azimuth-llm-shared
43+
if [[ ! $(docker network ls | grep $DOCKER_NET_NAME) ]]; then
44+
docker network create $DOCKER_NET_NAME
45+
fi
46+
47+
if [[ -f $1/test.py ]]; then
48+
49+
# Ensure app image is available
50+
IMAGE_NAME=$(image_name $1)
51+
if [[ $IMAGE_TAG == "latest" ]]; then
52+
build $1
53+
else
54+
log "Pulling image $IMAGE_NAME:$IMAGE_TAG"
55+
docker pull $IMAGE_NAME:$IMAGE_TAG
56+
fi
57+
58+
# Ensure Ollama instance is available
59+
if [[ $(curl -s localhost:11434) == "Ollama is running" ]]; then
60+
log "Using existing ollama process running on localhost:11434"
61+
else
62+
log "Ollama process not running - starting containerised server"
63+
docker run --rm --network $DOCKER_NET_NAME -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
64+
sleep 3
65+
docker exec -it ollama ollama pull smollm2:135m
66+
fi
67+
68+
log "Starting Gradio app container"
69+
docker run --network $DOCKER_NET_NAME -d --name $1-app $IMAGE_NAME
70+
71+
# Give the app time to start
72+
sleep 3
73+
74+
log "Running tests"
75+
docker run --network $DOCKER_NET_NAME --rm --name $1-test-suite -e GRADIO_URL=http://$1-app:7860 --entrypoint python $IMAGE_NAME test.py
76+
77+
log "Removing containers:"
78+
docker rm -f ollama $1-app
79+
80+
log "Removing docker network:"
81+
docker network rm $DOCKER_NET_NAME
82+
83+
echo
84+
echo "----- Tests succeed -----"
85+
echo
86+
else
87+
echo No test.py file found for $1 app
88+
fi
89+
}
90+
91+
for image in $(find_images .); do
92+
test $image
93+
done

0 commit comments

Comments
 (0)