Skip to content

Commit d016126

Browse files
authored
Merge pull request #1879 from AlexonOliveiraRH/main
feat(script): add browser override and improve service startup flow
2 parents bc08134 + 5b71938 commit d016126

File tree

2 files changed

+84
-21
lines changed

2 files changed

+84
-21
lines changed

docs/demo/README.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
# RamaLama
22

3-
This script demonstrates running RamaLama
3+
This script demonstrates running RamaLama with a sample workflow that pulls a model, serves it, and allows testing inference through a browser or curl.
44

5-
You need to execute the ramalama.sh script in this directory.
5+
## Requirements
66

7-
RamaLama and Podman are required to run this script
7+
- [RamaLama](https://github.com/) installed and available in your PATH
8+
- [Podman](https://podman.io/) installed and configured
9+
10+
## Usage
11+
12+
Run the script:
13+
14+
```bash
15+
./ramalama.sh
16+
````
17+
18+
Override the browser (optional):
19+
20+
```bash
21+
BROWSER=google-chrome ./ramalama.sh
22+
```
23+
24+
## Features
25+
26+
* Pulls and runs the `smollm:135m` and `granite` models with RamaLama
27+
* Opens the service endpoint in your browser automatically
28+
* Waits for the service to be ready before testing inference
29+
* Performs a sample inference with `curl` against the `granite3.1-dense` model
30+
31+
## Advanced usage
32+
33+
You can also call specific functions from the script directly, for example:
34+
35+
```bash
36+
./ramalama.sh pull
37+
./ramalama.sh run
38+
./ramalama.sh test
39+
```
40+
41+
Extra arguments can be passed after the function name if supported.
42+
43+
---

docs/demo/ramalama.sh

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
# This script will demonstrate a lot of the features of RamaLama, concentrating
55
# on the security features.
66

7+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
8+
if [[ -z "${SCRIPT_DIR}" ]]; then
9+
echo "Error: Could not determine script directory." >&2
10+
exit 1
11+
fi
12+
713
#set -eou pipefail
814
IFS=$'\n\t'
915

@@ -13,6 +19,9 @@ bold=$(tput bold)
1319
cyan=$(tput setaf 6)
1420
reset=$(tput sgr0)
1521

22+
# Allow overriding browser (default: firefox)
23+
BROWSER="${BROWSER:-firefox}"
24+
1625
echo_color() {
1726
echo "${cyan}$1${reset}"
1827
}
@@ -100,7 +109,8 @@ serve() {
100109
echo ""
101110

102111
echo_color "Use web browser to show interaction"
103-
exec_color "firefox http://localhost:8080"
112+
exec_color "$BROWSER http://localhost:8080"
113+
echo ""
104114

105115
echo_color "Stop the ramalama container"
106116
exec_color "ramalama stop granite-service"
@@ -109,12 +119,14 @@ serve() {
109119
echo_color "Serve granite via RamaLama model service"
110120
exec_color "ramalama serve --port 8085 --api llama-stack --name granite-service -d granite"
111121
echo ""
122+
123+
echo_color "Waiting for the model service to come up"
124+
exec_color "timeout 25 bash -c 'until curl -s -f -o /dev/null http://localhost:8085/v1/openai/v1/models; do sleep 1; done';"
125+
echo ""
112126

113-
echo_color "Use web browser to show interaction"
114-
exec_color "firefox http://localhost:8085"
115-
116-
echo_color "Use web browser to show interaction"
117-
exec_color "firefox http://localhost:8085/v1/openai"
127+
echo_color "Inference against the model using llama-stack API"
128+
exec_color "printf \"\n\"; curl --no-progress-meter http://localhost:8085/v1/openai/v1/chat/completions -H \"Content-Type: application/json\" -d '{ \"model\": \"granite3.1-dense\", \"messages\": [{\"role\": \"user\", \"content\": \"Tell me a joke\"}], \"stream\": false }' | grep -Po '(?<=\"content\":\")[^\"]*' | head -1"
129+
echo ""
118130

119131
echo_color "Stop the ramalama container"
120132
exec_color "ramalama stop granite-service"
@@ -176,31 +188,46 @@ multi-modal() {
176188
echo ""
177189

178190
echo_color "Use web browser to show interaction"
179-
exec_color "firefox \"$(dirname \"$1\")/camera-demo.html\""
191+
exec_color "$BROWSER \"${SCRIPT_DIR}/camera-demo.html\""
192+
echo ""
180193

181194
echo_color "Stop the ramalama container"
182-
exec_color "ramalama stop multi-modal "
195+
exec_color "ramalama stop multi-modal"
183196
echo ""
184197

185198
read -r -p "--> clear"
186199
clear
187200
}
188201

189-
setup
202+
if [[ $# -eq 0 ]]; then
203+
# No argument: runs the whole demo script
204+
setup
190205

191-
version
206+
version
192207

193-
pull
208+
pull
194209

195-
run
210+
run
196211

197-
serve
212+
serve
198213

199-
kubernetes
214+
kubernetes
200215

201-
quadlet
216+
quadlet
202217

203-
multi-modal
218+
multi-modal
219+
220+
else
221+
# Runs only the called function as an argument
222+
cmd="$1"
223+
if declare -f "$cmd" > /dev/null; then
224+
"$cmd" "${@:2}" # extra arguments if there is any
225+
226+
else
227+
echo "Error: function '$cmd' not found"
228+
exit 1
229+
fi
230+
fi
204231

205-
echo_color "End of Demo"
206-
echo "Thank you!"
232+
echo_color "End of Demo"
233+
echo "Thank you!"

0 commit comments

Comments
 (0)