-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·161 lines (135 loc) · 3.54 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·161 lines (135 loc) · 3.54 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
#!/bin/bash
# LLM-Local 启动脚本
# 这个脚本会自动检测环境并启动应用
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 打印带颜色的消息
print_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
# 检查 Python
check_python() {
if ! command -v python &> /dev/null && ! command -v python3 &> /dev/null; then
print_error "未找到 Python。请先安装 Python 3.9 或更高版本。"
exit 1
fi
PYTHON_CMD=$(command -v python3 2>/dev/null || command -v python 2>/dev/null)
PYTHON_VERSION=$($PYTHON_CMD --version 2>&1 | awk '{print $2}')
print_success "找到 Python $PYTHON_VERSION"
}
# 检查虚拟环境
check_venv() {
if [ ! -d "venv" ]; then
print_warning "未找到虚拟环境"
print_info "正在创建虚拟环境..."
$PYTHON_CMD -m venv venv
print_success "虚拟环境创建成功"
else
print_success "找到虚拟环境"
fi
}
# 激活虚拟环境
activate_venv() {
if [ -f "venv/bin/activate" ]; then
source venv/bin/activate
print_success "虚拟环境已激活"
else
print_error "无法激活虚拟环境"
exit 1
fi
}
# 检测平台
detect_platform() {
if [[ "$OSTYPE" == "darwin"* ]]; then
MACHINE=$(uname -m)
if [[ "$MACHINE" == "arm64" ]]; then
print_info "检测到 Apple Silicon (M1/M2/M3)"
PLATFORM="mlx"
else
print_info "检测到 Intel Mac"
PLATFORM="pytorch"
fi
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
print_info "检测到 Linux"
if command -v nvidia-smi &> /dev/null; then
print_info "检测到 NVIDIA GPU"
PLATFORM="cuda"
else
PLATFORM="pytorch"
fi
else
print_info "检测到其他平台"
PLATFORM="pytorch"
fi
}
# 检查依赖
check_dependencies() {
print_info "检查依赖..."
if ! $PYTHON_CMD -c "import torch" &> /dev/null && \
! $PYTHON_CMD -c "import mlx" &> /dev/null; then
print_warning "未安装推理引擎"
install_dependencies
else
print_success "依赖已安装"
fi
}
# 安装依赖
install_dependencies() {
print_info "正在安装依赖..."
case $PLATFORM in
mlx)
print_info "安装 MLX 依赖 (Apple Silicon 优化)..."
pip install -r requirements-mlx.txt
;;
cuda)
print_info "安装 CUDA 依赖..."
pip install torch --index-url https://download.pytorch.org/whl/cu118
pip install -r requirements-cuda.txt
;;
*)
print_info "安装基础依赖..."
pip install -r requirements.txt
;;
esac
print_success "依赖安装完成"
}
# 主函数
main() {
echo ""
echo "🤖 LLM-Local 启动器"
echo "===================="
echo ""
# 检查 Python
check_python
# 检测平台
detect_platform
# 检查虚拟环境
check_venv
# 激活虚拟环境
activate_venv
# 检查依赖
check_dependencies
echo ""
print_success "环境准备完成!"
echo ""
print_info "正在启动应用..."
echo ""
# 启动应用
$PYTHON_CMD main.py "$@"
}
# 运行主函数
main "$@"