-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalAI.sh
137 lines (118 loc) · 3.61 KB
/
LocalAI.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# Function to check if Ollama is installed
check_ollama() {
if ! command -v ollama &> /dev/null; then
echo "Ollama is not installed. Installing now..."
curl -fsSL https://ollama.com/install.sh | sh
if [ $? -ne 0 ]; then
echo "Installation failed. Please check your internet connection or try again."
exit 1
fi
echo "Ollama installed successfully!"
else
echo "Ollama is already installed."
fi
}
# Display URLs for user reference
display_options() {
echo "Please refer to the following links for available versions and documentation:"
echo "Ollama GitHub Repository: https://github.com/ollama/ollama"
echo "Official Ollama Website: https://ollama.com/"
}
# Pull a model
pull_model() {
read -p "Enter the model/version name you want to pull (e.g., llama2, stablelm): " version
if [ -z "$version" ]; then
echo "No version entered. Returning to main menu..."
return
fi
echo "Pulling model: $version..."
ollama pull "$version"
if [ $? -eq 0 ]; then
echo "Successfully pulled '$version'."
else
echo "Failed to pull '$version'. Please check the version name."
fi
}
# List all available models
list_models() {
echo "Listing all models:"
ollama list
}
# Run a model
run_model() {
read -p "Enter the model/version you want to run: " version
if [ -z "$version" ]; then
echo "No version entered. Returning to main menu..."
return
fi
echo "Running model: $version..."
ollama run "$version"
}
# Stop a running model
stop_model() {
read -p "Enter the model/version you want to stop: " version
if [ -z "$version" ]; then
echo "No version entered. Returning to main menu..."
return
fi
echo "Stopping model: $version..."
ollama stop "$version"
}
# Remove a model
remove_model() {
read -p "Enter the model/version you want to remove: " version
if [ -z "$version" ]; then
echo "No version entered. Returning to main menu..."
return
fi
echo "Removing model: $version..."
ollama rm "$version"
}
# Show information about a model
show_model() {
read -p "Enter the model/version you want information for: " version
if [ -z "$version" ]; then
echo "No version entered. Returning to main menu..."
return
fi
echo "Showing information for: $version..."
ollama show "$version"
}
# Main Menu
main_menu() {
while true; do
echo ""
echo "=== Ollama Management Script ==="
echo "1. Pull a Model"
echo "2. List Models"
echo "3. Run a Model"
echo "4. Stop a Running Model"
echo "5. Remove a Model"
echo "6. Show Information About a Model"
echo "================================"
echo "Note: To check Ollama's status, visit http://localhost:11434"
echo "================================"
echo "7. Exit"
echo "================================"
read -p "Enter your choice [1-7]: " choice
case $choice in
1) pull_model ;;
2) list_models ;;
3) run_model ;;
4) stop_model ;;
5) remove_model ;;
6) show_model ;;
7) echo "Exiting. Goodbye!"; exit 0 ;;
*) echo "Invalid choice. Please enter a number between 1 and 7." ;;
esac
done
}
# Main script execution
echo "=== Ollama Installation and Management Script ==="
# Step 1: Check and install Ollama if not present
check_ollama
# Step 2: Display helpful URLs
display_options
# Step 3: Launch the main menu
main_menu