-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-ollama.sh
executable file
·97 lines (79 loc) · 2.02 KB
/
run-ollama.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
usage () {
echo "Usage: $0 [-m model] [-d directory] [-h]"
echo " -m, --model MODEL Specify the ollama model to use (default: llama2:13b)"
echo " -d, --directory DIRECTORY Specify the directory for the model to read. (must be absolute path)"
echo " -h, --help Show this help message."
}
error_handler() {
echo "Killing docker..."
sudo docker rm -f ollama
}
SHORT="m:d:h"
LONG="model:,directory:,help"
PARSED=$(getopt --options $SHORT --longoptions $LONG --name "$0" -- "$@")
PORT=11434
if [[ $? -ne 0 ]]; then
exit 2
fi
eval set -- "$PARSED"
model="llama2:13b"
directory=""
while true; do
case "$1" in
-m|--model)
model="$2"
shift 2
;;
-d|--directory)
directory="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
--)
shift
break
;;
*)
echo "An unknown error has occured."
exit 3
;;
esac
done
if [ -z "$directory" ]; then
echo "Error: Directory is required."
usage
exit 1
fi
trap error_handler ERR
echo "Model: $model"
echo "Directory: $directory"
sudo systemctl start docker
docker run -d --device /dev/kfd --device /dev/dri -v ollama:/root/.ollama -p ${PORT}:${PORT} --name ollama ollama/ollama:rocm
sudo docker exec -d ollama ollama run $model
prompt="Why is the sky blue?"
response=$(curl -s -X POST http://localhost:${PORT}/api/generate -d '{
"model": "'"$model"'",
"prompt": "'"$prompt"'",
"stream": false
}')
echo "$response" | jq -r '.response'
echo ""
while true; do
read -p "Prompt: " prompt
if [[ "$prompt" == "exit" ]]; then
break
fi
response=$(curl -s -X POST http://localhost:${PORT}/api/generate -d '{
"model": "'"$model"'",
"prompt": "'"$prompt"'",
"stream": false
}')
echo "$response" | jq -r '.response'
echo ""
done
echo ""
sudo docker rm -f ollama