fix: consolidate chat smoke scripts (#88)

This commit is contained in:
hzrd149
2026-08-28 11:32:16 +00:00
committed by GitHub
parent ec95923729
commit 0da2407119
4 changed files with 90 additions and 40 deletions
+14
View File
@@ -218,6 +218,20 @@ Typecheck:
bun run lint bun run lint
``` ```
### Manual chat-completions smoke test
With a funded daemon running, create or reuse a client API key and pass one or
more current model IDs to the smoke script:
```sh
routstrd clients add --name smoke-test
ROUTSTRD_API_KEY=<api-key> scripts/smoke/chat-completions.sh <model> [model ...]
```
Set `ROUTSTRD_BASE_URL` to test a daemon at a different address. The script
makes live provider requests that may spend wallet funds, so it is intentionally
not part of `bun test`.
## Project Structure ## Project Structure
``` ```
+76
View File
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
set -euo pipefail
readonly BASE_URL="${ROUTSTRD_BASE_URL:-http://127.0.0.1:8008}"
readonly API_KEY="${ROUTSTRD_API_KEY:-}"
usage() {
cat <<'EOF'
Usage: ROUTSTRD_API_KEY=<api-key> scripts/smoke/chat-completions.sh <model> [model ...]
Environment:
ROUTSTRD_API_KEY Routstrd client API key, without the "Bearer " prefix.
ROUTSTRD_BASE_URL Daemon base URL (default: http://127.0.0.1:8008).
EOF
}
if [[ -z "$API_KEY" ]]; then
echo "error: ROUTSTRD_API_KEY is required" >&2
usage >&2
exit 2
fi
if (( $# == 0 )); then
echo "error: at least one model ID is required" >&2
usage >&2
exit 2
fi
for model in "$@"; do
echo "=== Testing $model ==="
response="$(
MODEL="$model" python3 -c '
import json
import os
print(json.dumps({
"model": os.environ["MODEL"],
"messages": [
{"role": "system", "content": "You are Routstr."},
{"role": "user", "content": "Ping the node"},
],
"max_tokens": 128,
}))
' | curl --silent --show-error --fail-with-body \
"${BASE_URL%/}/v1/chat/completions" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
--data-binary @-
)"
RESPONSE="$response" python3 - <<'PY'
import json
import os
import sys
try:
payload = json.loads(os.environ["RESPONSE"])
except json.JSONDecodeError as error:
print(f"error: response was not valid JSON: {error}", file=sys.stderr)
sys.exit(1)
choices = payload.get("choices")
if not isinstance(choices, list) or not choices:
print("error: response did not contain a non-empty choices array", file=sys.stderr)
json.dump(payload, sys.stderr, indent=2)
print(file=sys.stderr)
sys.exit(1)
json.dump(payload, sys.stdout, indent=2)
print()
PY
echo
done
-29
View File
@@ -1,29 +0,0 @@
#!/bin/bash
AUTH="Bearer sk-a2d0981bd84ebf214f4bfb861a273873bfe3e10e6af97533"
BASE_URL="http://localhost:8008/v1/chat/completions"
echo "=== Testing GPT-4 ==="
curl -s "$BASE_URL" \
-H "Content-Type: application/json" \
-H "Authorization: $AUTH" \
-d '{
"model": "gpt-4",
"messages": [
{"role": "user", "content": "Hello, how are you?"}
],
"max_tokens": 128
}' | python3 -m json.tool
echo ""
echo "=== Testing GLM-4.7 ==="
curl -s "$BASE_URL" \
-H "Content-Type: application/json" \
-H "Authorization: $AUTH" \
-d '{
"model": "glm-4.7",
"messages": [
{"role": "user", "content": "Hello, how are you?"}
],
"max_tokens": 128
}' | python3 -m json.tool
-11
View File
@@ -1,11 +0,0 @@
#!/bin/bash
curl -X POST "http://localhost:8008/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemma-3n-e4b-it",
"messages": [
{"role":"system","content":"You are Routstr."},
{"role":"user","content":"Ping the node"}
]
}'