This commit is contained in:
2026-08-17 10:33:40 +08:00
parent eaabd6056e
commit ef3f69fabd
3 changed files with 151 additions and 1 deletions
+26 -1
View File
@@ -1,8 +1,9 @@
#!/bin/bash
# 启动本地 MLX 模型服务:chat + embedding 均由 oMLX(18080) 提供
# chat=Qwen3.5-9B-MLX-4bit4-bit),embedding=BGE-M3oMLX 原生 BERT 系支持)
# 首次运行自动检测 .venv:缺失/损坏(如来自其他机器)时按 requirements.txt 重建,就绪则跳过安装
# 用法: ./scripts/start_models.sh
set -u
set -eu
cd "$(dirname "$0")/.."
ROOT=$(pwd)
VENV="$ROOT/.venv"
@@ -10,6 +11,30 @@ LOG_DIR="$HOME/.omlx/logs"
CACHE_DIR="$HOME/.omlx/cache"
mkdir -p "$LOG_DIR" "$CACHE_DIR"
# .venv 不可跨机复制(pyvenv.cfg / bin 脚本 shebang 写死本机路径),须在本机重建
if [ ! -x "$VENV/bin/python" ]; then
if [ -d "$VENV" ]; then
echo "[warn] $VENV 存在但 python 不可用(可能来自其他机器),删除重建"
rm -rf "$VENV"
fi
if ! command -v python3 >/dev/null 2>&1; then
echo "[error] 未找到 python3,请先安装 Python >= 3.11" >&2
exit 1
fi
if ! python3 -c 'import sys; raise SystemExit(0 if sys.version_info >= (3, 11) else 1)' 2>/dev/null; then
echo "[error] 需要 Python >= 3.11(当前 $(python3 --version 2>&1)),omlx 依赖无法安装" >&2
exit 1
fi
echo "[setup] 创建 venv 并安装依赖(首次/新机器运行,见 scripts/requirements.txt..."
python3 -m venv "$VENV"
"$VENV/bin/pip" install -r "$ROOT/scripts/requirements.txt"
elif [ ! -x "$VENV/bin/omlx" ]; then
echo "[setup] venv 存在但依赖未装全,补装 scripts/requirements.txt ..."
"$VENV/bin/pip" install -r "$ROOT/scripts/requirements.txt"
else
echo "[ok] .venv 已就绪,跳过安装"
fi
# oMLX 模型目录:chatQwen3.5-9B-MLX-4bit+ embeddingbge-m3)均为实体目录,oMLX 按目录扫描注册模型
OMLX_MODEL_DIR="$ROOT/models/mlx/omlx"