Files
ZY-Agent/apps/examples/http-chat/run.sh
T
1445043649 dd1d40368d feat(scripts): 新增本地调试与示例启动脚本,并登记进 apps/README
新增 4 个脚本,统一子命令风格(start/stop/restart/status/logs/run):

- scripts/dev-gateway.sh:方式 B,只起 Gateway(:8001),用 backend/.venv 虚拟环境,
  自动加载 .env、释放端口、等待就绪;带 PID/日志文件,可查状态与跟随日志。
- scripts/dev-full.sh:方式 A,复用 serve.sh 守护模式起全量栈(Gateway+前端+nginx),
  补齐 serve.sh 缺失的 status 与 logs;restart 默认跳过依赖安装,统一入口 :2026。
- apps/examples/http-chat/run.sh:自动探测网关(:2026 优先,回退 :8001),
  优先 uv 临时环境带 requests(--no-project,不污染系统),无 uv 时回退 venv+pip。
- apps/examples/embedded-chat/run.sh:自动定位 backend、加载 .env 后用 uv run 运行,
  内嵌 SDK 模式无需起服务。

apps/README.md 增加「本地调试脚本」与「运行示例」两节,说明上述脚本用法。

全部脚本均已本地实跑验证:全量栈三服务 HTTP 200,两个示例多轮对话正常。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-27 22:47:30 +08:00

51 lines
2.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
#
# http-chat 示例启动脚本
# ------------------------------------------------------------------
# - 自动探测网关地址:优先 :2026(nginx 全量栈),回退 :8001(只起 Gateway)
# - 优先用 uv 临时虚拟环境带上 requests--no-project,不污染系统/项目)
# 没有 uv 时回退到本地 .venv + pip
#
# 用法:
# ./run.sh # 自动探测网关并运行
# DF_BASE=http://localhost:8001 ./run.sh # 手动指定网关
# DF_EMAIL=a@b.com DF_PASSWORD=xxxx ./run.sh
#
# 前提:先起好 Gateway
# ../../../scripts/dev-gateway.sh start # → :8001
# ../../../scripts/dev-full.sh start # → :2026
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# ── 探测可用网关 ──────────────────────────────────────────────────
_alive() { curl -s -o /dev/null -w "%{http_code}" "$1/api/v1/auth/setup-status" 2>/dev/null | grep -qE "200|429"; }
if [ -z "${DF_BASE:-}" ]; then
if _alive "http://localhost:2026"; then DF_BASE="http://localhost:2026"
elif _alive "http://localhost:8001"; then DF_BASE="http://localhost:8001"
else
echo "✗ 没探测到运行中的网关(:2026 / :8001 都不通)。" >&2
echo " 先启动:scripts/dev-gateway.sh start 或 scripts/dev-full.sh start" >&2
echo " 或手动指定:DF_BASE=http://your-host:port ./run.sh" >&2
exit 1
fi
fi
export DF_BASE
echo "→ 使用网关: $DF_BASE"
# ── 运行:优先 uv,回退 venv+pip ─────────────────────────────────
if command -v uv >/dev/null 2>&1; then
echo "→ uv 临时环境运行(--with requests"
exec uv run --no-project --with "requests>=2.31" python app.py
else
echo "→ 未找到 uv,使用本地 .venv + pip"
if [ ! -d .venv ]; then
python3 -m venv .venv
./.venv/bin/pip install -q -r requirements.txt
fi
exec ./.venv/bin/python app.py
fi