-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_model.sh
executable file
·63 lines (50 loc) · 1.53 KB
/
create_model.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
#!/bin/bash
# Exit on any error
set -e
# Check if directory path and GGUF file name are provided as arguments
if [ $# -ne 2 ]; then
echo "Usage: $0 <directory_path> <gguf_file_name>"
echo "Example: $0 /path/to/shell-commands unsloth.Q8_0.gguf"
exit 1
fi
# Define paths using provided directory and file name
SCRIPT_DIR="$1"
GGUF_FILE="$2"
# Get just the last part of the path
MODEL_NAME=$(basename "$SCRIPT_DIR")
MODEL_FILE="${SCRIPT_DIR}/${GGUF_FILE}"
MODELFILE_PATH="${SCRIPT_DIR}/Modelfile"
# Check if directory exists
if [ ! -d "$SCRIPT_DIR" ]; then
echo "Error: Directory not found at ${SCRIPT_DIR}"
exit 1
fi
# Check if the model file exists
if [ ! -f "$MODEL_FILE" ]; then
echo "Error: Model file not found at ${MODEL_FILE}"
exit 1
fi
# Create Modelfile with proper template
# Using weak quotes for heredoc to allow variable expansion
cat > "$MODELFILE_PATH" << EOL
FROM ${MODEL_FILE}
PARAMETER temperature 0
PARAMETER top_p 0.7
PARAMETER stop "<|im_end|>"
TEMPLATE """
{{ if .System }}<|im_start|>system
{{ .System }}<|im_end|>{{ end }}<|im_start|>user
{{ .Prompt }}<|im_end|>
<|im_start|>assistant
"""
EOL
# Check if Modelfile was created successfully
if [ ! -f "$MODELFILE_PATH" ]; then
echo "Error: Failed to create Modelfile"
exit 1
fi
echo "Created Modelfile successfully at ${MODELFILE_PATH}"
# Create Ollama model using just the directory name
echo "Creating Ollama model '${MODEL_NAME}'..."
ollama create "$MODEL_NAME" -f "$MODELFILE_PATH"
echo "Model '${MODEL_NAME}' creation completed successfully!"