diff options
| author | Your Name <you@example.com> | 2026-04-26 21:02:47 +0800 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-04-26 21:02:47 +0800 |
| commit | d3e770254de0bb301815ca87257c8b1a357d06c4 (patch) | |
| tree | 358c814be2a06b9e2009905f14938243286b8d82 /tests | |
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/smoke.sh | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/smoke.sh b/tests/smoke.sh new file mode 100755 index 0000000..a5ef23d --- /dev/null +++ b/tests/smoke.sh | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | # Smoke test for the OpenAI-compatible LLM endpoint. | ||
| 3 | # Usage: | ||
| 4 | # ENDPOINT=http://llm.dev.localtest.me:8080 MODEL=Qwen2.5-0.5B-Instruct ./tests/smoke.sh | ||
| 5 | set -euo pipefail | ||
| 6 | |||
| 7 | ENDPOINT="${ENDPOINT:-http://llm.dev.localtest.me:8080}" | ||
| 8 | MODEL="${MODEL:-Qwen2.5-0.5B-Instruct}" | ||
| 9 | TIMEOUT="${TIMEOUT:-120}" | ||
| 10 | |||
| 11 | say() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } | ||
| 12 | fail() { printf '\033[1;31mFAIL\033[0m %s\n' "$*" >&2; exit 1; } | ||
| 13 | |||
| 14 | say "Endpoint: $ENDPOINT" | ||
| 15 | say "Model: $MODEL" | ||
| 16 | |||
| 17 | say "GET /v1/models" | ||
| 18 | models_json="$(curl -fsS --max-time "$TIMEOUT" "$ENDPOINT/v1/models")" || fail "/v1/models unreachable" | ||
| 19 | echo "$models_json" | grep -q "$MODEL" || fail "/v1/models does not list $MODEL" | ||
| 20 | |||
| 21 | say "POST /v1/chat/completions" | ||
| 22 | resp="$(curl -fsS --max-time "$TIMEOUT" "$ENDPOINT/v1/chat/completions" \ | ||
| 23 | -H 'Content-Type: application/json' \ | ||
| 24 | -d "$(cat <<EOF | ||
| 25 | { | ||
| 26 | "model": "$MODEL", | ||
| 27 | "messages": [{"role": "user", "content": "Reply with the single word: pong"}], | ||
| 28 | "max_tokens": 8, | ||
| 29 | "temperature": 0 | ||
| 30 | } | ||
| 31 | EOF | ||
| 32 | )")" || fail "chat completion request failed" | ||
| 33 | |||
| 34 | content="$(echo "$resp" | python3 -c 'import sys, json; print(json.load(sys.stdin)["choices"][0]["message"]["content"])')" | ||
| 35 | echo "model reply: $content" | ||
| 36 | [[ -n "$content" ]] || fail "empty completion content" | ||
| 37 | |||
| 38 | say "OK" | ||
