From 0da240711925196b821757789b4edeedd11b1773 Mon Sep 17 00:00:00 2001 From: hzrd149 <8001706+hzrd149@users.noreply.github.com> Date: Fri, 28 Aug 2026 12:32:16 +0100 Subject: [PATCH] fix: consolidate chat smoke scripts (#88) --- README.md | 14 ++++++ scripts/smoke/chat-completions.sh | 76 +++++++++++++++++++++++++++++++ test_chat.sh | 29 ------------ test_curl.sh | 11 ----- 4 files changed, 90 insertions(+), 40 deletions(-) create mode 100755 scripts/smoke/chat-completions.sh delete mode 100755 test_chat.sh delete mode 100755 test_curl.sh diff --git a/README.md b/README.md index 14295f1..a9f0ac7 100644 --- a/README.md +++ b/README.md @@ -218,6 +218,20 @@ Typecheck: 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= scripts/smoke/chat-completions.sh [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 ``` diff --git a/scripts/smoke/chat-completions.sh b/scripts/smoke/chat-completions.sh new file mode 100755 index 0000000..32f706e --- /dev/null +++ b/scripts/smoke/chat-completions.sh @@ -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= scripts/smoke/chat-completions.sh [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 diff --git a/test_chat.sh b/test_chat.sh deleted file mode 100755 index b6d8a2e..0000000 --- a/test_chat.sh +++ /dev/null @@ -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 diff --git a/test_curl.sh b/test_curl.sh deleted file mode 100755 index f6c2d16..0000000 --- a/test_curl.sh +++ /dev/null @@ -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"} - ] - }'