#!/usr/bin/env bash
# Send one chat request through the OpenAI-compatible API and print the answer.
. "$(dirname "$0")/common.sh"

prompt=${1:-"What is 17 * 23? Answer with just the number."}
body=$(python3 -c 'import json,sys;print(json.dumps({"model":sys.argv[1],"messages":[{"role":"user","content":sys.argv[2]}],"stream":False}))' "$MODEL" "$prompt")
start=$(date +%s)
curl -fsS "$URL/v1/chat/completions" -H 'Content-Type: application/json' -d "$body" >"$BASE/logs/test-response.json"
python3 - "$BASE/logs/test-response.json" <<'PY'
import json, sys
d = json.load(open(sys.argv[1]))
m = d["choices"][0]["message"]
if m.get("reasoning"):
    print("--- thinking ---\n" + m["reasoning"].strip())
print("--- answer ---\n" + m["content"].strip())
print("--- usage ---", d.get("usage"))
PY
echo "Elapsed: $(( $(date +%s) - start )) s"
