forked from bentoml/OpenLLM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
local.sh
executable file
·96 lines (83 loc) · 2.23 KB
/
local.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
#!/usr/bin/env bash
set -e
GIT_ROOT=$(git rev-parse --show-toplevel)
cd "$GIT_ROOT" || exit 1
print_usage() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -e, -E, --ext Specify extensions for OpenLLM. Can be used multiple times or as a comma-separated list."
echo " Example: $0 -e ext1,ext2"
echo " Example: $0 --ext ext1 --ext ext2"
echo ""
echo "This script installs various components with optional extensions."
}
split_csv() {
local IFS=','
read -ra ADDR <<< "$1"
for i in "${ADDR[@]}"; do
EXTENSIONS+=("$i")
done
}
# Function to ensure tomlkit is installen# Function to ensure tomlkit is installed
ensure_tomlkit() {
if ! python -c "import tomlkit" > /dev/null 2>&1; then
echo "Installing tomlkit..."
pip install tomlkit
fi
}
# Function to validate extensions
validate_extensions() {
ensure_tomlkit
local valid_extensions
valid_extensions=$(python -c "
import tomlkit
with open('$GIT_ROOT/openllm-python/pyproject.toml', 'r') as file:
data = tomlkit.load(file)
optional_dependencies = data['project']['optional-dependencies']
print(' '.join(optional_dependencies.keys()))
")
COMMENT="[${valid_extensions[*]}]"
COMMENT=${COMMENT// /,} # Replace spaces with commas
for ext in "${EXTENSIONS[@]}"; do
if ! [[ $valid_extensions =~ (^|[[:space:]])$ext($|[[:space:]]) ]]; then
echo "Invalid extension: $ext. Available extensions are: $COMMENT"
exit 1
fi
done
}
EXTENSIONS=()
# Parse command line arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--extensions|-e|-E|--ext)
if [[ -n $2 && $2 != -* ]]; then
split_csv "$2"
shift
else
print_usage
exit 1
fi
;;
--help|-h)
print_usage
exit 0
;;
*)
print_usage
exit 1
;;
esac
shift
done
validate_extensions
# Check if the EXTENSIONS array is empty
if [ ${#EXTENSIONS[@]} -eq 0 ]; then
echo "No extensions specified"
EXTENSIONS_STR=""
else
EXTENSIONS_STR="[${EXTENSIONS[*]}]"
EXTENSIONS_STR=${EXTENSIONS_STR// /,} # Replace spaces with commas
fi
pip install -e "$GIT_ROOT/openllm-core"
pip install -e "$GIT_ROOT/openllm-client"
pip install -e "$GIT_ROOT/openllm-python$EXTENSIONS_STR" -v