#!/bin/bash # 模型池批量测试脚本 # 用法: bash ~/.hermes/skills/devops/openclaw/scripts/test-models.sh [model_id ...] # 不带参数则测试 models.json 中所有模型 set -e API_KEY="sk-0ExNiLblJvIWBDpkS50fwOBw4MmqLyKdHJK5iQtlw9dOMWBP" ENDPOINT="http://127.0.0.1:3000/v1/chat/completions" PAYLOAD='{"model":"MODEL_ID","messages":[{"role":"user","content":"say ok"}],"max_tokens":5}' test_model() { local model_id="$1" local payload="${PAYLOAD//MODEL_ID/$model_id}" local response response=$(curl -s -X POST "$ENDPOINT" \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d "$payload" 2>&1) # 解析错误 if echo "$response" | python3 -c "import json,sys; d=json.load(sys.stdin); err=d.get('error',{}); print(err.get('message','')[:80])" 2>/dev/null | grep -qE "end of life|DEGRADED|Not found"; then echo "❌ $model_id" return 1 fi # 检查 content 是否有有效内容(content 可能为 null) local content content=$(echo "$response" | python3 -c "import json,sys; d=json.load(sys.stdin); c=d.get('choices',[{}])[0].get('message',{}).get('content'); print(c if c else 'NO_CONTENT')" 2>/dev/null) if [[ "$content" == "NO_CONTENT" ]]; then # 检查 reasoning 字段(有内容的 thinking 模型) local reasoning reasoning=$(echo "$response" | python3 -c "import json,sys; d=json.load(sys.stdin); r=d.get('choices',[{}])[0].get('message',{}).get('reasoning'); print(r[:30] if r else '')" 2>/dev/null) if [[ -n "$reasoning" ]]; then echo "✅ $model_id (thinking, content=null)" else echo "❌ $model_id (empty response)" fi else echo "✅ $model_id → $content" fi } # 如果有参数,测试指定模型;否则测试 models.json 中所有模型 if [[ $# -gt 0 ]]; then for model in "$@"; do test_model "$model" done else echo "Usage: $0 model_id [model_id ...]" echo "或者手动测试单个模型:" echo " curl -s -X POST http://127.0.0.1:3000/v1/chat/completions \\" echo " -H 'Authorization: Bearer sk-...' \\" echo " -H 'Content-Type: application/json' \\" echo " -d '{\"model\":\"模型ID\",\"messages\":[{\"role\":\"user\",\"content\":\"say ok\"}],\"max_tokens\":5}'" fi