9814d18e8c
- test_connectivity.py: connectivity tests for all four endpoint types (anthropic, openai, lm_studio, hermes, agent0) — treats no-credits as success - test_hermes.py: raw WebSocket frame logger used to reverse-engineer protocol - Fix handle_hermes: skip prompt.submit ack frame, read full text from message.complete payload.text, always raise on status==error - Fix requirements.txt: use >= pins (fastapi/uvicorn versions didn't exist) - Fix dev.sh: prefer python3.12 for venv (mcp>=1.9.0 requires 3.10+) - Remove ANTHROPIC_KEY env var dependency from server.py (keys come from DB) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
112 lines
3.8 KiB
Bash
Executable File
112 lines
3.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# dev.sh - Run Agent inference inference service locally
|
|
#
|
|
# Usage:
|
|
# ./dev.sh [--port <port>]
|
|
#
|
|
# Options:
|
|
# --port N Port to listen on (default: 8089)
|
|
#
|
|
# Requires: Python 3, pip (installs deps from requirements.txt if missing)
|
|
# Logs are written to ./dev.log in this directory.
|
|
|
|
set -e
|
|
|
|
# ── Parse arguments ────────────────────────────────────────────────────────────
|
|
|
|
PORT=8089
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--port) PORT="$2"; shift 2 ;;
|
|
*) echo "Unknown option: $1" >&2; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
# ── Setup ─────────────────────────────────────────────────────────────────────
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
LOG_FILE="$SCRIPT_DIR/dev.log"
|
|
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m'
|
|
|
|
log() {
|
|
local color="$1"; shift
|
|
echo -e "${color}$*${NC}"
|
|
echo "$*" >> "$LOG_FILE"
|
|
}
|
|
|
|
echo "=== dev.sh started $(date -u '+%Y-%m-%d %H:%M:%S UTC') ===" > "$LOG_FILE"
|
|
echo "Service: agent-inference Port: ${PORT}" >> "$LOG_FILE"
|
|
|
|
log "$GREEN" "Starting Agent inference inference service on port ${PORT}..."
|
|
log "$GREEN" " Log file : ${LOG_FILE}"
|
|
|
|
# Pull latest changes
|
|
log "$GREEN" "Pulling latest changes..."
|
|
git -C "$SCRIPT_DIR" pull --ff-only >> "$LOG_FILE" 2>&1 \
|
|
|| log "$YELLOW" "Warning: git pull failed — continuing with local state"
|
|
|
|
# ── Python environment ─────────────────────────────────────────────────────────
|
|
|
|
if [ ! -d "$SCRIPT_DIR/.venv" ]; then
|
|
log "$YELLOW" "Creating virtual environment..."
|
|
PYTHON=$(which python3.12 || which python3.11 || which python3.10 || which python3)
|
|
$PYTHON -m venv "$SCRIPT_DIR/.venv" >> "$LOG_FILE" 2>&1
|
|
fi
|
|
|
|
source "$SCRIPT_DIR/.venv/bin/activate"
|
|
|
|
if [ -f "$SCRIPT_DIR/requirements.txt" ]; then
|
|
log "$GREEN" "Installing dependencies..."
|
|
pip install -q -r "$SCRIPT_DIR/requirements.txt" >> "$LOG_FILE" 2>&1
|
|
fi
|
|
|
|
# ── Load .env ──────────────────────────────────────────────────────────────────
|
|
|
|
if [ -f "$SCRIPT_DIR/.env" ]; then
|
|
log "$GREEN" "✓ Loading .env file"
|
|
set -a
|
|
source "$SCRIPT_DIR/.env"
|
|
set +a
|
|
fi
|
|
|
|
export AGENT_INFERENCE_PORT="$PORT"
|
|
|
|
# ── Cleanup trap ───────────────────────────────────────────────────────────────
|
|
|
|
cleanup() {
|
|
echo ""
|
|
log "$YELLOW" "Shutting down Agent inference inference..."
|
|
kill $SERVER_PID 2>/dev/null || true
|
|
echo "=== dev.sh stopped $(date -u '+%Y-%m-%d %H:%M:%S UTC') ===" >> "$LOG_FILE"
|
|
exit 0
|
|
}
|
|
|
|
trap cleanup SIGINT SIGTERM
|
|
|
|
# ── Start server ───────────────────────────────────────────────────────────────
|
|
|
|
log "$GREEN" "Starting uvicorn on port ${PORT}..."
|
|
cd "$SCRIPT_DIR"
|
|
uvicorn server:app --host 0.0.0.0 --port "$PORT" --reload >> "$LOG_FILE" 2>&1 &
|
|
SERVER_PID=$!
|
|
|
|
echo ""
|
|
echo -e "${GREEN}============================================${NC}"
|
|
echo -e "${GREEN} Agent inference inference is running!${NC}"
|
|
echo -e "${GREEN}============================================${NC}"
|
|
echo ""
|
|
echo -e " Service : ${YELLOW}http://localhost:${PORT}${NC}"
|
|
echo -e " Health : ${YELLOW}http://localhost:${PORT}/health${NC}"
|
|
echo -e " Log file : ${YELLOW}${LOG_FILE}${NC}"
|
|
echo ""
|
|
echo -e " Press ${RED}Ctrl+C${NC} to stop"
|
|
echo ""
|
|
|
|
wait
|