-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmanage.sh
More file actions
executable file
·250 lines (222 loc) · 5.47 KB
/
manage.sh
File metadata and controls
executable file
·250 lines (222 loc) · 5.47 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/bin/bash
# manage.sh - Environment management helper for lmagi
# (c) Gregory L. Magnusson MIT license 2024
VENV_DIR="venv"
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
print_header() {
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}========================================${NC}"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
# Check if virtual environment exists
check_venv() {
if [ ! -d "$VENV_DIR" ]; then
print_error "Virtual environment not found!"
echo "Run './setup.sh' first to create the environment."
return 1
fi
return 0
}
# Activate virtual environment
activate_env() {
if check_venv; then
source "$VENV_DIR/bin/activate"
print_success "Virtual environment activated"
python --version
fi
}
# Run the main application
run_app() {
if check_venv; then
source "$VENV_DIR/bin/activate"
print_header "Starting lmagi..."
python lmagi.py
fi
}
# Run with Ollama
run_ollama() {
if check_venv; then
source "$VENV_DIR/bin/activate"
print_header "Starting lmagi with Ollama..."
python lmagi.py
fi
}
# Update dependencies
update_deps() {
if check_venv; then
source "$VENV_DIR/bin/activate"
print_header "Updating dependencies..."
pip install --upgrade pip
pip install -r requirements.txt --upgrade
print_success "Dependencies updated"
fi
}
# Check environment
check_env() {
print_header "Environment Status"
# Check Python
if command -v python3 &> /dev/null; then
print_success "Python: $(python3 --version)"
else
print_error "Python not found"
fi
# Check venv
if [ -d "$VENV_DIR" ]; then
print_success "Virtual environment: exists"
else
print_error "Virtual environment: not found"
fi
# Check .env
if [ -f ".env" ]; then
print_success ".env file: exists"
echo " Configured APIs:"
grep -E "^[A-Z_]+_API_KEY=" .env | sed 's/=.*/=***/' | sed 's/^/ - /'
else
print_warning ".env file: not found"
fi
# Check directories
echo ""
echo "Memory directories:"
for dir in memory/stm memory/logs memory/truth; do
if [ -d "$dir" ]; then
print_success "$dir"
else
print_warning "$dir (missing)"
fi
done
# Check installed packages
if check_venv; then
source "$VENV_DIR/bin/activate"
echo ""
echo "Key packages installed:"
pip list | grep -E "openai|groq|together|ai71|nicegui|aiohttp" | sed 's/^/ /'
fi
}
# Clean environment
clean_env() {
print_header "Cleaning environment..."
echo "This will remove:"
echo " - Virtual environment ($VENV_DIR)"
echo " - Python cache files (__pycache__, *.pyc)"
echo ""
read -p "Continue? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf "$VENV_DIR"
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null
find . -type f -name "*.pyc" -delete 2>/dev/null
print_success "Environment cleaned"
echo "Run './setup.sh' to recreate the environment"
else
print_warning "Cleaning cancelled"
fi
}
# Test installation
test_install() {
if check_venv; then
source "$VENV_DIR/bin/activate"
print_header "Testing installation..."
python3 << 'EOF'
import sys
print(f"Python version: {sys.version}")
print("\nTesting imports...")
packages = [
"openai",
"groq",
"together",
"ai71",
"nicegui",
"aiohttp",
"ujson",
"psutil",
"dotenv"
]
failed = []
for pkg in packages:
try:
__import__(pkg.replace("-", "_"))
print(f" ✓ {pkg}")
except ImportError:
print(f" ✗ {pkg} - FAILED")
failed.append(pkg)
if failed:
print(f"\n{len(failed)} package(s) failed to import")
sys.exit(1)
else:
print("\n✓ All packages imported successfully!")
EOF
if [ $? -eq 0 ]; then
print_success "Installation test passed"
else
print_error "Installation test failed"
fi
fi
}
# Show help
show_help() {
print_header "lmagi Management Tool"
echo ""
echo "Usage: ./manage.sh [command]"
echo ""
echo "Commands:"
echo " run - Run the main application"
echo " ollama - Run with Ollama integration"
echo " check - Check environment status"
echo " update - Update dependencies"
echo " test - Test package installation"
echo " clean - Clean environment (removes venv)"
echo " help - Show this help message"
echo ""
echo "Examples:"
echo " ./manage.sh run"
echo " ./manage.sh check"
echo " ./manage.sh update"
}
# Main script
case "$1" in
run)
run_app
;;
ollama)
run_ollama
;;
check)
check_env
;;
update)
update_deps
;;
test)
test_install
;;
clean)
clean_env
;;
help|--help|-h)
show_help
;;
*)
if [ -z "$1" ]; then
show_help
else
print_error "Unknown command: $1"
echo ""
show_help
fi
exit 1
;;
esac