-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.sh
105 lines (93 loc) · 2.73 KB
/
helpers.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
98
99
100
101
102
103
104
105
#!/bin/bash
# Example usage:
# print_usage_instructions "lfm-3b" 9000 # Uses custom port 3000
# print_usage_instructions "lfm-3b" 9000 "sk-abc123" # Uses custom port and API key
print_usage_instructions() {
local MODEL_NAME=$1
local PORT=$2
local API_KEY=$3
cat <<EOF
Model '$MODEL_NAME' started successfully
The vLLM API will be accessible at http://localhost:$PORT
Please wait 1-2 minutes for the model to load before making API calls
You can check the container logs for more information:
docker logs -f $MODEL_NAME
To stop the container:
docker stop $MODEL_NAME
To check model status:
EOF
if [ -n "$API_KEY" ]; then
echo " curl http://localhost:$PORT/v1/models \\"
echo " -H \"Authorization: Bearer $API_KEY\""
else
echo " curl http://localhost:$PORT/v1/models"
fi
echo -e "\nTo chat with the model:"
echo " curl http://localhost:$PORT/v1/chat/completions \\"
echo " -H \"Content-Type: application/json\" \\"
# Add authorization header if API key is provided
if [ -n "$API_KEY" ]; then
echo " -H \"Authorization: Bearer $API_KEY\" \\"
fi
# Complete the curl command
cat <<EOF
-d '{
"model": "$MODEL_NAME",
"messages": [
{
"role": "user",
"content": "At which temperature does silver melt?"
}
],
"max_tokens": 128,
"temperature": 0
}'
EOF
}
# Function to parse yaml file
parse_yaml() {
local yaml_file=$1
local model_count=$(grep -c "^[[:space:]]\+[^[:space:]]\+:$" "$yaml_file")
if [ "$model_count" -eq 0 ]; then
echo "Error: No models found in $yaml_file" >&2
exit 1
fi
# First pass to find the default model
local default_model=$(awk '
/^models:/ {in_models=1; next}
in_models && /^[[:space:]]+[^[:space:]]+:$/ {
model=$1
sub(/:$/, "", model)
sub(/^[[:space:]]+/, "", model)
current_model=model
}
in_models && /^[[:space:]]+default:[[:space:]]+true/ {
print current_model
exit
}
' "$yaml_file")
# Second pass to output model information with default tag
awk -v default_model="$default_model" '
/^models:/ {in_models=1; next}
in_models && /^[[:space:]]+[^[:space:]]+:$/ {
# Extract model name by removing trailing colon and leading spaces
model=$1
sub(/:$/, "", model)
sub(/^[[:space:]]+/, "", model)
current_model=model
is_default=0
if (current_model == default_model) {
is_default=1
}
}
in_models && /^[[:space:]]+image:/ {
# Extract image value by removing quotes and "image:"
image=substr($2, 2, length($2)-2)
if (is_default) {
print current_model "\t" image "\tdefault_model"
} else {
print current_model "\t" image
}
}
' "$yaml_file"
}