summaryrefslogtreecommitdiff
path: root/tests/smoke.sh
blob: a5ef23d0be60448cb9dd063d66027489af2949ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
# Smoke test for the OpenAI-compatible LLM endpoint.
# Usage:
#   ENDPOINT=http://llm.dev.localtest.me:8080 MODEL=Qwen2.5-0.5B-Instruct ./tests/smoke.sh
set -euo pipefail

ENDPOINT="${ENDPOINT:-http://llm.dev.localtest.me:8080}"
MODEL="${MODEL:-Qwen2.5-0.5B-Instruct}"
TIMEOUT="${TIMEOUT:-120}"

say() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
fail() { printf '\033[1;31mFAIL\033[0m %s\n' "$*" >&2; exit 1; }

say "Endpoint: $ENDPOINT"
say "Model:    $MODEL"

say "GET /v1/models"
models_json="$(curl -fsS --max-time "$TIMEOUT" "$ENDPOINT/v1/models")" || fail "/v1/models unreachable"
echo "$models_json" | grep -q "$MODEL" || fail "/v1/models does not list $MODEL"

say "POST /v1/chat/completions"
resp="$(curl -fsS --max-time "$TIMEOUT" "$ENDPOINT/v1/chat/completions" \
  -H 'Content-Type: application/json' \
  -d "$(cat <<EOF
{
  "model": "$MODEL",
  "messages": [{"role": "user", "content": "Reply with the single word: pong"}],
  "max_tokens": 8,
  "temperature": 0
}
EOF
)")" || fail "chat completion request failed"

content="$(echo "$resp" | python3 -c 'import sys, json; print(json.load(sys.stdin)["choices"][0]["message"]["content"])')"
echo "model reply: $content"
[[ -n "$content" ]] || fail "empty completion content"

say "OK"